diff options
| author | 2016-09-25 10:04:28 +0200 | |
|---|---|---|
| committer | 2016-09-25 10:04:28 +0200 | |
| commit | fac053c3aacc0e2ede8a85ff41e27eed1c360f6f (patch) | |
| tree | c91ff176e60f1f6e634107b4e7a7282e831975ee | |
| parent | dbb57d52d351e340ce69fccaedbdf758b04ed8fe (diff) | |
| parent | e225f2edfd365d1709df2cb5bb2f752ec8d82c1c (diff) | |
| download | OneRoll-fac053c3aacc0e2ede8a85ff41e27eed1c360f6f.tar.gz OneRoll-fac053c3aacc0e2ede8a85ff41e27eed1c360f6f.zip | |
Merge branch 'master' of github.com:Rolisteam/DiceParser
38 files changed, 1408 insertions, 89 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 32621be..651c3a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(diceparser) add_subdirectory(irc) add_subdirectory(cli) +add_subdirectory(mobile) #qt5_use_modules() diff --git a/COPYING.txt b/COPYING.txt new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/COPYING.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 9497b41..680d1b8 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -1,7 +1,12 @@ cmake_minimum_required(VERSION 2.8) +option(UPDATE_TRANSLATIONS "update Translation" OFF) +MESSAGE(STATUS "UPDATE TRANSLATIONS: ${UPDATE_TRANSLATIONS}") + project(dice) + + # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. @@ -12,19 +17,48 @@ find_package(Qt5Core) set(EXECUTABLE_OUTPUT_PATH bin/) - include_directories(${Qt5Core_INCLUDES} ../) add_definitions(${Qt5Core_DEFINITIONS}) set(MODE "cli") - ADD_DEFINITIONS( -std=c++11 # Or -std=c++0x # Other flags ) -add_executable( - dice + +set(dice_RESOURCES diceparser.qrc) +FIND_PACKAGE(Qt5LinguistTools) + + +IF(UPDATE_TRANSLATIONS) + MESSAGE( update Translation ) + FILE(GLOB_RECURSE translate_dice_SRCS ../*.cpp ../*.h) + SET(translate_SRCS ${translate_dice_SRCS}) + SET(dice_TS "${CMAKE_CURRENT_SOURCE_DIR}/i18n/dice_en.ts" "${CMAKE_CURRENT_SOURCE_DIR}/i18n/dice_fr.ts") +ELSE() + MESSAGE( NO updates for translations) + FILE(GLOB dice_TS "${CMAKE_CURRENT_SOURCE_DIR}/i18n/*.ts") +ENDIF(UPDATE_TRANSLATIONS) + +if(Qt5Core_FOUND) + + IF(UPDATE_TRANSLATIONS) + MESSAGE(status "find" ${dice_TS} ${translate_SRCS} ) + QT5_CREATE_TRANSLATION(dice_QM ${translate_SRCS} ${dice_TS}) + ELSE() + QT5_ADD_TRANSLATION(dice_QM ${dice_TS}) + ENDIF() + + QT5_ADD_RESOURCES(dice_RESOURCES_RCC ${dice_RESOURCES}) + + # guess plugins and libraries directory + set(QT_PLUGINS_DIR "${Qt5Core_DIR}/../../../plugins") + get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION) + get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH) +endif() + +SET( dice_sources ../diceparser.cpp ../range.cpp ../booleancondition.cpp @@ -58,10 +92,11 @@ add_executable( ../node/ifnode.cpp main.cpp ../highlightdice.cpp - ) +) + +add_executable( dice ${dice_sources} ${dice_QM} ) target_link_libraries(dice ${Qt5Core_LIBRARIES}) INSTALL_TARGETS(/bin dice) #qt5_use_modules() - diff --git a/cli/cmds.txt b/cli/cmds.txt new file mode 100644 index 0000000..dfa4b26 --- /dev/null +++ b/cli/cmds.txt @@ -0,0 +1,47 @@ +1L[cheminée,chocolat,épée,arc,chute_de_pierre] +10d10c[>=6]-@c[=1] +10d10c[>=6]-@c[=1]-@c[=1] +10d10c[>6]+@c[=10] +1+1D10 +3d10c[>=5] +3nwod +1+(4*3)D10 +2+4/4 +2D10*2D20*8 +1+(4*3)D10 +(4D6)D10 +1D100a[>=95]a[>=96]a[>=97]a[>=98]a[>=99]e[>=100] +3D100 +4k3 +10D10e[>=6]sc[>=6] +10D10e10s +10D10s +15D10e10c[8-10] +10d10e11 +1D8+2D6+7 +D25 +1L[tete[10],ventre[50],jambe[40]] +2d6c[%2=0] +D25+D10 +D25;D10 +8+8+8 +1D20-88 +100*1D20*2D6 +100/28*3 +100/8 +100*3*8 +help +la +10D10c[<2|>7] +1L[tete,bras_droit,bras_gauche,jambe_droite,jambe_gauche,ventre[6-7],buste[8-10]] +10D6c[=2|=4|=6] +10D10e[=1|=10]k4 +10+10s +1d6e6;1d4e4mk1 +1d6e6;1d4e4mk1 +1d100e[>=95]i[<5]{-1d100e95} +100*3*8 +1d100i[<70]{1d10i[=10]{1d100i[<70]{1d10e10}}} +10d[-8--1] +4d6p[4:black]c[>=4]+1d6p[1:white]c6-@c1+1d6p[1:red]c[>=4]+@c6-@c1 +10d[0-9] diff --git a/cli/dice.qrc b/cli/dice.qrc new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cli/dice.qrc diff --git a/cli/i18n/dice_en.ts b/cli/i18n/dice_en.ts new file mode 100644 index 0000000..3efc610 --- /dev/null +++ b/cli/i18n/dice_en.ts @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="en_US"> +<context> + <name>QObject</name> + <message> + <location filename="../../diceparser.cpp" line="186"/> + <source>Nothing was understood</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="603"/> + <source>Dice with %1 face(s) does not exist. Please, put a value higher than 0</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="648"/> + <source>List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow])</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="905"/> + <source>Validator is missing after the c operator. Please, change it</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="931"/> + <source>Validator is missing after the %1 operator. Please, change it</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="943"/> + <source>This condition %1 introduces an endless loop. Please, change it</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="954"/> + <source>Validator is missing after the e operator. Please, change it</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../node/keepdiceexecnode.cpp" line="48"/> + <source> You ask to keep %1 dice but the result only has %2</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../node/listaliasnode.cpp" line="55"/> + <source>List of Alias: +</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../node/helpnode.cpp" line="37"/> + <source>Rolisteam Dice Parser: +Full documentation at: %1</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../node/jumpbackwardnode.cpp" line="75"/> + <source> The @ operator expects dice result. Please check the documentation to fix your command.</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../node/dicerollernode.cpp" line="30"/> + <source>No dice to roll</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../../node/scalaroperatornode.cpp" line="128"/> + <source>Division by zero</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/cli/i18n/dice_fr.ts b/cli/i18n/dice_fr.ts new file mode 100644 index 0000000..438e99b --- /dev/null +++ b/cli/i18n/dice_fr.ts @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="fr_FR"> +<context> + <name>QObject</name> + <message> + <location filename="../../diceparser.cpp" line="186"/> + <source>Nothing was understood</source> + <translation>Rien n'a été compris</translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="603"/> + <source>Dice with %1 face(s) does not exist. Please, put a value higher than 0</source> + <translation>Dés avec %1 face(s) n'existe pas. Si vous plait, demander une valeur supérieure à 0</translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="648"/> + <source>List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow])</source> + <translation>Liste manquante après l'operateur L. Veuillez l'ajouter (e.g : 1L[épée,lance,flingue,flèche]) </translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="905"/> + <source>Validator is missing after the c operator. Please, change it</source> + <translation>Validateur est manquant après l'opérateur c, veuillez le définir</translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="931"/> + <source>Validator is missing after the %1 operator. Please, change it</source> + <translation>Validateur est manquant après l'opérateur %1, veuillez le définir</translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="943"/> + <source>This condition %1 introduces an endless loop. Please, change it</source> + <translation>La condition %1 introduit une boucle infinie. Veuillez la changer</translation> + </message> + <message> + <location filename="../../diceparser.cpp" line="954"/> + <source>Validator is missing after the e operator. Please, change it</source> + <translation>Validateur est manquant après l'opérateur e, veuillez le définir</translation> + </message> + <message> + <location filename="../../node/keepdiceexecnode.cpp" line="48"/> + <source> You ask to keep %1 dice but the result only has %2</source> + <translation>Vous souhaitez garder %1 dés mais le resultat n'a seulement que %2 dés</translation> + </message> + <message> + <location filename="../../node/listaliasnode.cpp" line="55"/> + <source>List of Alias: +</source> + <translation>Liste d'alias:</translation> + </message> + <message> + <location filename="../../node/helpnode.cpp" line="37"/> + <source>Rolisteam Dice Parser: +Full documentation at: %1</source> + <translation>Rolisteam Dice Parser: +Documentation complète sur: %1</translation> + </message> + <message> + <location filename="../../node/jumpbackwardnode.cpp" line="75"/> + <source> The @ operator expects dice result. Please check the documentation to fix your command.</source> + <translation>L'opérateur @ attend un résultat de dés. Veuillez vérifier la documentation pour réparer votre commande.</translation> + </message> + <message> + <location filename="../../node/dicerollernode.cpp" line="30"/> + <source>No dice to roll</source> + <translation>Aucun dé à lancer</translation> + </message> + <message> + <location filename="../../node/scalaroperatornode.cpp" line="128"/> + <source>Division by zero</source> + <translation>Division par zéro</translation> + </message> +</context> +</TS> diff --git a/cli/main.cpp b/cli/main.cpp index 21bb1ca..7a5ed97 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2014 by Renaud Guezennec * -* http://renaudguezennec.homelinux.org/accueil,3.html * +* http://www.rolisteam.org/contact * * * * This file is part of DiceParser * * * @@ -77,6 +77,14 @@ QString diceToText(ExportedDiceResult& dice,bool highlight,bool homogeneous) { prefix = "\e[34m%1\e[0m"; } + if(tmp.getColor()=="red") + { + prefix = "\e[31m%1\e[0m"; + } + if(tmp.getColor()=="black") + { + prefix = "\e[30m%1\e[0m"; + } } if(i==0) @@ -116,8 +124,7 @@ void startDiceParsing(QString& cmd,QString& treeFile,bool highlight) if(parser->parseLine(cmd)) { // - if(treeFile.isEmpty()) - { + parser->Start(); if(!parser->getErrorMap().isEmpty()) { @@ -150,11 +157,10 @@ void startDiceParsing(QString& cmd,QString& treeFile,bool highlight) str = parser->getStringResult(); } out << str << "\n"; - } - else - { - parser->writeDownDotTree(treeFile); - } + if(!treeFile.isEmpty()) + { + parser->writeDownDotTree(treeFile); + } } else { diff --git a/cli/test_dice.sh b/cli/test_dice.sh new file mode 100755 index 0000000..bd20b6a --- /dev/null +++ b/cli/test_dice.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +export LD_LIBRARY_PATH="/home/renaud/application/other/Qt/5.7/gcc_64/lib:$LD_LIBRARY_PATH" +for line in `cat cmds.txt` +do + #echo $line; + dice $line +done diff --git a/diceParser.pro b/diceParser.pro index 3a95496..2b5f3fd 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -21,7 +21,7 @@ TEMPLATE = app CONFIG+= CLI CLI { DEFINES += CLI -include(cli/cli.pri)cd +include(cli/cli.pri) } IRC { include(irc/irc.pri) @@ -46,7 +46,8 @@ SOURCES += diceparser.cpp \ result/scalarresult.cpp \ parsingtoolbox.cpp \ result/stringresult.cpp \ - dicealias.cpp + dicealias.cpp \ + mobile/mainwindow.cpp HEADERS += \ @@ -60,7 +61,8 @@ HEADERS += \ result/scalarresult.h \ result/parsingtoolbox.h \ result/stringresult.h \ - dicealias.h + dicealias.h \ + mobile/mainwindow.h OTHER_FILES += README.md \ HelpMe.md diff --git a/diceparser.cpp b/diceparser.cpp index 4575bf5..b6081a7 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -221,7 +221,10 @@ bool DiceParser::readExpression(QString& str,ExecutionNode* & node) node = operandNode; operandNode= getLatestNode(operandNode); - while(readOperator(str,operandNode)); + while(readOperator(str,operandNode)) + { + operandNode= getLatestNode(operandNode); + }; } else if(readCommand(str,operandNode)) { @@ -885,7 +888,6 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, break; case Count: { - //Validator* validator = m_parsingToolbox->readValidator(str); Validator* validator = m_parsingToolbox->readCompositeValidator(str); if(NULL!=validator) { @@ -979,8 +981,8 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//, Validator* validator = m_parsingToolbox->readCompositeValidator(str); if(NULL!=validator) { - ExecutionNode* trueNode; - ExecutionNode* falseNode; + ExecutionNode* trueNode = NULL; + ExecutionNode* falseNode = NULL; if(readIfInstruction(str,trueNode,falseNode)) { nodeif->setInstructionTrue(trueNode); diff --git a/irc/CMakeLists.txt b/irc/CMakeLists.txt index d43ffed..af77dfb 100644 --- a/irc/CMakeLists.txt +++ b/irc/CMakeLists.txt @@ -10,23 +10,23 @@ set(CMAKE_AUTOMOC ON) # Find the QtWidgets library find_package(Qt5Core) -find_package(Qt5Gui) -find_package(Qt5Widgets) +#fsind_package(Qt5Gui) +#find_package(Qt5Widgets) find_package(Qt5Network) -SET(mainwindow_SOURCES mainwindow.cpp) -SET(mainwindow_HEADERS mainwindow.h) -SET(mainwindow_FORMS mainwindow.ui) +#SET(mainwindow_SOURCES mainwindow.cpp) +#SET(mainwindow_HEADERS mainwindow.h) +#SET(mainwindow_FORMS mainwindow.ui) set(EXECUTABLE_OUTPUT_PATH bin/) -include_directories(${Qt5Core_INCLUDES} ${Qt5Gui_INCLUDES} ${Qt5Widgets_INCLUDES} ${Qt5Network_INCLUDES} ../) -add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS}) +include_directories(${Qt5Core_INCLUDES} ${Qt5Network_INCLUDES} ../) +add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Network_DEFINITIONS}) -qt5_wrap_ui(UI_HEADERS mainwindow.ui) -#set(MODE "cli") +#qt5_wrap_ui(UI_HEADERS mainwindow.ui) +set(MODE "cli") ADD_DEFINITIONS( @@ -68,13 +68,11 @@ add_executable( ../node/sortresult.cpp ../node/startingnode.cpp ../node/ifnode.cpp - ${UI_HEADERS} botircdiceparser.cpp main.cpp) -target_link_libraries(irc ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) +target_link_libraries(irc ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES}) INSTALL_TARGETS(/bin irc) - #qt5_use_modules() diff --git a/irc/botircdiceparser.cpp b/irc/botircdiceparser.cpp index 87d47ff..eb2e3c1 100644 --- a/irc/botircdiceparser.cpp +++ b/irc/botircdiceparser.cpp @@ -37,6 +37,7 @@ BotIrcDiceParser::BotIrcDiceParser(QObject *parent) : // Connect signals and slots! connect(m_socket, SIGNAL(readyRead()), this, SLOT(readData())); connect(m_socket,SIGNAL(connected()),this,SLOT(authentificationProcess())); + connect(m_socket,SIGNAL(disconnected()),this,SLOT(connectToServer())); connect(m_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorOccurs(QAbstractSocket::SocketError))); } diff --git a/mobile/CMakeLists.txt b/mobile/CMakeLists.txt new file mode 100644 index 0000000..0ccff18 --- /dev/null +++ b/mobile/CMakeLists.txt @@ -0,0 +1,102 @@ +cmake_minimum_required(VERSION 2.8) + +option(UPDATE_TRANSLATIONS "update Translation" OFF) +MESSAGE(STATUS "UPDATE TRANSLATIONS: ${UPDATE_TRANSLATIONS}") + + +project(diceGui) + + +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +# Find the QtWidgets library +find_package(Qt5 COMPONENTS Quick Qml Core Widgets Gui) +#find_package(Qt5QuickCompiler) + +set(EXECUTABLE_OUTPUT_PATH bin/) + +include_directories(${Qt5Core_INCLUDES} ${Qt5Widgets_INCLUDES} ${Qt5Gui_INCLUDES} ${Qt5Qml_INCLUDES} ${Qt5Quick_INCLUDES}../) +add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Qml_DEFINITIONS} ${Qt5Quick_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ) + +ADD_DEFINITIONS( + -std=c++11 +) + +set(diceGui_RESOURCES diceparser.qrc) +FIND_PACKAGE(Qt5LinguistTools) + + +IF(UPDATE_TRANSLATIONS) + MESSAGE( update Translation ) + FILE(GLOB_RECURSE translate_diceGui_SRCS ../*.cpp ../*.h) + SET(translate_SRCS ${translate_dice_SRCS}) + SET(diceGui_TS "${CMAKE_CURRENT_SOURCE_DIR}/i18n/diceGui_en.ts" "${CMAKE_CURRENT_SOURCE_DIR}/i18n/diceGui_fr.ts") +ELSE() + MESSAGE( NO updates for translations) + FILE(GLOB diceGui_TS "${CMAKE_CURRENT_SOURCE_DIR}/i18n/*.ts") +ENDIF(UPDATE_TRANSLATIONS) + +if(Qt5Core_FOUND) + + IF(UPDATE_TRANSLATIONS) + MESSAGE(status "find" ${diceGui_TS} ${translate_SRCS} ) + QT5_CREATE_TRANSLATION(diceGui_QM ${translate_SRCS} ${diceGui_TS}) + ELSE() + QT5_ADD_TRANSLATION(diceGui_QM ${diceGui_TS}) + ENDIF() + + QT5_ADD_RESOURCES(diceGui_RESOURCES_RCC ${diceGui_RESOURCES}) + + # guess plugins and libraries directory + set(QT_PLUGINS_DIR "${Qt5Core_DIR}/../../../plugins") + get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION) + get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH) +endif() + +SET( diceGui_sources + ../diceparser.cpp + ../range.cpp + ../booleancondition.cpp + ../validator.cpp + ../compositevalidator.cpp + ../operationcondition.cpp + ../die.cpp + ../parsingtoolbox.cpp + ../dicealias.cpp + ../result/result.cpp + ../result/scalarresult.cpp + ../result/stringresult.cpp + ../result/diceresult.cpp + ../node/countexecutenode.cpp + ../node/dicerollernode.cpp + ../node/executionnode.cpp + ../node/explosedicenode.cpp + ../node/helpnode.cpp + ../node/mergenode.cpp + ../node/jumpbackwardnode.cpp + ../node/keepdiceexecnode.cpp + ../node/listaliasnode.cpp + ../node/listsetrollnode.cpp + ../node/numbernode.cpp + ../node/parenthesesnode.cpp + ../node/paintnode.cpp + ../node/rerolldicenode.cpp + ../node/scalaroperatornode.cpp + ../node/sortresult.cpp + ../node/startingnode.cpp + ../node/ifnode.cpp + main.cpp + maincontroler.cpp + ../highlightdice.cpp +) +qt5_add_resources(RESOURCE_ADDED mobile.qrc) + +add_executable( diceGui ${diceGui_sources} ${diceGui_QM} ${RESOURCE_ADDED} ) + +target_link_libraries(diceGui ${Qt5Core_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Qml_LIBRARIES} ${Qt5Quick_LIBRARIES}) +INSTALL_TARGETS(/bin diceGui) + +#qt5_use_modules() diff --git a/mobile/commandmodel.cpp b/mobile/commandmodel.cpp new file mode 100644 index 0000000..6a3ab1d --- /dev/null +++ b/mobile/commandmodel.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2016 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "commandmodel.h" + +CommandModel::CommandModel() +{ + +} + +QVariant CommandModel::data(const QModelIndex &index, int role) const +{ + QPair<QString,QString> indexP = m_data.at(index.row()); + if(role == NameRole) + { + return indexP.first; + } + else if(role == CmdRole) + { + return indexP.second; + } +} + +int CommandModel::rowCount(const QModelIndex &parent) const +{ + return m_data.count(); +} +QHash<int, QByteArray> CommandModel::roleNames() const +{ + QHash<int, QByteArray> roles; + roles[NameRole] = "name"; + roles[CmdRole] = "cmd"; + return roles; +} +void CommandModel::insertCmd(QString name, QString cmd) +{ + QModelIndex index; + beginInsertRows(index,0,0); + m_data.prepend(QPair<QString,QString>(name,cmd)); + endInsertRows(); +} diff --git a/mobile/commandmodel.h b/mobile/commandmodel.h new file mode 100644 index 0000000..2c20072 --- /dev/null +++ b/mobile/commandmodel.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2016 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef COMMANDMODEL_H +#define COMMANDMODEL_H + +#include <QObject> + +#include <QAbstractListModel> + +class CommandModel : public QAbstractListModel +{ + Q_OBJECT +public: + enum CustomRole {NameRole = Qt::UserRole+1,CmdRole}; + CommandModel(); + + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const; + virtual int rowCount(const QModelIndex &parent) const; + + QHash<int, QByteArray> roleNames() const; + + +public slots: + void insertCmd(QString name, QString cmd); +private: + QList<QPair<QString,QString> > m_data; +}; + +#endif // COMMANDMODEL_H diff --git a/mobile/deployment.pri b/mobile/deployment.pri new file mode 100644 index 0000000..265ce71 --- /dev/null +++ b/mobile/deployment.pri @@ -0,0 +1,13 @@ +unix:!android { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/mobile/main.cpp b/mobile/main.cpp new file mode 100644 index 0000000..c4c8b0a --- /dev/null +++ b/mobile/main.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2016 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * rolisteam is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +#include "maincontroler.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + MainControler* main = new MainControler(); + + + QQmlApplicationEngine engine; + main->initEngine(&engine); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + //main->setConnections(&engine); + + return app.exec(); +} diff --git a/mobile/main.qml b/mobile/main.qml new file mode 100644 index 0000000..700f3a7 --- /dev/null +++ b/mobile/main.qml @@ -0,0 +1,172 @@ +import QtQuick 2.7 +import QtQuick.Window 2.2 + +Window { + id:root + visible: true + signal addRoll(string name, string cmd ) + signal roll(string cmd) + color: "black" + height: 1280 + width: 720 + + Column{ + + anchors.fill: parent + leftPadding: width*0.025 + rightPadding: width*0.025 + topPadding: width*0.025 + Rectangle { + height: parent.height*0.12 + width: parent.width*0.95 + Image { + anchors.fill: parent + horizontalAlignment: Image.AlignHCenter + verticalAlignment:Image.AlignVCenter + fillMode: Image.PreserveAspectFit + source: "qrc:/resources/images/add.png" + } + gradient: Gradient { + GradientStop { position: 0.0; color: "darkblue" } + GradientStop { position: 1.0; color: "blue" } + } + MouseArea { + anchors.fill: parent + onClicked:popupAdd.visible = true + } + } + + ListView { + model: _model + focus: true + height: parent.height*0.88 + width: parent.width*0.95 + delegate: Item{ + height: parent.height + width: parent.width + Column{ + width: parent.width + height: parent.height + Text{ + text: name + font.pointSize: 40 + color: "white" + + + } + Text{ + text: cmd + font.pointSize:30 + color: "white" + + } + } + MouseArea{ + anchors.fill:parent + onClicked: roll(cmd) + } + } + } + + } + Rectangle { + id: popupAdd + color: "black" + x: parent.width*0.1 + y: parent.height*0.1 + height: parent.height*0.80 + width: parent.width*0.80 + visible: false + border.color: "white" + border.width: 1 + + Column{ + id:form + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + height: parent.height*0.80 + leftPadding: width*0.025 + rightPadding: width*0.025 + topPadding: width*0.025 + property alias name : nameInp + property alias cmd : cmdInp + Text { + text: qsTr("Name") + color: "white" + height: parent.height*0.1 + font.pointSize: 40 + } + Rectangle{ + height: parent.height*0.1 + width: parent.width*0.90 + border.color: "#BBBBBB" + border.width: 1 + color: "black" + TextInput{ + id: nameInp + color: "white" + anchors.fill: parent + font.pointSize: 40 + } + } + + Text { + text: qsTr("Command") + color: "white" + height: parent.height*0.1 + font.pointSize: 40 + } + Rectangle{ + height: parent.height*0.1 + width: parent.width*0.90 + border.color: "#BBBBBB" + border.width: 1 + color: "black" + TextInput{ + id: cmdInp + color: "white" + anchors.fill: parent + font.pointSize: 40 + } + } + } + + Rectangle { + color:"red" + id: cancel + anchors.top: form.bottom + anchors.left: form.left + anchors.right: form.horizontalCenter + anchors.bottom: parent.bottom + radius: height/2 + MouseArea { + anchors.fill: parent + onClicked:{ + nameInp.text="" + cmdInp.text="" + popupAdd.visible = false + } + } + } + Rectangle { + color:"green" + anchors.top: form.bottom + anchors.left: cancel.right + anchors.right: form.right + anchors.bottom: parent.bottom + radius: height/2 + MouseArea { + anchors.fill: parent + onClicked: + { + root.addRoll(nameInp,cmdInp.text); + nameInp.text="" + cmdInp.text="" + popupAdd.visible = false + } + } + + } + } +} diff --git a/mobile/maincontroler.cpp b/mobile/maincontroler.cpp new file mode 100644 index 0000000..4b40fa2 --- /dev/null +++ b/mobile/maincontroler.cpp @@ -0,0 +1,37 @@ +#include "maincontroler.h" + +#include <QQmlContext> +#include <QDebug> + +MainControler::MainControler(QObject *parent) + : QObject(parent) +{ + m_model = new CommandModel(); + m_model->insertCmd("L5R","8D10e10k4"); + + m_diceParser = new DiceParser(); +} +void MainControler::initEngine(QQmlApplicationEngine* engine) +{ + m_engine = engine; + engine->rootContext()->setContextProperty("_model",m_model); + connect(m_engine,SIGNAL(objectCreated(QObject*,QUrl)),this,SLOT(setConnections(QObject*,QUrl))); + + +} +void MainControler::rollDice(QString cmd) +{ + if(m_diceParser->parseLine(cmd)) + { + m_diceParser->Start(); + qDebug() << m_diceParser->getSumOfDiceResult(); + } +} +void MainControler::setConnections(QObject* root,QUrl url) +{ + //QObject* root = engine->rootContext()->contextObject(); + + + connect(root,SIGNAL(roll(QString)),this,SLOT(rollDice(QString))); + connect(root,SIGNAL(addRoll(QString,QString)),m_model,SLOT(insertCmd(QString,QString))); +} diff --git a/mobile/maincontroler.h b/mobile/maincontroler.h new file mode 100644 index 0000000..b94312d --- /dev/null +++ b/mobile/maincontroler.h @@ -0,0 +1,28 @@ +#ifndef MAINCONTROLER_H +#define MAINCONTROLER_H + +#include <QObject> +#include <QQmlApplicationEngine> + +#include "commandmodel.h" +#include "diceparser.h" + +class MainControler : public QObject +{ + Q_OBJECT +public: + explicit MainControler(QObject *parent = 0); + + void initEngine(QQmlApplicationEngine* ); +signals: + +public slots: + void setConnections(QObject* root,QUrl url); + void rollDice(QString cmd); +private: + CommandModel* m_model; + DiceParser* m_diceParser; + QQmlApplicationEngine* m_engine; +}; + +#endif // MAINCONTROLER_H diff --git a/mobile/mainwindow.cpp b/mobile/mainwindow.cpp new file mode 100644 index 0000000..ec0bd08 --- /dev/null +++ b/mobile/mainwindow.cpp @@ -0,0 +1,6 @@ +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) +{ + +} diff --git a/mobile/mainwindow.h b/mobile/mainwindow.h new file mode 100644 index 0000000..df67bfe --- /dev/null +++ b/mobile/mainwindow.h @@ -0,0 +1,17 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit MainWindow(QWidget *parent = 0); + +signals: + +public slots: +}; + +#endif // MAINWINDOW_H
\ No newline at end of file diff --git a/mobile/mobile.pro b/mobile/mobile.pro new file mode 100644 index 0000000..2e33522 --- /dev/null +++ b/mobile/mobile.pro @@ -0,0 +1,20 @@ +TEMPLATE = app + +QT += qml quick +CONFIG += c++11 + +SOURCES += main.cpp maincontroler.cpp \ + commandmodel.cpp + +HEADERS += maincontroler.h \ + commandmodel.h + +RESOURCES += qml.qrc + +include(../diceparser.pri) + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) diff --git a/mobile/mobile.qrc b/mobile/mobile.qrc new file mode 100644 index 0000000..69145a8 --- /dev/null +++ b/mobile/mobile.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>qml/main.qml</file> + </qresource> +</RCC> diff --git a/mobile/qml.qrc b/mobile/qml.qrc new file mode 100644 index 0000000..2cbbe08 --- /dev/null +++ b/mobile/qml.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>resources/images/add.png</file> + </qresource> +</RCC> diff --git a/mobile/qml/main.qml b/mobile/qml/main.qml new file mode 100644 index 0000000..ed9d480 --- /dev/null +++ b/mobile/qml/main.qml @@ -0,0 +1,17 @@ +import QtQuick 2.4 + +Item { + id:root + + ListView { + id: diceList + } + + Item{ + id: popupInput + + } + Item { + id: popupResult + } +} diff --git a/mobile/resources/images/add.png b/mobile/resources/images/add.png Binary files differnew file mode 100644 index 0000000..c8e1bd2 --- /dev/null +++ b/mobile/resources/images/add.png diff --git a/node/executionnode.cpp b/node/executionnode.cpp index d2f291b..a419bec 100644 --- a/node/executionnode.cpp +++ b/node/executionnode.cpp @@ -62,7 +62,7 @@ void ExecutionNode::generateDotTree(QString& s) s.append(toString(false)); s.append(" -> "); s.append(m_nextNode->toString(false)); - s.append(";\n"); + s.append("[label=\"next\"];\n"); // s.append(" [label=\"nextNode\"];\n"); m_nextNode->generateDotTree(s); } @@ -71,13 +71,17 @@ void ExecutionNode::generateDotTree(QString& s) s.append(toString(false)); s.append(" -> "); s.append("NULL;\n"); + if(NULL!=m_result) + { + s.append(toString(false)); + s.append(" ->"); + s.append(m_result->toString(false)); + s.append(" [label=\"Result\"];\n"); - s.append(toString(false)); - s.append(" ->"); - s.append(m_result->toString(false)); - s.append(" [label=\"Result\"];\n"); - m_result->generateDotTree(s); + m_result->generateDotTree(s); + } } + } diff --git a/node/ifnode.cpp b/node/ifnode.cpp index bf07776..8605dcf 100644 --- a/node/ifnode.cpp +++ b/node/ifnode.cpp @@ -105,6 +105,54 @@ void IfNode::setInstructionFalse(ExecutionNode* node) { m_false = node; } +void IfNode::generateDotTree(QString& s) +{ + s.append(toString(true)); + s.append(";\n"); + + if((NULL!=m_true)&&(m_true != m_nextNode)) + { + s.append(toString(false)); + s.append(" -> "); + s.append(m_true->toString(false)); + s.append("[label=\"true\"];\n"); +// s.append(" [label=\"nextNode\"];\n"); + m_true->generateDotTree(s); + } + if((NULL!=m_false)&&(m_false != m_nextNode)) + { + s.append(toString(false)); + s.append(" -> "); + s.append(m_false->toString(false)); + s.append("[label=\"false\"];\n"); + m_false->generateDotTree(s); + } + + if(NULL!=m_nextNode) + { + s.append(toString(false)); + s.append(" -> "); + s.append(m_nextNode->toString(false)); + s.append("[label=\"next\"];\n"); + m_nextNode->generateDotTree(s); + } + else + { + s.append(toString(false)); + s.append(" -> "); + s.append("NULL;\n"); + + if(NULL!=m_result) + { + + s.append(toString(false)); + s.append(" ->"); + s.append(m_result->toString(false)); + s.append(" [label=\"Result\"];\n"); + m_result->generateDotTree(s); + } + } +} QString IfNode::toString(bool wl) const { diff --git a/node/ifnode.h b/node/ifnode.h index 5872f79..ed9e8de 100644 --- a/node/ifnode.h +++ b/node/ifnode.h @@ -40,6 +40,13 @@ public: virtual QString toString(bool )const; virtual qint64 getPriority() const; + + /** + * @brief generateDotTree + */ + virtual void generateDotTree(QString&); + + protected: ExecutionNode *getLeafNode(ExecutionNode *node); diff --git a/node/jumpbackwardnode.cpp b/node/jumpbackwardnode.cpp index 25056b1..0b2cbf6 100644 --- a/node/jumpbackwardnode.cpp +++ b/node/jumpbackwardnode.cpp @@ -24,6 +24,7 @@ JumpBackwardNode::JumpBackwardNode() { m_previousNode=NULL; + m_backwardNode = NULL; m_diceResult =new DiceResult(); m_result = m_diceResult; } @@ -45,24 +46,74 @@ QString JumpBackwardNode::toString(bool wl) const return m_id; } } +void JumpBackwardNode::generateDotTree(QString& s) +{ + s.append(toString(true)); + s.append(";\n"); + + if(NULL!=m_backwardNode) + { + s.append(toString(false)); + s.append(" -> "); + s.append(m_backwardNode->toString(false)); + s.append("[label=\"backward\"];\n"); + //m_backwardNode->generateDotTree(s); + } + + if(NULL!=m_nextNode) + { + s.append(toString(false)); + s.append(" -> "); + s.append(m_nextNode->toString(false)); + s.append("[label=\"next\"];\n"); + m_nextNode->generateDotTree(s); + } + else + { + s.append(toString(false)); + s.append(" -> "); + s.append("NULL;\n"); + + if(NULL!=m_result) + { + s.append(toString(false)); + s.append(" ->"); + s.append(m_result->toString(false)); + s.append(" [label=\"Result\"];\n"); + m_result->generateDotTree(s); + } + } + +} + void JumpBackwardNode::run(ExecutionNode* previous) { m_previousNode = previous; ExecutionNode* parent = previous; bool found=false; - int i = 3; + //int i = 3; Result* result=NULL; while((NULL!=parent)&&(!found)) { result = parent->getResult(); - if((NULL!=result)) + if(NULL!=result) { - --i; - if((i==0)&&(result->hasResultOfType(Result::DICE_LIST))) + //--i; + if(/*(i==0)&&*/(result->hasResultOfType(Result::DICE_LIST))) { found =true; + m_backwardNode = parent; } + else + { + JumpBackwardNode* jpNode = dynamic_cast<JumpBackwardNode*>(parent); + if(NULL!=jpNode) + { + found = true; + m_backwardNode = parent; + } + } } if(!found) { @@ -88,7 +139,7 @@ void JumpBackwardNode::run(ExecutionNode* previous) } } - m_result->setPrevious(parent->getResult()); + m_result->setPrevious(previous->getResult()); if(NULL!=m_nextNode) { diff --git a/node/jumpbackwardnode.h b/node/jumpbackwardnode.h index a89d0d3..dd70b11 100644 --- a/node/jumpbackwardnode.h +++ b/node/jumpbackwardnode.h @@ -48,9 +48,11 @@ public: * @brief getPriority * @return */ - virtual qint64 getPriority() const; + virtual qint64 getPriority() const; + virtual void generateDotTree(QString &s); private: DiceResult* m_diceResult; + ExecutionNode* m_backwardNode; }; diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index 0dcb9b9..692b09f 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -47,7 +47,7 @@ ScalarOperatorNode::~ScalarOperatorNode() void ScalarOperatorNode::run(ExecutionNode* previous) { - m_previousNode = previous; + m_previousNode = previous; if(NULL!=m_internalNode) { m_internalNode->run(this); diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 38221f9..212c006 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -144,7 +144,7 @@ Validator* ParsingToolBox::readValidator(QString& str) { Validator* returnVal=NULL; BooleanCondition::LogicOperator myLogicOp = BooleanCondition::Equal; - /*bool hasReadLogicOperator = */readLogicOperator(str,myLogicOp); + readLogicOperator(str,myLogicOp); OperationCondition::ConditionOperator condiOp = OperationCondition::Modulo; @@ -169,6 +169,7 @@ Validator* ParsingToolBox::readValidator(QString& str) } else if(readNumber(str,value)) { + bool isRange = false; if(str.startsWith("-")) { str=str.remove(0,1); @@ -179,9 +180,15 @@ Validator* ParsingToolBox::readValidator(QString& str) Range* range = new Range(); range->setValue(value,end); returnVal = range; + isRange = true; + } + else + { + str.prepend("-"); } } - else + + if(!isRange) { BooleanCondition* condition = new BooleanCondition(); condition->setValue(value); @@ -489,18 +496,20 @@ void ParsingToolBox::readProbability(QStringList& str,QList<Range>& ranges) int maxValue = 0; int i=0; int j=0; + bool hasPercentage=false; + //QList<Range> rangesTemp; //range for(QString line:str) { int pos = line.indexOf('['); if(-1!=pos) { - QString range = line.right(line.length()-pos); + QString rangeStr = line.right(line.length()-pos); line = line.left(pos); str[j]=line; qint64 start; qint64 end; - if(readDiceRange(range,start,end)) + if(readDiceRange(rangeStr,start,end)) { Range range; range.setValue(start,end); @@ -510,6 +519,7 @@ void ParsingToolBox::readProbability(QStringList& str,QList<Range>& ranges) } else//pourcentage { + hasPercentage = true; Range range; range.setStart(start); ranges.append(range); @@ -521,11 +531,17 @@ void ParsingToolBox::readProbability(QStringList& str,QList<Range>& ranges) maxValue = end; } } + else + { + Range range; + range.setEmptyRange(true); + ranges.append(range); + } ++j; } - if(undefDistance!=0) + if((hasPercentage)&&(undefDistance!=0)) { qreal ratio = (qreal)100.0 / (qreal)undefDistance; qint64 realStart=0; @@ -545,5 +561,30 @@ void ParsingToolBox::readProbability(QStringList& str,QList<Range>& ranges) } } } + else + { + int limitUp = 1; + for(int i = 0; i< ranges.size(); ++i) + { + Range range = ranges.at(i); + if(range.isEmptyRange()) + { + range.setStart(limitUp); + range.setEnd(limitUp); + range.setEmptyRange(false); + + } + else + { + qint64 sizeRange = range.getEnd()-range.getStart(); + range.setStart(limitUp); + limitUp+=sizeRange+1; + range.setEnd(limitUp); + } + ++limitUp; + ranges[i]=range; + } + + } } diff --git a/parsingtoolbox.h b/parsingtoolbox.h index 3046570..e5f7fa8 100644 --- a/parsingtoolbox.h +++ b/parsingtoolbox.h @@ -41,25 +41,25 @@ class ParsingToolBox public: enum LIST_OPERATOR {NONE,UNIQUE}; - /** - * @brief ParsingToolBox - */ + /** + * @brief ParsingToolBox + */ ParsingToolBox(); /** * @brief ParsingToolBox * @param data */ ParsingToolBox(const ParsingToolBox & data); - /** - * @brief ~ParsingToolBox - */ - virtual ~ParsingToolBox(); - /** - * @brief addSort - * @param e - * @param b - * @return - */ + /** + * @brief ~ParsingToolBox + */ + virtual ~ParsingToolBox(); + /** + * @brief addSort + * @param e + * @param b + * @return + */ ExecutionNode* addSort(ExecutionNode* e,bool b); /** * @brief readAscending @@ -67,18 +67,18 @@ public: * @return */ static bool readAscending(QString& str); - /** - * @brief readLogicOperator - * @param str - * @param op - * @return - */ + /** + * @brief readLogicOperator + * @param str + * @param op + * @return + */ bool readLogicOperator(QString& str,BooleanCondition::LogicOperator& op); - /** - * @brief readValidator - * @param str - * @return - */ + /** + * @brief readValidator + * @param str + * @return + */ Validator* readValidator(QString& str); /** * @brief readCompositeValidator @@ -102,17 +102,17 @@ public: * @return */ static bool readVariable(QString& str,qint64& myNumber); - /** - * @brief readOpenParentheses - * @param str - * @return - */ + /** + * @brief readOpenParentheses + * @param str + * @return + */ static bool readOpenParentheses(QString& str); - /** - * @brief readCloseParentheses - * @param str - * @return - */ + /** + * @brief readCloseParentheses + * @param str + * @return + */ static bool readCloseParentheses(QString& str); /** @@ -168,11 +168,11 @@ private: QMap<QString,BooleanCondition::LogicOperator>* m_logicOp; QMap<QString,CompositeValidator::LogicOperation>* m_logicOperation; - QMap<QString,OperationCondition::ConditionOperator>* m_conditionOperation; - QHash<QString,ScalarOperatorNode::ArithmeticOperator>* m_arithmeticOperation; + QMap<QString,OperationCondition::ConditionOperator>* m_conditionOperation; + QHash<QString,ScalarOperatorNode::ArithmeticOperator>* m_arithmeticOperation; - static QHash<QString,QString>* m_variableHash; + static QHash<QString,QString>* m_variableHash; }; #endif // PARSINGTOOLBOX_H @@ -22,7 +22,7 @@ #include "range.h" Range::Range() - : m_hasEnd(false),m_hasStart(false) + : m_hasEnd(false),m_hasStart(false),m_emptyRange(false) { @@ -91,3 +91,12 @@ qint64 Range::getEnd() const { return m_end; } +void Range::setEmptyRange(bool b) +{ + m_emptyRange = b; +} + +bool Range::isEmptyRange() +{ + return m_emptyRange; +} @@ -44,11 +44,15 @@ public: qint64 getStart() const; qint64 getEnd() const; + void setEmptyRange(bool); + bool isEmptyRange(); + private: qint64 m_start; qint64 m_end; bool m_hasEnd; bool m_hasStart; + bool m_emptyRange; }; #endif // RANGE_H |