]> Johnzone git - splittermond-assistant.git/commitdiff
small progress towards skill def
authorJohn Janus <mail@johnzone.org>
Tue, 13 Aug 2019 06:12:50 +0000 (08:12 +0200)
committerJohn Janus <mail@johnzone.org>
Tue, 13 Aug 2019 06:12:50 +0000 (08:12 +0200)
resources/views.qrc [new file with mode: 0644]
resources/views/main.qml [moved from src/main.qml with 100% similarity]
splittermond-assistant.pro
src/character.cpp
src/character.h
src/definitions.h [deleted file]
src/main.cpp
src/qml.qrc [deleted file]
style.astylerc [new file with mode: 0644]

diff --git a/resources/views.qrc b/resources/views.qrc
new file mode 100644 (file)
index 0000000..a48eeca
--- /dev/null
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+    <qresource prefix="/views">
+        <file alias="main.qml">views/main.qml</file>
+    </qresource>
+</RCC>
similarity index 100%
rename from src/main.qml
rename to resources/views/main.qml
index 45b38352165e0d9a111df3cb13cfe0d0c011d7bf..4dc6d797fd3f184f88abe7881091545737a9f282 100644 (file)
@@ -1,7 +1,7 @@
 include(qmake-target-platform.pri)
 include(qmake-destination-path.pri)
 
-QT += quick xml
+QT += qml quick xml
 CONFIG += c++17
 
 # The following define makes your compiler emit warnings if you use
@@ -15,16 +15,20 @@ DEFINES += QT_DEPRECATED_WARNINGS
 # You can also select to disable deprecated APIs only up to a certain version of Qt.
 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
-INCLUDEPATH += src
+INCLUDEPATH += src resources
+
+HEADERS += \
+    src/character.h
 
 SOURCES += \
         src/character.cpp \
         src/main.cpp
 
-RESOURCES += src/qml.qrc
+RESOURCES += \
+    resources/views.qrc
 
 # Additional import path used to resolve QML modules in Qt Creator's code model
-QML_IMPORT_PATH =
+QML_IMPORT_PATH += $$PWD/resources
 
 # Additional import path used to resolve QML modules just for Qt Quick Designer
 QML_DESIGNER_IMPORT_PATH =
@@ -34,9 +38,8 @@ qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
 
-HEADERS += \
-    src/character.h \
-    src/definitions.h
+DISTFILES += \
+    style.astylerc
 
 DESTDIR = $$PWD/binaries/$$DESTINATION_PATH
 OBJECTS_DIR = $$PWD/build/$$DESTINATION_PATH/.obj
index 0a0455f1767eb471ec11d77cefc8386883c9e6ef..04907ee493dffb6827b1d8d8117515136520fbce 100644 (file)
@@ -1,6 +1,7 @@
 #include "character.h"
+namespace sm::data {
+  Character::Character(const QFile& file)
+  {
 
-Character::Character()
-{
-
+  }
 }
index 61b92e36dbb721e4df8b65b74e6d56811af8df4b..18df734ee41c808c7841054a01b66f4206368826 100644 (file)
 #define CHARACTER_H
 
 #include <QObject>
+#include <QFile>
+#include <QXmlSimpleReader>
+#include <unordered_map>
+#include "definitions.h"
 
-class Character
+namespace sm::data
 {
-public:
-    Character();
-};
+  enum Skill {
+    acrobatics,
+    alchemy,
+    leadership,
+    arcanelore,
+    athletics,
+    performance,
+    diplomacy,
+    clscraft,
+    empathy,
+    determination,
+    dexterity,
+    history,
+    craftmanship,
+    heal,
+    stealth,
+    hunting,
+    countrylore,
+    nature,
+    eloquence,
+    locksntraps,
+    swim,
+    seafaring,
+    streetlore,
+    animals,
+    survival,
+    perception,
+    endurance,
+    antimagic,
+    controlmagic,
+    motionmagic,
+    insightmagic,
+    stonemagic,
+    firemagic,
+    healmagic,
+    illusionmagic,
+    combatmagic,
+    lightmagic,
+    naturemagic,
+    shadowmagic,
+    fatemagic,
+    protectionmagic,
+    enhancemagic,
+    deathmagic,
+    transformationmagic,
+    watermagic,
+    windmagic
+  };
 
+  enum Attribute {
+    charisma,
+    agility,
+    intuition,
+    constitution,
+    mystic,
+    strength,
+    mind,
+    willpower
+  };
+
+  static const std::unordered_map<Skill, std::pair<Attribute, Attribute>> skillAttributes{
+    {acrobatics, {agility, strength}},
+    {alchemy, {mystic, mind}},
+    {leadership, {charisma, willpower}},
+    {arcanelore, {mystic, mind}},
+    {athletics, {agility, strength}},
+    {performance, {charisma, willpower}},
+    {diplomacy, {charisma, mind}},
+    {clscraft, {intuition, mind}},
+    {empathy, {intuition, mind}},
+    {determination, {charisma, willpower}},
+    {dexterity, {charisma, agility}},
+    {history, {mystic, mind}},
+    {craftmanship, {constitution, mind}},
+    {heal, {intuition, mind}},
+    {stealth, {agility, intuition}},
+    {hunting, {constitution, mind}},
+    {countrylore, {intuition, mind}},
+    {nature, {intuition, mind}},
+    {eloquence, {charisma, willpower}},
+    {locksntraps, {intuition, agility}},
+    {swim, {strength, constitution}},
+    {seafaring, {agility, constitution}},
+    {streetlore, {charisma, intuition}},
+    {animals, {charisma, agility}},
+    {survival, {intuition, constitution}},
+    {perception, {intuition, willpower}},
+    {endurance, {constitution, willpower}},
+    {antimagic, {mystic, willpower}},
+    {controlmagic, {mystic, willpower}},
+    {motionmagic, {mystic, agility}},
+    {insightmagic, {mystic, mind}},
+    {stonemagic, {mystic, constitution}},
+    {firemagic, {mystic, charisma}},
+    {healmagic, {mystic, charisma}},
+    {illusionmagic, {mystic, charisma}},
+    {combatmagic, {mystic, strength}},
+    {lightmagic, {mystic, charisma}},
+    {naturemagic, {mystic, charisma}},
+    {shadowmagic, {mystic, intuition}},
+    {fatemagic, {mystic, charisma}},
+    {protectionmagic, {mystic, charisma}},
+    {enhancemagic, {mystic, strength}},
+    {deathmagic, {mystic, mind}},
+    {transformationmagic, {mystic, constitution}},
+    {watermagic, {mystic, intuition}},
+    {windmagic, {mystic, mind}}
+  };
+
+  class Character
+  {
+  public:
+    explicit Character(const QFile& file);
+    virtual ~Character() {}
+    unsigned int skill(Skill _skill) const {return skills.at(_skill);}
+    unsigned int attribute(Attribute _attribute) const {return attributes.at(_attribute);}
+
+  private:
+    const std::unordered_map<Skill, unsigned int> skills;
+    const std::unordered_map<Attribute, unsigned int> attributes;
+
+
+
+    class SkillTest
+    {
+    public:
+      SkillTest(const Character& hero, const Skill skill, const unsigned int against)
+      {
+        std::uniform_int_distribution<int> d10(1,10);
+        std::random_device generator;
+        this->d1 = d10(generator);
+        this->d2 = d10(generator);
+        this->accumulated = d1 + d2
+            + hero.skill(skill)
+            + hero.attribute(skillAttributes.at(skill).first)
+            + hero.attribute(skillAttributes.at(skill).second);
+        this->delta = accumulated - against;
+        passed = delta >= 0;
+        grade = std::abs(delta) / 3;
+      }
+
+    private:
+      unsigned int d1;
+      unsigned int d2;
+      unsigned int accumulated;
+      int delta;
+      bool passed;
+      unsigned int grade;
+    };
+  };
+}
 #endif // CHARACTER_H
diff --git a/src/definitions.h b/src/definitions.h
deleted file mode 100644 (file)
index 03aa50f..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-#ifndef DEFINITIONS_H
-#define DEFINITIONS_H
-#include <unordered_map>
-#include <utility>
-
-enum Skill {
-acrobatics,
-alchemy,
-leadership,
-arcanelore,
-athletics,
-performance,
-diplomacy,
-clscraft,
-empathy,
-determination,
-dexterity,
-history,
-craftmanship,
-heal,
-stealth,
-hunting,
-countrylore,
-nature,
-eloquence,
-locksntraps,
-swim,
-seafaring,
-streetlore,
-animals,
-survival,
-perception,
-endurance,
-antimagic,
-controlmagic,
-motionmagic,
-insightmagic,
-stonemagic,
-firemagic,
-healmagic,
-illusionmagic,
-combatmagic,
-lightmagic,
-naturemagic,
-shadowmagic,
-fatemagic,
-protectionmagic,
-enhancemagic,
-deathmagic,
-transformationmagic,
-watermagic,
-windmagic
-};
-
-enum Attribute {
-    charisma,
-    agility,
-    intuition,
-    constitution,
-    mystic,
-    strength,
-    mind,
-    willpower
-};
-
-const std::unordered_map<Skill, std::pair<Attribute, Attribute>> skillAttributes();
-
-
-
-#endif // DEFINITIONS_H
index 39daa7e9952358566547cfec92c73019f96e6614..14cf956fe68d33aeebddc7d618cdc90eb3452fb3 100644 (file)
@@ -1,6 +1,6 @@
 #include <QGuiApplication>
 #include <QQmlApplicationEngine>
-#include "definitions.h"
+
 
 int main(int argc, char *argv[])
 {
@@ -9,7 +9,7 @@ int main(int argc, char *argv[])
     QGuiApplication app(argc, argv);
 
     QQmlApplicationEngine engine;
-    const QUrl url(QStringLiteral("qrc:/main.qml"));
+    const QUrl url(QStringLiteral("qrc:/views/main.qml"));
     QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                      &app, [url](QObject *obj, const QUrl &objUrl) {
         if (!obj && url == objUrl)
diff --git a/src/qml.qrc b/src/qml.qrc
deleted file mode 100644 (file)
index 5f6483a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
-    <qresource prefix="/">
-        <file>main.qml</file>
-    </qresource>
-</RCC>
diff --git a/style.astylerc b/style.astylerc
new file mode 100644 (file)
index 0000000..5706c31
--- /dev/null
@@ -0,0 +1,12 @@
+--style=kr #mozilla
+#-s2 -p -d -H -k1 -c -xy -xC120 -xL
+indent=spaces=2
+pad-oper
+pad-paren-out
+pad-header
+align-pointer=type
+convert-tabs
+#close-templates
+max-code-length=120
+#indent-continuation=2
+#pad-comma