new web index, refactor, data fixes
This commit is contained in:
@@ -7,7 +7,7 @@ import json
|
||||
import _pathfix
|
||||
|
||||
from mhapi.db import MHDB
|
||||
from mhapi.model import ModelJSONEncoder
|
||||
from mhapi.model import ModelJSONEncoder, get_costs
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
@@ -23,36 +23,6 @@ def parse_args(argv):
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def get_costs(db, weapon):
|
||||
"""
|
||||
Get a list of alternative ways of making a weapon, as a list of dicts
|
||||
containing item counts. The dicts also contain special keys _zenny
|
||||
for the total zenny needed, and _path for a list of weapons that
|
||||
make up the upgrade path.
|
||||
"""
|
||||
costs = []
|
||||
if weapon.parent_id:
|
||||
parent_weapon = db.get_weapon(weapon.parent_id, True)
|
||||
costs = get_costs(db, parent_weapon)
|
||||
for cost in costs:
|
||||
for item in weapon.upgrade_components:
|
||||
if item.type == "Weapon":
|
||||
continue
|
||||
if item.name not in cost["components"]:
|
||||
cost["components"][item.name] = 0
|
||||
cost["components"][item.name] += item.quantity
|
||||
cost["zenny"] += weapon.upgrade_cost
|
||||
cost["path"] += [weapon]
|
||||
if weapon.creation_cost:
|
||||
create_cost = dict(zenny=weapon.creation_cost,
|
||||
path=[weapon],
|
||||
components={})
|
||||
for item in weapon.create_components:
|
||||
create_cost["components"][item.name] = item.quantity
|
||||
costs = [create_cost] + costs
|
||||
return costs
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_args(None)
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ def skilltree_json(db, path):
|
||||
|
||||
|
||||
def weapon_json(db, path):
|
||||
weapons = db.get_weapons()
|
||||
weapons = db.get_weapons(get_components=True)
|
||||
mkdirs_p(path)
|
||||
write_list_file(path, weapons)
|
||||
|
||||
@@ -150,6 +150,14 @@ def weapon_json(db, path):
|
||||
with open(weapon_path, "w") as f:
|
||||
w.json_dump(f)
|
||||
|
||||
tree_path = os.path.join(path, "%s_tree.json" % w.id)
|
||||
costs = model.get_costs(db, w)
|
||||
for cost in costs:
|
||||
cost["path"] = [dict(name=w.name, id=w.id)
|
||||
for w in cost["path"]]
|
||||
with open(tree_path, "w") as f:
|
||||
json.dump(costs, f, cls=model.ModelJSONEncoder, indent=2)
|
||||
|
||||
write_index_file(path, indexes)
|
||||
|
||||
|
||||
@@ -176,12 +184,15 @@ def main():
|
||||
else:
|
||||
outpath = os.path.join(_pathfix.web_path, "jsonapi")
|
||||
|
||||
items_json(db, os.path.join(outpath, "item"))
|
||||
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"))
|
||||
decoration_json(db, os.path.join(outpath, "decoration"))
|
||||
|
||||
#quest_json(db, os.path.join(outpath, "quest"))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user