add active skills with description tooltip

main
Bryce Allen 11 years ago
parent 99f5283c71
commit 3f619579f0

@ -119,6 +119,21 @@ def decoration_json(db, path):
write_all_file(path, all_data) 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): def skilltree_json(db, path):
skill_trees = db.get_skill_trees() skill_trees = db.get_skill_trees()
mkdirs_p(path) mkdirs_p(path)
@ -185,12 +200,11 @@ def main():
outpath = os.path.join(_pathfix.web_path, "jsonapi") outpath = os.path.join(_pathfix.web_path, "jsonapi")
weapon_json(db, os.path.join(outpath, "weapon")) weapon_json(db, os.path.join(outpath, "weapon"))
sys.exit(0)
items_json(db, os.path.join(outpath, "item")) items_json(db, os.path.join(outpath, "item"))
monster_json(db, os.path.join(outpath, "monster")) monster_json(db, os.path.join(outpath, "monster"))
armor_json(db, os.path.join(outpath, "armor")) armor_json(db, os.path.join(outpath, "armor"))
skilltree_json(db, os.path.join(outpath, "skilltree")) skilltree_json(db, os.path.join(outpath, "skilltree"))
skill_json(db, os.path.join(outpath, "skill"))
decoration_json(db, os.path.join(outpath, "decoration")) decoration_json(db, os.path.join(outpath, "decoration"))
#quest_json(db, os.path.join(outpath, "quest")) #quest_json(db, os.path.join(outpath, "quest"))

@ -379,7 +379,7 @@ class MHDB(object):
""", (name,), model_cls=model.Decoration) """, (name,), model_cls=model.Decoration)
def get_skill_trees(self): def get_skill_trees(self):
return self._query_all("skills", """ return self._query_all("skill_trees", """
SELECT _id, name FROM skill_trees SELECT _id, name FROM skill_trees
""", model_cls=model.SkillTree) """, model_cls=model.SkillTree)
@ -392,6 +392,13 @@ class MHDB(object):
return result["_id"] return result["_id"]
return None 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): def get_decorations_by_skills(self, skill_tree_ids):
args = sorted(skill_tree_ids) args = sorted(skill_tree_ids)
placeholders = ", ".join(["?"] * len(skill_tree_ids)) placeholders = ", ".join(["?"] * len(skill_tree_ids))

@ -302,6 +302,13 @@ class SkillTree(RowModel):
return data return data
class Skill(RowModel):
_list_fields = ["id", "name"]
_indexes = { "skill_tree_id":
["id", "required_skill_tree_points", "name", "description"] }
class Weapon(RowModel): class Weapon(RowModel):
_list_fields = ["id", "wtype", "name"] _list_fields = ["id", "wtype", "name"]
_indexes = { "name": "id", _indexes = { "name": "id",

@ -45,6 +45,9 @@
// dict mapping skill name to object // dict mapping skill name to object
var skill_trees = {}; 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 // dict mapping type to armor data, including dummy dict for Weapon and
// Talisman (containing "num_slots" and "skills" dicts // Talisman (containing "num_slots" and "skills" dicts
var armors = { var armors = {
@ -69,8 +72,13 @@
$.getJSON(DATA_PATH + "skilltree/_all.json", $.getJSON(DATA_PATH + "skilltree/_all.json",
function(data) { function(data) {
skill_trees = data; skill_trees = data;
setup_talisman_autocomplete(); $.getJSON(DATA_PATH +
load_local_storage(); "skill/_index_skill_tree_id.json",
function(data) {
tree_skills = data;
setup_talisman_autocomplete();
load_local_storage();
});
}); });
}); });
$("#armor_table").on("click", "button.add_decoration", $("#armor_table").on("click", "button.add_decoration",
@ -605,7 +613,7 @@
tskills_by_type[type][skill_name] = 0; tskills_by_type[type][skill_name] = 0;
} }
tskills_by_type[type][skill_name] += skill_value; tskills_by_type[type][skill_name] += skill_value;
}) });
$.each(gear_decorations, function(i, decoration) { $.each(gear_decorations, function(i, decoration) {
$.each(decoration["skills"], $.each(decoration["skills"],
function(skill_name, skill_value) { function(skill_name, skill_value) {
@ -625,7 +633,7 @@
tskills_by_type[type][skill_name] += skill_value; tskills_by_type[type][skill_name] += skill_value;
} }
); );
}) });
$.each(ELEMENTS, function(i, element) { $.each(ELEMENTS, function(i, element) {
key = element + "_res"; key = element + "_res";
if (armor[key] == undefined) { if (armor[key] == undefined) {
@ -636,7 +644,7 @@
} }
element_resist[element] += armor[key]; element_resist[element] += armor[key];
$("#" + type + "_" + element).html(armor[key]); $("#" + type + "_" + element).html(armor[key]);
}) });
slots += armor["num_slots"]; slots += armor["num_slots"];
slots_free += slots_left[type] || 0; slots_free += slots_left[type] || 0;
//$("#" + type + "_slots").html(armor["num_slots"]); //$("#" + type + "_slots").html(armor["num_slots"]);
@ -651,12 +659,34 @@
return sb - sa; 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<current_tree_skills.length; i++) {
var skill = current_tree_skills[i];
required_points = skill["required_skill_tree_points"];
if (total_points > 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( var skills_table = template_skills.render(
{ TYPES: GEAR, { TYPES: GEAR,
skills: skills, skills: skills,
dskills_by_type: dskills_by_type, dskills_by_type: dskills_by_type,
tskills_by_type: tskills_by_type, tskills_by_type: tskills_by_type,
active_skills: skill_names, skill_names: skill_names,
active_skills: active_skills,
armors: armors }); armors: armors });
$("#skills_div").html(skills_table); $("#skills_div").html(skills_table);

@ -2,21 +2,23 @@
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>Total</th> <th>Total</th>
<th>Skill</th>
<% for(var i=0; i<TYPES.length; i++) { %> <% for(var i=0; i<TYPES.length; i++) { %>
<td><%= TYPES[i] %></td> <td><%= TYPES[i] %></td>
<% } %> <% } %>
</tr> </tr>
<% for(var i=0; i<active_skills.length; i++) { %> <% for(var i=0; i<skill_names.length; i++) { %>
<tr> <tr>
<td><%= active_skills[i] %></td> <td><%= skill_names[i] %></td>
<td class="num"><%= skills[active_skills[i]] %></td> <td class="num"><%= skills[skill_names[i]] %></td>
<td title="<%= active_skills[skill_names[i]]
? active_skills[skill_names[i]]["description"] : "No Skills" %>"
><%= active_skills[skill_names[i]]
? active_skills[skill_names[i]]["name"] : "&nbsp;" %></td>
<% for(var j=0; j<TYPES.length; j++) { %> <% for(var j=0; j<TYPES.length; j++) { %>
<td class="num"> <td class="num">
<%= (armors[TYPES[j]] && tskills_by_type[TYPES[j]][active_skills[i]]) <%= (armors[TYPES[j]] && tskills_by_type[TYPES[j]][skill_names[i]])
? tskills_by_type[TYPES[j]][active_skills[i]] ? tskills_by_type[TYPES[j]][skill_names[i]]
: "&nbsp;" %>
<%= 0 && (armors[TYPES[j]] && dskills_by_type[TYPES[j]][active_skills[i]])
? " (" + dskills_by_type[TYPES[j]][active_skills[i]] + ")"
: "&nbsp;" %> : "&nbsp;" %>
</td> </td>
<% } %> <% } %>

Loading…
Cancel
Save