diff --git a/bin/mkjsonapi.py b/bin/mkjsonapi.py index 2856743..e25d03a 100755 --- a/bin/mkjsonapi.py +++ b/bin/mkjsonapi.py @@ -119,6 +119,21 @@ def decoration_json(db, path): write_all_file(path, all_data) +def skill_json(db, path): + skills = db.get_skills() + mkdirs_p(path) + write_list_file(path, skills) + + indexes = {} + for s in skills: + s.update_indexes(indexes) + skill_path = file_path(path, s) + with open(skill_path, "w") as f: + s.json_dump(f) + + write_index_file(path, indexes) + + def skilltree_json(db, path): skill_trees = db.get_skill_trees() mkdirs_p(path) @@ -185,12 +200,11 @@ def main(): outpath = os.path.join(_pathfix.web_path, "jsonapi") weapon_json(db, os.path.join(outpath, "weapon")) - sys.exit(0) - items_json(db, os.path.join(outpath, "item")) monster_json(db, os.path.join(outpath, "monster")) armor_json(db, os.path.join(outpath, "armor")) skilltree_json(db, os.path.join(outpath, "skilltree")) + skill_json(db, os.path.join(outpath, "skill")) decoration_json(db, os.path.join(outpath, "decoration")) #quest_json(db, os.path.join(outpath, "quest")) diff --git a/mhapi/db.py b/mhapi/db.py index 15fe228..99f5510 100644 --- a/mhapi/db.py +++ b/mhapi/db.py @@ -379,7 +379,7 @@ class MHDB(object): """, (name,), model_cls=model.Decoration) def get_skill_trees(self): - return self._query_all("skills", """ + return self._query_all("skill_trees", """ SELECT _id, name FROM skill_trees """, model_cls=model.SkillTree) @@ -392,6 +392,13 @@ class MHDB(object): return result["_id"] return None + def get_skills(self): + return self._query_all("skills", """ + SELECT _id, skill_tree_id, required_skill_tree_points, + name, description + FROM skills + """, model_cls=model.Skill) + def get_decorations_by_skills(self, skill_tree_ids): args = sorted(skill_tree_ids) placeholders = ", ".join(["?"] * len(skill_tree_ids)) diff --git a/mhapi/model.py b/mhapi/model.py index 3a686e3..3799710 100644 --- a/mhapi/model.py +++ b/mhapi/model.py @@ -302,6 +302,13 @@ class SkillTree(RowModel): return data +class Skill(RowModel): + _list_fields = ["id", "name"] + _indexes = { "skill_tree_id": + ["id", "required_skill_tree_points", "name", "description"] } + + + class Weapon(RowModel): _list_fields = ["id", "wtype", "name"] _indexes = { "name": "id", diff --git a/web/outfitters.html b/web/outfitters.html index dba0882..bfbb434 100644 --- a/web/outfitters.html +++ b/web/outfitters.html @@ -45,6 +45,9 @@ // dict mapping skill name to object var skill_trees = {}; + // dict mapping skill_tree_id to list of skill dicts, highest point first + var tree_skills = {}; + // dict mapping type to armor data, including dummy dict for Weapon and // Talisman (containing "num_slots" and "skills" dicts var armors = { @@ -69,8 +72,13 @@ $.getJSON(DATA_PATH + "skilltree/_all.json", function(data) { skill_trees = data; - setup_talisman_autocomplete(); - load_local_storage(); + $.getJSON(DATA_PATH + + "skill/_index_skill_tree_id.json", + function(data) { + tree_skills = data; + setup_talisman_autocomplete(); + load_local_storage(); + }); }); }); $("#armor_table").on("click", "button.add_decoration", @@ -605,7 +613,7 @@ tskills_by_type[type][skill_name] = 0; } tskills_by_type[type][skill_name] += skill_value; - }) + }); $.each(gear_decorations, function(i, decoration) { $.each(decoration["skills"], function(skill_name, skill_value) { @@ -625,7 +633,7 @@ tskills_by_type[type][skill_name] += skill_value; } ); - }) + }); $.each(ELEMENTS, function(i, element) { key = element + "_res"; if (armor[key] == undefined) { @@ -636,7 +644,7 @@ } element_resist[element] += armor[key]; $("#" + type + "_" + element).html(armor[key]); - }) + }); slots += armor["num_slots"]; slots_free += slots_left[type] || 0; //$("#" + type + "_slots").html(armor["num_slots"]); @@ -651,12 +659,34 @@ return sb - sa; }); + var active_skills = {} + $.each(skills, function(skill_name, total_points) { + var skill_tree_id = skill_trees[skill_name]["id"]; + var current_tree_skills = tree_skills[skill_tree_id] || []; + for (i=0; i 0) { + if (total_points >= required_points && required_points > 0) { + active_skills[skill_name] = skill; + break; + } + } else if (total_points < 0) { + if (total_points <= required_points && required_points < 0) { + active_skills[skill_name] = skill; + break; + } + } + } + }); + var skills_table = template_skills.render( { TYPES: GEAR, skills: skills, dskills_by_type: dskills_by_type, tskills_by_type: tskills_by_type, - active_skills: skill_names, + skill_names: skill_names, + active_skills: active_skills, armors: armors }); $("#skills_div").html(skills_table); diff --git a/web/templates/skills.ejs b/web/templates/skills.ejs index ed67c8b..62ffdd1 100644 --- a/web/templates/skills.ejs +++ b/web/templates/skills.ejs @@ -2,21 +2,23 @@   Total + Skill <% for(var i=0; i <%= TYPES[i] %> <% } %> -<% for(var i=0; i +<% for(var i=0; i - <%= active_skills[i] %> - <%= skills[active_skills[i]] %> + <%= skill_names[i] %> + <%= skills[skill_names[i]] %> + " + ><%= active_skills[skill_names[i]] + ? active_skills[skill_names[i]]["name"] : " " %> <% for(var j=0; j - <%= (armors[TYPES[j]] && tskills_by_type[TYPES[j]][active_skills[i]]) - ? tskills_by_type[TYPES[j]][active_skills[i]] - : " " %> - <%= 0 && (armors[TYPES[j]] && dskills_by_type[TYPES[j]][active_skills[i]]) - ? " (" + dskills_by_type[TYPES[j]][active_skills[i]] + ")" + <%= (armors[TYPES[j]] && tskills_by_type[TYPES[j]][skill_names[i]]) + ? tskills_by_type[TYPES[j]][skill_names[i]] : " " %> <% } %>