add horn notes and melodies

main
Bryce Allen 10 years ago
parent feb419c98a
commit ba4c0da67b

@ -12,7 +12,9 @@ import _pathfix
from mhapi.db import MHDB from mhapi.db import MHDB
from mhapi import model 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): def parse_args(argv=None):
parser = argparse.ArgumentParser(description= parser = argparse.ArgumentParser(description=
@ -37,9 +39,10 @@ def mkdirs_p(path):
SAFE_CHARS = " &'+\"" SAFE_CHARS = " &'+\""
def file_path(path, model_object, use_name=False): def file_path(path, model_object, alt_name_field=None):
if use_name and "name" in model_object: if alt_name_field:
key = urllib.quote(model_object.name.encode("utf8"), SAFE_CHARS) key = urllib.quote(model_object[alt_name_field].encode("utf8"),
SAFE_CHARS)
else: else:
key = str(model_object.id) key = str(model_object.id)
return os.path.join(path, "%s.json" % key) return os.path.join(path, "%s.json" % key)
@ -171,13 +174,25 @@ def weapon_json(db, path):
mkdirs_p(path) mkdirs_p(path)
write_list_file(path, weapons) write_list_file(path, weapons)
melodies = {}
indexes = {} indexes = {}
for w in weapons: for w in weapons:
weapon_path = file_path(path, w) weapon_path = file_path(path, w)
w.update_indexes(indexes) w.update_indexes(indexes)
data = w.as_data() data = w.as_data()
child_weapons = db.get_weapons_by_parent(w.id) child_weapons = db.get_weapons_by_parent(w.id)
data["children"] = [dict(id=c.id, name=c.name) for c in child_weapons] 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: with open(weapon_path, "w") as f:
json.dump(data, f, cls=model.ModelJSONEncoder, indent=2) json.dump(data, f, cls=model.ModelJSONEncoder, indent=2)
@ -207,6 +222,18 @@ def item_json(db, path):
write_index_file(path, indexes) 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(): def main():
db = MHDB(_pathfix.db_path) db = MHDB(_pathfix.db_path)

@ -472,3 +472,16 @@ class MHDB(object):
ON items._id = components.component_item_id ON items._id = components.component_item_id
WHERE created_item_id=? AND components.type=? WHERE created_item_id=? AND components.type=?
""", (item_id, method), model_cls=model.ItemComponent) """, (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)

@ -377,6 +377,13 @@ class Location(RowModel):
pass pass
class HornMelody(RowModel):
_list_fields = ["notes", "song", "effect1", "effect2",
"duration", "extension"]
_indexes = { "notes": ["song", "effect1", "effect2", "duration",
"extension"] }
class MonsterPartStateDamage(RowModel): class MonsterPartStateDamage(RowModel):
""" """
Model for the damage to the monster on a particular hitbox and in Model for the damage to the monster on a particular hitbox and in

@ -220,3 +220,18 @@ function set_sharpness_titles(weapon_data) {
weapon_data["sharpness_all_title"] = ""; 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("
");
}

@ -1,4 +1,4 @@
<tr> <tr title="id: <%= id %>">
<td><% if (final == 1) { %> <td><% if (final == 1) { %>
<strong>*</strong> <strong>*</strong>
<% } else { %> <% } else { %>
@ -57,4 +57,6 @@
<td><%= defense ? "+" + defense + " Def" : "" %></td> <td><%= defense ? "+" + defense + " Def" : "" %></td>
<td style="text-align:right"><%= phial %></td> <td style="text-align:right"><%= phial %></td>
<td style="text-align:right"><%= shelling_type %></td> <td style="text-align:right"><%= shelling_type %></td>
<td title="<%= horn_melodies_title %>"
style="text-align:right"><%= horn_notes %></td>
</tr> </tr>

@ -1,9 +1,15 @@
<table> <table>
<tr> <tr title="<%= id %>">
<td><%= name %></td> <td><%= name %></td>
<td>(<%= wtype %>)</td> <td>(<%= wtype %>)</td>
<td><% if (phial) { %>&lt;<%= phial %> Phial&gt;<% } %></td> <td><% if (phial) {
<td><% if (shelling_type) { %>&lt;<%= shelling_type %>&gt;<% } %></td> %>&lt;<%= phial %> Phial&gt;<%
} else if (shelling_type) {
%>&lt;<%= shelling_type %>&gt;<%
} else if (horn_notes) {
%><span title="<%= horn_melodies_title %>"
>[<%= horn_notes %>]<%
} %></td>
<td><%= Array(num_slots + 1).join("o") <td><%= Array(num_slots + 1).join("o")
%><%= Array(3 - num_slots + 1).join("-") %></td> %><%= Array(3 - num_slots + 1).join("-") %></td>
</tr> </tr>

@ -232,6 +232,7 @@
return; return;
} }
set_sharpness_titles(data); set_sharpness_titles(data);
set_horn_melodies_title(data);
data["wtype_short"] = data["wtype_short"] =
WEAPON_TYPE_ABBR[data["wtype"]]; WEAPON_TYPE_ABBR[data["wtype"]];
data["ELEMENT_ABBR"] = ELEMENT_ABBR; data["ELEMENT_ABBR"] = ELEMENT_ABBR;

@ -179,6 +179,7 @@
$.getJSON(DATA_PATH + "weapon/" + weapon_id + ".json", $.getJSON(DATA_PATH + "weapon/" + weapon_id + ".json",
function(data) { function(data) {
set_sharpness_titles(data); set_sharpness_titles(data);
set_horn_melodies_title(data);
var html = template_stats.render(data); var html = template_stats.render(data);
$("#weapon_stats").html(html); $("#weapon_stats").html(html);
}); });

Loading…
Cancel
Save