add html/jsonapi armor builder
- make decoration calculator use 1-slot decorations multiple times
This commit is contained in:
@@ -7,9 +7,9 @@ import codecs
|
||||
import _pathfix
|
||||
|
||||
from mhapi.db import MHDB
|
||||
from mhapi.model import get_decoration_values
|
||||
from mhapi.util import get_utf8_writer
|
||||
|
||||
def get_utf8_writer(writer):
|
||||
return codecs.getwriter("utf8")(writer)
|
||||
|
||||
def parse_args(argv):
|
||||
parser = argparse.ArgumentParser(description=
|
||||
@@ -46,7 +46,7 @@ def find_armors(args):
|
||||
ds = db.get_decorations_by_skills([sid])
|
||||
for d in ds:
|
||||
d.set_skills(db.get_item_skills(d.id))
|
||||
decoration_values = get_decoration_values(sid, ds)
|
||||
decoration_values = get_decoration_values(sid, ds)[1]
|
||||
decorations[sid] = (ds, decoration_values)
|
||||
print "%s[%s]:" % (skill_name, sid), ", ".join(d.name for d in ds), \
|
||||
decoration_values
|
||||
@@ -88,20 +88,6 @@ def find_armors(args):
|
||||
print " ", a.one_line_skills_u(args.skills)
|
||||
|
||||
|
||||
def get_decoration_values(skill_id, decorations):
|
||||
# TODO: write script to compute this and shove innto skill_tree table
|
||||
values = [0, 0, 0]
|
||||
for d in decorations:
|
||||
assert d.num_slots is not None
|
||||
# some skills like Handicraft have multiple decorations with
|
||||
# same number of slots - use the best one
|
||||
new = d.skills[skill_id]
|
||||
current = values[d.num_slots-1]
|
||||
if new > current:
|
||||
values[d.num_slots-1] = new
|
||||
return values
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_args(None)
|
||||
|
||||
|
||||
@@ -35,13 +35,21 @@ def file_path(path, model_object, use_name=False):
|
||||
def write_list_file(path, model_list):
|
||||
list_path = os.path.join(path, "_list.json")
|
||||
with open(list_path, "w") as f:
|
||||
json.dump([o.as_list_data() for o in model_list], f, indent=2)
|
||||
json.dump([o.as_list_data() for o in model_list],
|
||||
f, cls=model.ModelJSONEncoder, indent=2)
|
||||
|
||||
|
||||
def write_index_file(path, indexes):
|
||||
index_path = os.path.join(path, "_index.json")
|
||||
with open(index_path, "w") as f:
|
||||
json.dump(indexes, f, indent=2)
|
||||
for key, data in indexes.iteritems():
|
||||
index_path = os.path.join(path, "_index_%s.json" % key)
|
||||
with open(index_path, "w") as f:
|
||||
json.dump(data, f, cls=model.ModelJSONEncoder, indent=2)
|
||||
|
||||
|
||||
def write_all_file(path, all_data):
|
||||
all_path = os.path.join(path, "_all.json")
|
||||
with open(all_path, "w") as f:
|
||||
json.dump(all_data, f, cls=model.ModelJSONEncoder, indent=2)
|
||||
|
||||
|
||||
def monster_json(db, path):
|
||||
@@ -63,6 +71,73 @@ def monster_json(db, path):
|
||||
write_index_file(path, indexes)
|
||||
|
||||
|
||||
def armor_json(db, path):
|
||||
armors = db.get_armors()
|
||||
mkdirs_p(path)
|
||||
write_list_file(path, armors)
|
||||
all_data = []
|
||||
|
||||
indexes = {}
|
||||
for a in armors:
|
||||
armor_path = file_path(path, a)
|
||||
a.update_indexes(indexes)
|
||||
skills = db.get_item_skills(a.id)
|
||||
if not skills:
|
||||
print "WARN: armor '%s' (%d) has no skills" % (a.name, a.id)
|
||||
a.set_skills(skills)
|
||||
|
||||
all_data.append(a.as_data())
|
||||
|
||||
with open(armor_path, "w") as f:
|
||||
a.json_dump(f)
|
||||
|
||||
write_index_file(path, indexes)
|
||||
write_all_file(path, all_data)
|
||||
|
||||
|
||||
def decoration_json(db, path):
|
||||
decorations = db.get_decorations()
|
||||
mkdirs_p(path)
|
||||
write_list_file(path, decorations)
|
||||
all_data = []
|
||||
|
||||
indexes = {}
|
||||
for a in decorations:
|
||||
decoration_path = file_path(path, a)
|
||||
a.update_indexes(indexes)
|
||||
skills = db.get_item_skills(a.id)
|
||||
if not skills:
|
||||
print "WARN: decoration '%s' (%d) has no skills" % (a.name, a.id)
|
||||
a.set_skills(skills)
|
||||
|
||||
all_data.append(a.as_data())
|
||||
|
||||
with open(decoration_path, "w") as f:
|
||||
a.json_dump(f)
|
||||
|
||||
write_index_file(path, indexes)
|
||||
write_all_file(path, all_data)
|
||||
|
||||
|
||||
def skilltree_json(db, path):
|
||||
skill_trees = db.get_skill_trees()
|
||||
mkdirs_p(path)
|
||||
write_list_file(path, skill_trees)
|
||||
|
||||
all_data = {}
|
||||
for st in skill_trees:
|
||||
ds = db.get_decorations_by_skills([st.id])
|
||||
for d in ds:
|
||||
d.set_skills(db.get_item_skills(d.id))
|
||||
st.set_decorations(ds)
|
||||
skilltree_path = file_path(path, st)
|
||||
all_data[st.name] = st
|
||||
with open(skilltree_path, "w") as f:
|
||||
st.json_dump(f)
|
||||
|
||||
write_all_file(path, all_data)
|
||||
|
||||
|
||||
def weapon_json(db, path):
|
||||
weapons = db.get_weapons()
|
||||
mkdirs_p(path)
|
||||
@@ -104,7 +179,10 @@ def main():
|
||||
items_json(db, os.path.join(outpath, "item"))
|
||||
weapon_json(db, os.path.join(outpath, "weapon"))
|
||||
monster_json(db, os.path.join(outpath, "monster"))
|
||||
#quest_json
|
||||
armor_json(db, os.path.join(outpath, "armor"))
|
||||
skilltree_json(db, os.path.join(outpath, "skilltree"))
|
||||
decoration_json(db, os.path.join(outpath, "decoration"))
|
||||
#quest_json(db, os.path.join(outpath, "quest"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user