diff options
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/cmd.h | 1 | ||||
-rw-r--r-- | src/cmd/cmd_manipulate.cc | 102 | ||||
-rw-r--r-- | src/cmd/cmd_usage.cc | 4 |
3 files changed, 98 insertions, 9 deletions
diff --git a/src/cmd/cmd.h b/src/cmd/cmd.h index ff96b32..1763f95 100644 --- a/src/cmd/cmd.h +++ b/src/cmd/cmd.h @@ -29,6 +29,7 @@ namespace cmd { std::string del(std::vector<std::string> args); std::string edit(std::vector<std::string> args); std::string spellcasting(std::vector<std::string> args); + std::string create(std::vector<std::string> args); std::string git(std::vector<std::string> args); //Queries diff --git a/src/cmd/cmd_manipulate.cc b/src/cmd/cmd_manipulate.cc index 904615b..f0d3fc4 100644 --- a/src/cmd/cmd_manipulate.cc +++ b/src/cmd/cmd_manipulate.cc @@ -44,7 +44,7 @@ namespace cmd { } else { c->applyDamage(amnt, dmgType, qualifiers); } - utils::saveJson(*c, p); + utils::saveJson(c->serialize(), p); return formatHealingDamage(c, initHP, heal, amnt, dmgType, qualifiers); } @@ -159,7 +159,7 @@ namespace cmd { if(flags.find("damage") != flags.end() and (halves or ! passed)) { text << formatHealingDamage(c, initHP, false, damage, type, parseQualifiers(flags)); } - utils::saveJson(*c, p); + utils::saveJson(c->serialize(), p); } return text.str(); } @@ -169,7 +169,7 @@ namespace cmd { fs::path p = getTruePath(s); auto c = utils::instantiate<creature::Creature>(p); c->longRest(); - utils::saveJson(*c, p); + utils::saveJson(c->serialize(), p); } return ""; } @@ -180,13 +180,32 @@ namespace cmd { } fs::path p = getTruePath(args[0]); args.erase(args.begin()); // remove path from args - auto c = utils::instantiate<creature::Creature>(p); if(args[0] == "name") { args.erase(args.begin()); // remove "name" from args - c->setGivenName(utils::join(args, " ")); + auto newname = utils::join(args, " "); + auto e = utils::instantiate<entry::Entry>(p); + if(e->getEntryType() == "creatures") { // creature, we should do given name instead + auto c = utils::instantiate<creature::Creature>(p); + c->setGivenName(newname); + utils::saveJson(c->serialize(), p); + } else { // Standard entry, no given name so we set name + e->setName(newname); + utils::saveJson(e->serialize(), p); + } } else if(args[0] == "proficiency") { + auto c = utils::instantiate<creature::Creature>(p); c->setProficiency(utils::parseInt(args[1])); + utils::saveJson(c->serialize(), p); + } else if(args[0] == "cost") { + auto i = utils::instantiate<entry::Item>(p); + i->setCost(utils::parseInt(args[1])); + utils::saveJson(i->serialize(), p); + } else if(args[0] == "weight") { + auto i = utils::instantiate<entry::Item>(p); + i->setWeight(utils::parseDouble(args[1])); + utils::saveJson(i->serialize(), p); } else { + auto c = utils::instantiate<creature::Creature>(p); // Either an ability or a skill. If skill, then it could be multiple words long. std::string toSet = args.back(); args.erase(--args.end()); @@ -209,8 +228,8 @@ namespace cmd { } else { throw std::runtime_error("Subcommand 'set' expected an ability, skill, proficiency, or name field to set, but was given " + abilityOrSkill); } + utils::saveJson(c->serialize(), p); } - utils::saveJson(*c, p); return ""; } @@ -239,7 +258,7 @@ namespace cmd { throw std::runtime_error("Could not add the " + ent->getType() + " " + ent->getName() + " to " + c->getGivenName() + " the " + c->getName() + ": Requires a weapon, armor, or spell, but received object of type " + ent->getType()); } } - utils::saveJson(*c, p); + utils::saveJson(c->serialize(), p); text << "Added the " << ent->getType() << " " << ent->getName() << " to " << c->getGivenName() << " the " << c->getName() << std::endl; return text.str(); } @@ -278,7 +297,7 @@ namespace cmd { } } } - utils::saveJson(*c, p); + utils::saveJson(c->serialize(), p); if(removed) { text << "Successfully removed the " << removed->Entry::getType() << " " << removed->getName() << std::endl; } else { @@ -342,10 +361,75 @@ namespace cmd { text << "Gave " << c->getName() << " " << slots << " " << utils::toOrdinal(level) << " level spell slots" << std::endl; } } - utils::saveJson(*c, p); + utils::saveJson(c->serialize(), p); return text.str(); } + std::string create(std::vector<std::string> args) { + auto p = getTruePath(args[0]); + args.erase(args.begin()); // remove path from args + auto name = args[1]; + if(args[0] == "item") { + nlohmann::json j = entry::Entry("item", name, "item", ""); + j["cost"] = 0; + j["weight"] = 0.0; + utils::saveJson(j, p); + } else if(args[0] == "weapon" or args[0] == "feature_attack") { + nlohmann::json j = entry::Entry((args[0] == "weapon")? "item" : "feature", name, "weapons", ""); + j["cost"] = 0; + j["weight"] = 0.0; + j["damage"] = {{{"dmg_die_count", 1}, {"dmg_die_sides", 6}, {"dmg_type", "bludgeoning"}, {"is_or", false}}}; + j["properties"] = std::vector<std::string>(); + j["weapon_type"] = ""; + j["range"] = {0, 0}; + j["reach"] = 5; + j["toHitOverride"] = {}; // Set to null + j["dmgBonusOverride"] = {}; + j["abilityOverride"] = {}; + utils::saveJson(j, p); + } else if(args[0] == "armor") { + nlohmann::json j = entry::Entry("item", name, "armor", ""); + j["cost"] = 0; + j["weight"] = 0.0; + j["ac"] = 10; + j["strength"] = 0; + j["disadvantage"] = false; + j["armor_type"] = "light"; + utils::saveJson(j, p); + } else if(args[0] == "spell") { + nlohmann::json j = entry::Entry("spells", name, "UNKNOWN", ""); + j["level"] = 0; + j["classes"] = std::vector<std::string>(); + j["casting_time"] = "1 action"; + j["range"] = "Touch"; + j["components"] = "V, S, M"; + j["duration"] = "Instantaneous"; + utils::saveJson(j, p); + } else if(args[0] == "feature") { + nlohmann::json j = entry::Entry("feature", name, "feature", ""); + utils::saveJson(j, p); + } else if(args[0] == "creature") { + nlohmann::json j = entry::Entry("creatures", name, "UNKNOWN", ""); + j["givenName"] = "NAME"; + j["hpMax"] = j["hp"] = -1; + j["inventory"] = j["saves"] = j["senses"] = j["d_resistances"] = j["d_vulnerabilities"] = j["d_immunities"] = j["c_immunities"] = j["features"] = std::vector<std::string>(); + j["skills"] = std::map<std::string, std::string>(); + j["stats"] = {{"str", 10}, {"dex", 10}, {"con", 10}, {"int", 10}, {"wis", 10}, {"cha", 10}}; + j["prof"] = 2; + j["size"] = "Medium"; + j["alignment"] = "any alignment"; + j["hit_die_count"] = 1; + j["hit_die_sides"] = 8; + j["speed"] = "30 ft."; + j["langs"] = "any one language (usually Common)"; + j["cr"] = 0.0; + j["observant"] = false; + j["natural_armor"] = {{"name", ""}, {"bonus", 0}}; + utils::saveJson(j, p); + } + return "Successfully created " + args[0] + " " + args[1] + ".\n"; + } + std::string git(std::vector<std::string> args) { std::string root = getTruePath("").string(); std::system(("cd " + root + " && " + utils::join(args, " ")).c_str()); diff --git a/src/cmd/cmd_usage.cc b/src/cmd/cmd_usage.cc index 44daca4..4f8d82f 100644 --- a/src/cmd/cmd_usage.cc +++ b/src/cmd/cmd_usage.cc @@ -40,6 +40,8 @@ namespace cmd { text << indDesc << " skill (athletics, \"sleight of hand\", etc.); value is (none|proficient|expert)" << std::endl; text << indDesc << " proficiency; value is new proficency bonus." << std::endl; text << indDesc << " name; value is new given name." << std::endl; + text << indDesc << " cost; (for an item) value is cost in cp." << std::endl; + text << indDesc << " weight; (for an item) value is weight in lbs." << std::endl; text << indOpt << "edit path" << std::endl; text << indDesc << "Edit notes associated with creature." << std::endl; text << indOpt << "add path entry" << std::endl; @@ -51,6 +53,8 @@ namespace cmd { text << indDesc << " init; adds spellcasting to a creature which currently does not have spellcasting" << std::endl; text << indDesc << " ability value; sets the spellcasting ability, where value is the ability name" << std::endl; text << indDesc << " level l slots; sets the number of slots at spell level l to slots" << std::endl; + text << indOpt << "create path type name" << std::endl; + text << indDesc << "Create a new entry at path location of type and name, where type is any of item, weapon, armor, spell, feature, feature_attack, creature." << std::endl; text << indOpt << "git [command]" << std::endl; text << indDesc << "Execute a git command within the dmtool folder." << std::endl; text << indOpt << "help" << std::endl; |