Skip to content

Instantly share code, notes, and snippets.

@xdjoshuaaz
Created June 7, 2023 20:38
Show Gist options
  • Select an option

  • Save xdjoshuaaz/91be977eb6bcd07bad810461caec904f to your computer and use it in GitHub Desktop.

Select an option

Save xdjoshuaaz/91be977eb6bcd07bad810461caec904f to your computer and use it in GitHub Desktop.
eco game calc sync
var data = await fetch("http://eco-web-server/elixr-mods/framework/api/v1/get-prices/false").then(resp => resp.json())
var calcIngredients = getAllAngularRootElements()[0].__ngContext__.filter(x => x && typeof x === "object" && "craftingParentComponent" in x)[0].craftingParentComponent.ingredientsComponent.itemIngredients;
var supermap = calcIngredients.reduce((map, obj) => {
map[obj.name] = obj.nameID;
map[obj.nameID] = obj.name;
return map;
}, {})
for (var ingredient of ingredients) {
var id = ingredient.id; // calc id = BasicUpgrade1Item
var name = supermap[id] || id; // eco name = Basic Upgrade 1
if (!(name in pricesByTagItemName)) {
continue;
}
var prices = pricesByTagItemName[name];
var minPrice = Math.min.apply(null, prices.map(x => x.Price));
var maxPrice = Math.max.apply(null, prices.map(x => x.Price));
if (ingredient.pr !== minPrice) {
console.log(`ingredient ${name} was ${ingredient.pr}, is now ${minPrice}/${maxPrice}`);
ingredient.pr = minPrice;
}
}
window.localStorage.ingredients = JSON.stringify(ingredients);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment