improve weapon list, mhx weapon scraper

This commit is contained in:
Bryce Allen
2016-01-07 22:35:33 -05:00
parent d0173157b9
commit 43c9e6c79c
6 changed files with 33672 additions and 15651 deletions

View File

@@ -299,14 +299,41 @@ function set_bow_values(weapon_data) {
}
function set_horn_melodies_title(weapon_data) {
function set_horn_melodies_title(weapon_data, melody_map) {
if (! weapon_data["horn_notes"]) {
weapon_data["horn_melodies_title"] = ""
weapon_data["horn_melodies_title"] = "";
return;
}
var notes = weapon_data["horn_notes"];
var melodies;
if (melody_map) {
melodies = melody_map[notes];
if (! melodies) {
// Try flipping second two notes if not found, mhx data is
// either wrong or game itself is inconsistant about note
// order.
notes = notes.substring(0, 1) + notes.substring(2, 3)
+ notes.substring(1, 2);
melodies = melody_map[notes];
if (melodies) {
weapon_data["horn_notes"] = notes;
}
}
} else {
melodies = weapon_data["horn_melodies"];
}
if (! melodies) {
var msg = "Unknown melodies for " + notes;
weapon_data["horn_melodies_title"] = msg;
console.log(msg);
return;
}
var lines = [];
$.each(weapon_data["horn_melodies"], function(i, melody) {
$.each(melodies, function(i, melody) {
var space = Array(6 - melody["song"].length).join(" ");
lines.push(melody["song"] + space + melody["effect1"]);
});
@@ -402,7 +429,7 @@ function cmp_arrays(alist, blist) {
for (var i=0; i<alist.length; i++) {
a = alist[i];
b = blist[i];
if (a == null && b == null) {
if (a == null || b == null) {
// ignore
} else if (typeof a == "object") {
cmp = cmp_arrays(a, b);

View File

@@ -99,6 +99,7 @@
<script type="text/javascript">
var WEAPON_LIST = null;
var HORN_MELODY_MAP = null;
$.ajax({
url: "/jsonapi/mhx/weapon_list.json",
@@ -110,6 +111,16 @@
}
});
$.ajax({
url: "/jsonapi/horn_melody/_index_notes.json",
async: false,
dataType: "json",
success: function (data) {
HORN_MELODY_MAP = data;
}
});
var template_row = new EJS({ url: "/templates/weaponrow.ejs" });
$(document).ready(function(){
@@ -236,7 +247,7 @@
match_count += 1;
set_sharpness_titles(weapon_data);
set_bow_values(weapon_data);
set_horn_melodies_title(weapon_data);
set_horn_melodies_title(weapon_data, HORN_MELODY_MAP);
weapon_data["wtype_short"] =
WEAPON_TYPE_ABBR[weapon_data["wtype"]];
weapon_data["ELEMENT_ABBR"] = ELEMENT_ABBR;

View File

@@ -71,5 +71,5 @@
title="<%= bow_coatings_text %>"><%= bow_shots_text %></td>
<% } %>
<td title="<%= horn_melodies_title %>"
style="text-align:right"><%= horn_notes %></td>
style="text-align:right; font-family:mono"><%= horn_notes %></td>
</tr>

View File

@@ -221,7 +221,10 @@
function update_weapon_list(state) {
var match_count = 0;
var cp_setups = [];
var comps = state["weapon_component_text"].split("|");
var comps = state["weapon_component_text"];
if (comps) {
comps = comps.split("|");
}
console.log("updating weapon list: " + JSON.stringify(state));
var results = [];
$.each(WEAPON_ID_IDX, function(weapon_id, weapon_list) {