Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ruleset editor #749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions html/components/ruleset-tab/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="sbGroup sbSubHeader selection" sbClass="sbHide:-:sbNoGame">
<span
>Current Ruleset:
<select id="select" sbProp="disabled: State: !== 'Prepared'" sbControl="Ruleset: rsUpdateActive">
<select id="select" sbProp="disabled: State: !== 'Prepared'" sbControl="Ruleset">
<option value="">Custom</option>
<option
sbForeach="Ruleset:: sbOrderRsAsTree: resort=Parent"
Expand Down Expand Up @@ -38,13 +38,13 @@
sbForeach="RuleDefinition:: index: filter=^"
class="definition"
sbAttr="index: Index"
sbClass="Inherited: §.Rule([RuleDefinition]): == null"
sbClass="Inherited: §.Ruleset, §.Rule([RuleDefinition]): rsIsInherited"
>
<td class="name">
<input
type="checkbox"
class="Selector"
sbProp="checked: §.Rule([RuleDefinition]): != null | disabled: §.Readonly, §.Ruleset: rsDisableToggle"
sbProp="checked: §.Ruleset, §.Rule([RuleDefinition]): rsIsNotInherited | disabled: §.Readonly: rsDisableToggle"
sbSet="§.Rule([RuleDefinition]): rsDefinitionOverride"
/>
<span sbDisplay="Name: rsPart2"></span>
Expand All @@ -55,19 +55,18 @@
type="text"
class="override"
sbClass="sbHide: Type: === 'Boolean'"
sbProp="disabled: §.Readonly, §.Ruleset: rsDisableSetter"
sbProp="disabled: §.Readonly"
sbControl="§.Rule([RuleDefinition])"
/>
<select
class="override"
sbClass="sbHide: Type: !== 'Boolean'"
sbProp="disabled: §.Readonly, §.Ruleset: rsDisableSetter"
sbControl="§.Rule([RuleDefinition])"
>
<select class="override" sbClass="sbHide: Type: !== 'Boolean'" sbProp="disabled: §.Readonly" sbControl="§.Rule([RuleDefinition])">
<option value="true" sbDisplay="TrueValue"></option>
<option value="false" sbDisplay="FalseValue"></option>
</select>
<span class="inherit" sbDisplay="/ScoreBoard.Rulesets.Ruleset(*).Rule([RuleDefinition]): rsGetDisplayValue"> </span>
<span
class="inherit"
sbDisplay="§.Rule([RuleDefinition]), /ScoreBoard.Rulesets.Ruleset(*).Rule([RuleDefinition]), §.Parent: rsGetDisplayValue"
>
</span>
</td>
</tr>
</tbody>
Expand Down
28 changes: 12 additions & 16 deletions html/components/ruleset-tab/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
'use strict';

let activeRsPrefix = _windowFunctions.hasParam('ruleset')
? 'ScoreBoard.Rulesets.Ruleset(' + _windowFunctions.getParam('ruleset') + ')'
: 'ScoreBoard.Game(' + _windowFunctions.getParam('game') + ')';
WS.Register('ScoreBoard.Rulesets.Ruleset(*).Parent');

function rsCompareChildIndex(a, b) {
return _sbCompareAttrThenSubId('index', $(a).children('[index]'), $(b).children('[index]'));
}

function rsUpdateActive(k, v) {
if (k.Game) {
activeRsPrefix = v ? 'ScoreBoard.Rulesets.Ruleset(' + v + ')' : 'ScoreBoard.Game(' + k.Game + ')';
}
return v;
}

function rsTriggerFold(k, v, elem) {
elem.parent().parent().toggleClass('folded');
}
Expand All @@ -27,12 +18,16 @@ function rsPart2(k, v) {
return v ? v.split('.', 2)[1] : '';
}

function rsDisableToggle() {
return isTrue(WS.state[activeRsPrefix + '.Readonly']) || WS.state[activeRsPrefix + '.Ruleset'] == null;
function rsIsInherited(k, v) {
return (k.field === 'Ruleset' && !!v) || (!k.Game && !v);
}

function rsIsNotInherited(k, v) {
return !rsIsInherited(k, v);
}

function rsDisableSetter() {
return isTrue(WS.state[activeRsPrefix + '.Readonly']);
function rsDisableToggle(k, v) {
return k.Game != null || isTrue(v);
}

function rsDefinitionOverride(k, v, elem) {
Expand All @@ -49,8 +44,9 @@ function _rsGetEffectiveValue(rs, rule) {
}

function rsGetDisplayValue(k, v, elem) {
const value =
WS.state[activeRsPrefix + '.Rule(' + k.Rule + ')'] || _rsGetEffectiveValue(activeRsPrefix.split('(')[1].slice(0, -1), k.Rule);
const value = k.Game
? v
: _rsGetEffectiveValue(_windowFunctions.getParam('ruleset'), WS._enrichProp(WS._getContext(elem)[0]).RuleDefinition);
return (
elem
.parent()
Expand Down