public void parse(String data) throws JSONException { JSONObject itemJson = new JSONObject(data); id = itemJson.optInt("id"); itemData = itemJson.optString("itemData"); name = itemJson.optString("name"); icon = itemJson.optString("icon"); flavorText = itemJson.optString("flavorText"); displayColor = itemJson.optString("displayColor"); tooltipParams = itemJson.optString("tooltipParams"); requiredLevel = itemJson.optInt("requiredLevel"); itemLevel = itemJson.optInt("itemLevel"); bonusAffixes = itemJson.optInt("bonusAffixes"); dps.parse(itemJson.optString("dps")); attacksPerSecond.parse(itemJson.optString("attacksPerSecond")); minDamage.parse(itemJson.optString("minDamage")); maxDamage.parse(itemJson.optString("maxDamage")); attributes.clear(); attributes.addAll(parseAttributes(itemJson.optJSONArray("attributes"))); attributesRaw.parse(itemJson.optString("attributesRaw")); salvage.parse(itemJson.optString("salvage")); }
// ----------------------------------------------------------------- // Apply the function (or inverse) defined by the object // to Value 'v'. // ----------------------------------------------------------------- void applyTo(Value v, String inv) { v.completereduce(); if (dimen != null) { Value dim; try { dim = Value.parse(dimen); } catch (EvalError e) { throw new EvalError( "Invalid dimension, " + dimen + ", of function " + inv + name + ". " + e.getMessage()); } dim.completereduce(); if (!dim.isCompatibleWith(v, Factor.Ignore.NONE)) throw new EvalError( "Argument " + v.asString() + " of function " + inv + name + " is not conformable to " + dim.asString() + "."); } Value result; try { result = Value.parse(def, param, v); } catch (EvalError e) { throw new EvalError( "Invalid definition of function '" + inv + name + "'. " + e.getMessage()); } v.copyFrom(result); } // end applyTo
// ===================================================================== // Check the function. Used in 'checkunits'. // ===================================================================== void check() { if (Env.verbose == 2) Env.out.println("doing function " + name); Value v; if (forward.dimen != null) { try { v = Value.parse(forward.dimen); v.completereduce(); } catch (EvalError e) { Env.out.println("Function '" + name + "' has invalid type '" + forward.dimen + "'"); return; } } else v = new Value(); v.factor *= 7; // Arbitrary choice where we evaluate inverse Value saved = new Value(v); try { applyTo(v); } catch (EvalError e) { Env.out.println("Error in definition " + name + "(" + forward.param + ") as " + forward.def); return; } if (inverse.def == null) { Env.out.println("Warning: no inverse for function '" + name + "'"); return; } try { applyInverseTo(v); v.div(saved); v.completereduce(); double delta = v.factor - 1; if (!v.isNumber() || delta < -1e-12 || delta > 1e-12) Env.out.println("Inverse is not the inverse for function '" + name + "'"); } catch (EvalError e) { Env.out.println("Error in inverse ~" + name + "(" + inverse.param + ") as " + inverse.def); } }