From 06794cf580770ba32112a145924aecc372efeb02 Mon Sep 17 00:00:00 2001 From: John Janus Date: Tue, 13 Aug 2019 08:12:50 +0200 Subject: [PATCH] small progress towards skill def --- resources/views.qrc | 6 ++ {src => resources/views}/main.qml | 0 splittermond-assistant.pro | 17 ++-- src/character.cpp | 7 +- src/character.h | 159 +++++++++++++++++++++++++++++- src/definitions.h | 70 ------------- src/main.cpp | 4 +- src/qml.qrc | 5 - style.astylerc | 12 +++ 9 files changed, 189 insertions(+), 91 deletions(-) create mode 100644 resources/views.qrc rename {src => resources/views}/main.qml (100%) delete mode 100644 src/definitions.h delete mode 100644 src/qml.qrc create mode 100644 style.astylerc diff --git a/resources/views.qrc b/resources/views.qrc new file mode 100644 index 0000000..a48eeca --- /dev/null +++ b/resources/views.qrc @@ -0,0 +1,6 @@ + + + + views/main.qml + + diff --git a/src/main.qml b/resources/views/main.qml similarity index 100% rename from src/main.qml rename to resources/views/main.qml diff --git a/splittermond-assistant.pro b/splittermond-assistant.pro index 45b3835..4dc6d79 100644 --- a/splittermond-assistant.pro +++ b/splittermond-assistant.pro @@ -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 diff --git a/src/character.cpp b/src/character.cpp index 0a0455f..04907ee 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -1,6 +1,7 @@ #include "character.h" +namespace sm::data { + Character::Character(const QFile& file) + { -Character::Character() -{ - + } } diff --git a/src/character.h b/src/character.h index 61b92e3..18df734 100644 --- a/src/character.h +++ b/src/character.h @@ -2,11 +2,162 @@ #define CHARACTER_H #include +#include +#include +#include +#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> 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 skills; + const std::unordered_map attributes; + + + + class SkillTest + { + public: + SkillTest(const Character& hero, const Skill skill, const unsigned int against) + { + std::uniform_int_distribution 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 index 03aa50f..0000000 --- a/src/definitions.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef DEFINITIONS_H -#define DEFINITIONS_H -#include -#include - -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> skillAttributes(); - - - -#endif // DEFINITIONS_H diff --git a/src/main.cpp b/src/main.cpp index 39daa7e..14cf956 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include #include -#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 index 5f6483a..0000000 --- a/src/qml.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - main.qml - - diff --git a/style.astylerc b/style.astylerc new file mode 100644 index 0000000..5706c31 --- /dev/null +++ b/style.astylerc @@ -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 -- 2.47.0