From a3515c745cdbdd0a19d81c737616c2e45a1d4eb0 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 23 Oct 2021 17:33:12 -0400 Subject: [PATCH] Allow mass estimation; fix food intake/value clashing Also styles selects differently if they have their 'disabled' value --- macrovision.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/macrovision.js b/macrovision.js index 9e61e961..13a6079a 100644 --- a/macrovision.js +++ b/macrovision.js @@ -1206,8 +1206,26 @@ function makeEntity(info, views, sizes, forms = {}) { view.units = {}; + if (config.autoMass && view.attributes.weight === undefined) { + let base = undefined; + switch(config.autoMass) { + case "human": + base = math.divide(math.unit(150, "lbs"), math.unit(5.917, "feet")) + break + case "quadruped at shoulder": + base = math.divide(math.unit(80, "lbs"), math.unit(30, "inches")) + break + } + view.attributes.weight = { + name: "Mass", + power: 3, + type: "mass", + base: math.multiply(base, view.attributes.height.base) + } + } + if (config.autoFoodIntake && view.attributes.weight !== undefined && view.attributes.energyNeed === undefined) { - view.attributes.energyNeed = { + view.attributes.energyIntake = { name: "Food Intake", power: 3, type: "energy", @@ -2526,6 +2544,7 @@ const settingsData = { desc: "Draw interesting altitudes", type: "select", default: "none", + disabled: "none", options: [ "none", "all", @@ -2598,6 +2617,7 @@ const settingsData = { desc: "What kind of ground to show, if any", type: "select", default: "black", + disabled: "none", options: [ "none", "black", @@ -2822,6 +2842,24 @@ const settingsData = { toggleBodyClass("smoothing", param); } }, + "auto-mass": { + name: "Estimate Mass", + desc: "Guess the mass of things that don't have one specified using the selected body type", + type: "select", + default: "off", + disabled: "off", + options: [ + "off", + "human", + "quadruped at shoulder", + ], + get value() { + return config.autoMass + }, + set value(param) { + config.autoMass = param + } + }, "auto-food-intake": { name: "Estimate Food Intake", desc: "Guess how much food creatures need, based on their mass -- 2000kcal per 150lbs", @@ -2941,10 +2979,16 @@ function prepareSettings(userSettings) { holder.appendChild(select); menubar.appendChild(holder); - holder.classList.add("enabled"); - const update = () => { entry.value = select.value; + + if (entry.disabled !== undefined && entry.value !== entry.disabled) { + holder.classList.add("enabled"); + holder.classList.remove("disabled"); + } else { + holder.classList.remove("enabled"); + holder.classList.add("disabled"); + } } update();