From ba4c0da67b24abecdcce2ac71f19358a1bc1c574 Mon Sep 17 00:00:00 2001 From: Bryce Allen Date: Wed, 5 Aug 2015 22:39:20 -0500 Subject: [PATCH] add horn notes and melodies --- bin/mkjsonapi.py | 35 +++++++++++++++++++++++++++++++---- mhapi/db.py | 13 +++++++++++++ mhapi/model.py | 7 +++++++ web/js/common.js | 15 +++++++++++++++ web/templates/weaponrow.ejs | 4 +++- web/templates/weaponstats.ejs | 12 +++++++++--- web/weaponlist.html | 1 + web/weaponplanner.html | 1 + 8 files changed, 80 insertions(+), 8 deletions(-) diff --git a/bin/mkjsonapi.py b/bin/mkjsonapi.py index 6deeb07..792707c 100755 --- a/bin/mkjsonapi.py +++ b/bin/mkjsonapi.py @@ -12,7 +12,9 @@ import _pathfix from mhapi.db import MHDB from mhapi import model -ENTITIES = "item weapon monster armor skilltree skill decoration".split() +ENTITIES = """item weapon monster armor + skilltree skill decoration + horn_melody""".split() def parse_args(argv=None): parser = argparse.ArgumentParser(description= @@ -37,9 +39,10 @@ def mkdirs_p(path): SAFE_CHARS = " &'+\"" -def file_path(path, model_object, use_name=False): - if use_name and "name" in model_object: - key = urllib.quote(model_object.name.encode("utf8"), SAFE_CHARS) +def file_path(path, model_object, alt_name_field=None): + if alt_name_field: + key = urllib.quote(model_object[alt_name_field].encode("utf8"), + SAFE_CHARS) else: key = str(model_object.id) return os.path.join(path, "%s.json" % key) @@ -171,13 +174,25 @@ def weapon_json(db, path): mkdirs_p(path) write_list_file(path, weapons) + melodies = {} + indexes = {} for w in weapons: weapon_path = file_path(path, w) w.update_indexes(indexes) data = w.as_data() + child_weapons = db.get_weapons_by_parent(w.id) data["children"] = [dict(id=c.id, name=c.name) for c in child_weapons] + + if w.horn_notes: + if w.horn_notes not in melodies: + melodies[w.horn_notes] = [ + dict(song=melody.song, effect1=melody.effect1) + for melody in db.get_horn_melodies_by_notes(w.horn_notes) + ] + data["horn_melodies"] = melodies[w.horn_notes] + with open(weapon_path, "w") as f: json.dump(data, f, cls=model.ModelJSONEncoder, indent=2) @@ -207,6 +222,18 @@ def item_json(db, path): write_index_file(path, indexes) +def horn_melody_json(db, path): + # only 143 rows, just do index with all data + melodies = db.get_horn_melodies() + mkdirs_p(path) + + indexes = {} + for melody in melodies: + melody.update_indexes(indexes) + + write_index_file(path, indexes) + + def main(): db = MHDB(_pathfix.db_path) diff --git a/mhapi/db.py b/mhapi/db.py index c0134fa..35fdb77 100644 --- a/mhapi/db.py +++ b/mhapi/db.py @@ -472,3 +472,16 @@ class MHDB(object): ON items._id = components.component_item_id WHERE created_item_id=? AND components.type=? """, (item_id, method), model_cls=model.ItemComponent) + + def get_horn_melodies(self): + return self._query_all("horn_melodies", """ + SELECT * + FROM horn_melodies + """, model_cls=model.HornMelody) + + def get_horn_melodies_by_notes(self, notes): + return self._query_all("horn_melodies", """ + SELECT * + FROM horn_melodies + WHERE notes=? + """, (notes,), model_cls=model.HornMelody) diff --git a/mhapi/model.py b/mhapi/model.py index 8eed700..7a0a02f 100644 --- a/mhapi/model.py +++ b/mhapi/model.py @@ -377,6 +377,13 @@ class Location(RowModel): pass +class HornMelody(RowModel): + _list_fields = ["notes", "song", "effect1", "effect2", + "duration", "extension"] + _indexes = { "notes": ["song", "effect1", "effect2", "duration", + "extension"] } + + class MonsterPartStateDamage(RowModel): """ Model for the damage to the monster on a particular hitbox and in diff --git a/web/js/common.js b/web/js/common.js index 8a0d941..b6a4985 100644 --- a/web/js/common.js +++ b/web/js/common.js @@ -220,3 +220,18 @@ function set_sharpness_titles(weapon_data) { weapon_data["sharpness_all_title"] = ""; } } + + +function set_horn_melodies_title(weapon_data) { + if (! weapon_data["horn_notes"]) { + weapon_data["horn_melodies_title"] = "" + return; + } + + var lines = []; + $.each(weapon_data["horn_melodies"], function(i, melody) { + var space = Array(6 - melody["song"].length).join(" "); + lines.push(melody["song"] + space + melody["effect1"]); + }); + weapon_data["horn_melodies_title"] = lines.join(" "); +} diff --git a/web/templates/weaponrow.ejs b/web/templates/weaponrow.ejs index 69998e4..c86a2f0 100644 --- a/web/templates/weaponrow.ejs +++ b/web/templates/weaponrow.ejs @@ -1,4 +1,4 @@ - + <% if (final == 1) { %> * <% } else { %> @@ -57,4 +57,6 @@ <%= defense ? "+" + defense + " Def" : "" %> <%= phial %> <%= shelling_type %> +<%= horn_notes %> diff --git a/web/templates/weaponstats.ejs b/web/templates/weaponstats.ejs index 64e6504..65f390b 100644 --- a/web/templates/weaponstats.ejs +++ b/web/templates/weaponstats.ejs @@ -1,9 +1,15 @@ - + - - + diff --git a/web/weaponlist.html b/web/weaponlist.html index 2090502..08b74f7 100644 --- a/web/weaponlist.html +++ b/web/weaponlist.html @@ -232,6 +232,7 @@ return; } set_sharpness_titles(data); + set_horn_melodies_title(data); data["wtype_short"] = WEAPON_TYPE_ABBR[data["wtype"]]; data["ELEMENT_ABBR"] = ELEMENT_ABBR; diff --git a/web/weaponplanner.html b/web/weaponplanner.html index c63c4fe..15e520f 100644 --- a/web/weaponplanner.html +++ b/web/weaponplanner.html @@ -179,6 +179,7 @@ $.getJSON(DATA_PATH + "weapon/" + weapon_id + ".json", function(data) { set_sharpness_titles(data); + set_horn_melodies_title(data); var html = template_stats.render(data); $("#weapon_stats").html(html); });
<%= name %> (<%= wtype %>)<% if (phial) { %><<%= phial %> Phial><% } %><% if (shelling_type) { %><<%= shelling_type %>><% } %><% if (phial) { + %><<%= phial %> Phial><% + } else if (shelling_type) { + %><<%= shelling_type %>><% + } else if (horn_notes) { + %>[<%= horn_notes %>]<% + } %> <%= Array(num_slots + 1).join("o") %><%= Array(3 - num_slots + 1).join("-") %>