diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js index 098c47ce5ab3b28caa6fa6ff6288f6b9159b45e7..2a346ba8bc9707f431e496e5c3e6ad7dcddf4e8d 100644 --- a/src/js/rulesAssistantOptions.js +++ b/src/js/rulesAssistantOptions.js @@ -304,16 +304,18 @@ window.rulesAssistantOptions = (function() { return; } const selected = this.children.filter(listItem => _.isEqual(listItem.data, what)); - if(selected != null && selected.length === 1) { + if(selected != null && selected.length == 1) + { this.selectItem(selected[0]); - } else if(this._allowNullValue) { + } + else if(this._allowNullValue) { this.setValue(null); } } setValue(what) { if(what == null && !this._allowNullValue) { what = ""; } this.realValue = what; - if(this[_blockCallback]) { return; } + if(this[_blockCallback]) return; try { this[_blockCallback] = true; this.setTextValue(what); @@ -356,11 +358,12 @@ window.rulesAssistantOptions = (function() { let selected; if(dataValue == null) { selected = this.children.filter(listItem => listItem.data == null); - } else { + } + else { selected = this.children.filter(listItem => this.dataEqual(listItem.data, dataValue)); } if (selected.length > 1) { debugger; throw Error(`Multiple shortcuts matched ${JSON.stringify(dataValue)}`); } - if (selected.length === 1) { + if (selected.length == 1) { const listItem = selected[0]; listItem.select(false); if(this.selectedItem != null @@ -751,12 +754,13 @@ window.rulesAssistantOptions = (function() { } dataEqual(left, right) { + debugger; if (left == null && right == null) { return true; } if (left == null || right == null) { return false; } - // ignore the operator + //ignore the operator if(_.isObject(left )) { left = left .val; } if(_.isObject(right)) { right = right.val; } - return left === right; + return left == right; } } @@ -1051,7 +1055,7 @@ window.rulesAssistantOptions = (function() { // buttons for selecting the current rule class RuleSelector extends List { constructor() { - super("Current rule", V.defaultRules.map(i => [(i.name + (RuleHasError(i) ? " <span class='yellow'>[!]</span>" : "")), i]), false); + super("Current rule", V.defaultRules.map(i => [(i.name + (!!RuleHasError(i) ? " <span class='yellow'>[!]</span>" : "")), i]), false); this.setValue(current_rule.name); this.onchange = function(rule) { V.currentRule = rule.ID; @@ -1262,12 +1266,13 @@ window.rulesAssistantOptions = (function() { textarea.innerHTML = data; $(textarea).blur(() => { current_rule.condition.data = textarea.value; - // TODO: this would be a good place to cache the Function object that will be used by RuleHasError and ruleAppliesP + //TODO: this would be a good place to cache the Function object that will be used by RuleHasError and ruleAppliesP reload(); }); elem.appendChild(textarea); - if(RuleHasError(current_rule)) { + if(RuleHasError(current_rule)) + { const errorMessage = document.createElement("div"); $(errorMessage).addClass("yellow"); errorMessage.innerText = "WARNING: There are errors in this condition. Please ensure the syntax is correct and equality is either '==' or '===', not '='"; @@ -1600,6 +1605,9 @@ window.rulesAssistantOptions = (function() { constructor(tabButtons) { super("behavior", "Behavior", tabButtons); this.appendChild(new AutomaticAssignmentList()); + if (V.pit === 1) { + this.appendChild(new PitAssignmentList()); + } this.appendChild(new LivingStandardList()); this.appendChild(new PunishmentList()); this.appendChild(new RewardList()); @@ -2663,7 +2671,7 @@ window.rulesAssistantOptions = (function() { default: return value; } - }; + } class DietBaseList extends List { constructor() { // TODO: better data structure? @@ -2677,7 +2685,7 @@ window.rulesAssistantOptions = (function() { ["Milk-Based", {cum: 0, milk: 2}], ]; super("Diet base", pairs, false); - this.setValue({cum: current_rule.set.dietCum, milk: current_rule.set.dietMilk}); + this.setValue({cum: current_rule.set.dietCum, milk: current_rule.set.dietMilk }); this.onchange = (value) => { current_rule.set.dietCum = value.cum; current_rule.set.dietMilk = value.milk; @@ -2687,7 +2695,8 @@ window.rulesAssistantOptions = (function() { setTextValue(what) { if(what.cum == null && what.milk == null) { super.setTextValue(capFirstChar(noDefaultSetting.text)); - } else { + } + else { super.setTextValue(`Cum: ${dietAddedText(what.cum)}, Milk: ${dietAddedText(what.milk)}`); } } @@ -2973,10 +2982,13 @@ window.rulesAssistantOptions = (function() { this.shapelist.setValue(val); } else { let list = val.split(' '); - if(list.length === 2) { + if(list.length == 2) + { this.colorlist.setValue(list[0]); this.shapelist.setValue(list[1]); - } else if(list.length === 1) { + } + else if(list.length == 1) + { this.colorlist.trySetValue(list[0]); this.shapelist.trySetValue(list[0]); } @@ -4243,6 +4255,15 @@ window.rulesAssistantOptions = (function() { this.onchange = (value) => current_rule.set.setAssignment = value; } } + + class PitAssignmentList extends BooleanSwitch{ + constructor() { + super("Is assigned to Pit", [0, 1]); + this.setValue(current_rule.set.pitRules); + this.onchange = (value) => current_rule.set.pitRules = value; + } + } + class BellyImplantList extends RadioSelector { constructor() {