mh4u: show wyp trade mouse over in planner
This commit is contained in:
@@ -14,7 +14,7 @@ from mhapi import model
|
|||||||
|
|
||||||
ENTITIES = """item weapon monster armor
|
ENTITIES = """item weapon monster armor
|
||||||
skilltree skill decoration
|
skilltree skill decoration
|
||||||
horn_melody""".split()
|
horn_melody wyporium""".split()
|
||||||
|
|
||||||
def parse_args(argv=None):
|
def parse_args(argv=None):
|
||||||
parser = argparse.ArgumentParser(description=
|
parser = argparse.ArgumentParser(description=
|
||||||
@@ -23,6 +23,7 @@ def parse_args(argv=None):
|
|||||||
parser.add_argument("-o", "--outpath",
|
parser.add_argument("-o", "--outpath",
|
||||||
help="output base directory, defaults to web/jsonapi/"
|
help="output base directory, defaults to web/jsonapi/"
|
||||||
" in project root")
|
" in project root")
|
||||||
|
parser.add_argument("-g", "--game", help="game, one of 4u, gu, gen")
|
||||||
parser.add_argument("entities", nargs="*",
|
parser.add_argument("entities", nargs="*",
|
||||||
help=", ".join(ENTITIES))
|
help=", ".join(ENTITIES))
|
||||||
return parser.parse_args(argv)
|
return parser.parse_args(argv)
|
||||||
@@ -68,6 +69,12 @@ def write_all_file(path, all_data):
|
|||||||
json.dump(all_data, f, cls=model.ModelJSONEncoder, indent=2)
|
json.dump(all_data, f, cls=model.ModelJSONEncoder, indent=2)
|
||||||
|
|
||||||
|
|
||||||
|
def write_map_file(path, map_data):
|
||||||
|
map_path = os.path.join(path, "_map.json")
|
||||||
|
with open(map_path, "w") as f:
|
||||||
|
json.dump(map_data, f, cls=model.ModelJSONEncoder, indent=2)
|
||||||
|
|
||||||
|
|
||||||
def monster_json(db, path):
|
def monster_json(db, path):
|
||||||
monsters = db.get_monsters()
|
monsters = db.get_monsters()
|
||||||
mkdirs_p(path)
|
mkdirs_p(path)
|
||||||
@@ -219,10 +226,14 @@ def weapon_json(db, path):
|
|||||||
|
|
||||||
|
|
||||||
def item_json(db, path):
|
def item_json(db, path):
|
||||||
|
if db.game == "4u":
|
||||||
|
items = db.get_items(wyporium=True)
|
||||||
|
else:
|
||||||
items = db.get_items()
|
items = db.get_items()
|
||||||
mkdirs_p(path)
|
mkdirs_p(path)
|
||||||
write_list_file(path, items)
|
write_list_file(path, items)
|
||||||
|
|
||||||
|
|
||||||
indexes = {}
|
indexes = {}
|
||||||
for item in items:
|
for item in items:
|
||||||
item_path = file_path(path, item)
|
item_path = file_path(path, item)
|
||||||
@@ -233,6 +244,21 @@ def item_json(db, path):
|
|||||||
write_index_file(path, indexes)
|
write_index_file(path, indexes)
|
||||||
|
|
||||||
|
|
||||||
|
def wyporium_json(db, path):
|
||||||
|
trade_map = {}
|
||||||
|
for item in db.get_wyporium_trades():
|
||||||
|
trade_map[item.id] = dict(id=item.id,
|
||||||
|
name=item.name)
|
||||||
|
all_data = item.as_data()
|
||||||
|
for k in all_data.keys():
|
||||||
|
if not k.startswith("wyporium"):
|
||||||
|
continue
|
||||||
|
trade_map[item.id][k] = all_data[k]
|
||||||
|
print trade_map
|
||||||
|
mkdirs_p(path)
|
||||||
|
write_map_file(path, trade_map)
|
||||||
|
|
||||||
|
|
||||||
def horn_melody_json(db, path):
|
def horn_melody_json(db, path):
|
||||||
# only 143 rows, just do index with all data
|
# only 143 rows, just do index with all data
|
||||||
melodies = db.get_horn_melodies()
|
melodies = db.get_horn_melodies()
|
||||||
@@ -246,10 +272,10 @@ def horn_melody_json(db, path):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
db = MHDB(include_item_components=True)
|
|
||||||
|
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
|
db = MHDB(game=args.game, include_item_components=True)
|
||||||
|
|
||||||
if not args.outpath:
|
if not args.outpath:
|
||||||
args.outpath = os.path.join(_pathfix.web_path, "jsonapi")
|
args.outpath = os.path.join(_pathfix.web_path, "jsonapi")
|
||||||
|
|
||||||
@@ -261,6 +287,9 @@ def main():
|
|||||||
else:
|
else:
|
||||||
args.entities = ENTITIES
|
args.entities = ENTITIES
|
||||||
|
|
||||||
|
if db.game != "4u":
|
||||||
|
args.entities.remove("wyporium")
|
||||||
|
|
||||||
for entity in args.entities:
|
for entity in args.entities:
|
||||||
fn = globals()["%s_json" % entity]
|
fn = globals()["%s_json" % entity]
|
||||||
fn(db, os.path.join(args.outpath, entity))
|
fn(db, os.path.join(args.outpath, entity))
|
||||||
|
|||||||
37
mhapi/db.py
37
mhapi/db.py
@@ -157,22 +157,30 @@ class MHDB(object):
|
|||||||
WHERE type IN (%s)
|
WHERE type IN (%s)
|
||||||
""" % placeholders, tuple(args), model_cls=field_model("name"))
|
""" % placeholders, tuple(args), model_cls=field_model("name"))
|
||||||
|
|
||||||
def get_items(self, item_types=None, exclude_types=None):
|
def get_items(self, item_types=None, exclude_types=None, wyporium=False):
|
||||||
"""
|
"""
|
||||||
List of item objects.
|
List of item objects.
|
||||||
"""
|
"""
|
||||||
q = "SELECT * FROM items"
|
fields = ["items.*"]
|
||||||
|
where = []
|
||||||
args = []
|
args = []
|
||||||
if item_types:
|
if item_types:
|
||||||
item_types = sorted(item_types)
|
item_types = sorted(item_types)
|
||||||
placeholders = ", ".join(["?"] * len(item_types))
|
placeholders = ", ".join(["?"] * len(item_types))
|
||||||
q += "\nWHERE type IN (%s)" % placeholders
|
where.append("WHERE type IN (%s)" % placeholders)
|
||||||
args.extend(item_types)
|
args.extend(item_types)
|
||||||
if exclude_types:
|
if exclude_types:
|
||||||
exclude_types = sorted(exclude_types)
|
exclude_types = sorted(exclude_types)
|
||||||
placeholders = ", ".join(["?"] * len(exclude_types))
|
placeholders = ", ".join(["?"] * len(exclude_types))
|
||||||
q += "\nWHERE type NOT IN (%s)" % placeholders
|
where.append("WHERE type NOT IN (%s)" % placeholders)
|
||||||
args.extend(exclude_types)
|
args.extend(exclude_types)
|
||||||
|
if wyporium:
|
||||||
|
where.append("LEFT JOIN wyporium AS w ON w.item_in_id = items._id")
|
||||||
|
where.append(
|
||||||
|
"LEFT JOIN items AS wi ON w.item_out_id = wi._id")
|
||||||
|
fields += ["w.item_out_id AS wyporium_item_id",
|
||||||
|
"wi.name AS wyporium_item_name"]
|
||||||
|
q = "SELECT " + ", ".join(fields) + " FROM items " + "\n".join(where)
|
||||||
args = tuple(args)
|
args = tuple(args)
|
||||||
return self._query_all("items", q, args, model_cls=model.Item)
|
return self._query_all("items", q, args, model_cls=model.Item)
|
||||||
|
|
||||||
@@ -205,6 +213,27 @@ class MHDB(object):
|
|||||||
WHERE item_in_id=?
|
WHERE item_in_id=?
|
||||||
""", (item_id,))
|
""", (item_id,))
|
||||||
|
|
||||||
|
def get_wyporium_trades(self):
|
||||||
|
"""
|
||||||
|
Single wyporium row or None.
|
||||||
|
"""
|
||||||
|
if self.game != "4u":
|
||||||
|
return None
|
||||||
|
return self._query_all("wyporium", """
|
||||||
|
SELECT items.*,
|
||||||
|
wyporium.item_out_id AS wyporium_item_id,
|
||||||
|
trade_items.name AS wyporium_item_name,
|
||||||
|
quests._id AS wyporium_quest_id,
|
||||||
|
quests.name AS wyporium_quest_name,
|
||||||
|
quests.hub AS wyporium_quest_hub,
|
||||||
|
quests.stars AS wyporium_quest_stars,
|
||||||
|
quests.rank AS wyporium_quest_rank
|
||||||
|
FROM wyporium
|
||||||
|
JOIN items ON items._id = wyporium.item_in_id
|
||||||
|
JOIN items AS trade_items ON trade_items._id = wyporium.item_out_id
|
||||||
|
JOIN quests ON wyporium.unlock_quest_id == quests._id
|
||||||
|
""", model_cls=model.Item)
|
||||||
|
|
||||||
def search_item_name(self, term, item_type=None):
|
def search_item_name(self, term, item_type=None):
|
||||||
"""
|
"""
|
||||||
Search for items containing @term somewhere in the name. Returns
|
Search for items containing @term somewhere in the name. Returns
|
||||||
|
|||||||
@@ -654,6 +654,15 @@ class ItemStars(object):
|
|||||||
self.db = db
|
self.db = db
|
||||||
self._item_stars = {} # item id -> stars dict
|
self._item_stars = {} # item id -> stars dict
|
||||||
self._weapon_stars = {} # weapon id -> stars dict
|
self._weapon_stars = {} # weapon id -> stars dict
|
||||||
|
self._wyporium_trades = {}
|
||||||
|
|
||||||
|
if self.db.game == "4u":
|
||||||
|
self.init_wyporium_trades()
|
||||||
|
|
||||||
|
def init_wyporium_trades(self):
|
||||||
|
trades = self.db.get_wyporium_trades()
|
||||||
|
for item in trades:
|
||||||
|
self._wyporium_trades[item.id] = item
|
||||||
|
|
||||||
def get_weapon_stars(self, weapon):
|
def get_weapon_stars(self, weapon):
|
||||||
"""
|
"""
|
||||||
@@ -724,7 +733,10 @@ class ItemStars(object):
|
|||||||
item = self.db.get_item(row["item_id"])
|
item = self.db.get_item(row["item_id"])
|
||||||
if "Scrap" in item.name:
|
if "Scrap" in item.name:
|
||||||
continue
|
continue
|
||||||
stars = self.get_item_stars(item.id)
|
istars = self.get_item_stars(item.id)
|
||||||
|
for k, v in stars.items():
|
||||||
|
if istars[k] > v:
|
||||||
|
stars[k] = istars[k]
|
||||||
break
|
break
|
||||||
self._item_stars[material_item_id] = stars
|
self._item_stars[material_item_id] = stars
|
||||||
return stars
|
return stars
|
||||||
@@ -737,6 +749,16 @@ class ItemStars(object):
|
|||||||
stars = dict(Village=None, Guild=None, Permit=None, Arena=None,
|
stars = dict(Village=None, Guild=None, Permit=None, Arena=None,
|
||||||
Event=None)
|
Event=None)
|
||||||
|
|
||||||
|
# for 4u wyporium trade items, use the stars from the unlock quest
|
||||||
|
trade = self._wyporium_trades.get(item_id)
|
||||||
|
if trade is not None:
|
||||||
|
hub = trade.wyporium_quest_hub
|
||||||
|
if hub == "Caravan":
|
||||||
|
hub = "Village"
|
||||||
|
stars[hub] = trade.wyporium_quest_stars
|
||||||
|
self._item_stars[item_id] = stars
|
||||||
|
return stars
|
||||||
|
|
||||||
quests = self.db.get_item_quests(item_id)
|
quests = self.db.get_item_quests(item_id)
|
||||||
|
|
||||||
gathering = self.db.get_item_gathering(item_id)
|
gathering = self.db.get_item_gathering(item_id)
|
||||||
|
|||||||
@@ -86,10 +86,23 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var DATA_PATH = "/jsonapi/mh4u/";
|
var DATA_PATH = "/jsonapi/mh4u/";
|
||||||
|
var WYPORIUM_MAP = {};
|
||||||
|
|
||||||
var template_path = new EJS({ url: "/templates/weaponpath.ejs" });
|
var template_path = new EJS({ url: "/templates/weaponpath.ejs" });
|
||||||
var template_stats = new EJS({ url: "/templates/weaponstats.ejs" });
|
var template_stats = new EJS({ url: "/templates/weaponstats.ejs" });
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: DATA_PATH + "wyporium/_map.json",
|
||||||
|
async: false,
|
||||||
|
dataType: "json",
|
||||||
|
success: function (data) {
|
||||||
|
$.each(data, function(id, item) {
|
||||||
|
WYPORIUM_MAP[item["name"]] = item["wyporium_item_name"];
|
||||||
|
});
|
||||||
|
console.log("wyporium count " + WYPORIUM_MAP.length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
setup_weapon_autocomplete("#weapon", autocomplete_predicate,
|
setup_weapon_autocomplete("#weapon", autocomplete_predicate,
|
||||||
init_page, update_search);
|
init_page, update_search);
|
||||||
@@ -234,6 +247,16 @@
|
|||||||
}
|
}
|
||||||
path["delta"] = delta;
|
path["delta"] = delta;
|
||||||
path["component_list"].sort();
|
path["component_list"].sort();
|
||||||
|
path["trade_names"] = [];
|
||||||
|
for (j=0; j<all_components.length; j++) {
|
||||||
|
var name = all_components[j];
|
||||||
|
if (name in WYPORIUM_MAP) {
|
||||||
|
path["trade_names"][j] = WYPORIUM_MAP[name];
|
||||||
|
} else {
|
||||||
|
path["trade_names"][j] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var html = template_path.render(path);
|
var html = template_path.render(path);
|
||||||
$("#results").append(html);
|
$("#results").append(html);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
<td class="<%= delta[all_components[i]] < 0 ? 'plus' :
|
<td class="<%= delta[all_components[i]] < 0 ? 'plus' :
|
||||||
delta[all_components[i]] > 0 ? 'minus' :
|
delta[all_components[i]] > 0 ? 'minus' :
|
||||||
'neutral' %>"
|
'neutral' %>"
|
||||||
|
<%if (trade_names[i]) { %>
|
||||||
|
title="<%= trade_names[i] %>"
|
||||||
|
<% } %>
|
||||||
><a href="recommends.html?item=<%=
|
><a href="recommends.html?item=<%=
|
||||||
encodeURIComponent(all_components[i]) %>"
|
encodeURIComponent(all_components[i]) %>"
|
||||||
><%= all_components[i] %></a></td>
|
><%= all_components[i] %></a></td>
|
||||||
|
|||||||
Reference in New Issue
Block a user