Skip to content

Commit

Permalink
Add support for resetProperties (#2447)
Browse files Browse the repository at this point in the history
  • Loading branch information
96LawDawg authored Jan 28, 2025
1 parent 972cfa5 commit 63dc59e
Show file tree
Hide file tree
Showing 6 changed files with 1,158 additions and 1 deletion.
25 changes: 25 additions & 0 deletions client/js/jsonedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ function jeAddCommands() {
jeAddRoutineOperationCommands('MOVE', { count: 1, face: null, from: null, to: null, fillTo: null, collection: 'DEFAULT' });
jeAddRoutineOperationCommands('MOVEXY', { count: 1, face: null, from: null, x: 0, y: 0, snapToGrid: true, resetOwner: true });
jeAddRoutineOperationCommands('RECALL', { owned: true, inHolder: true, holder: null, excludeCollection: null });
jeAddRoutineOperationCommands('RESET', { property: 'resetProperties' });
jeAddRoutineOperationCommands('ROTATE', { count: 1, angle: 90, mode: 'add', holder: null, collection: 'DEFAULT' });
jeAddRoutineOperationCommands('SCORE', { mode: 'set', property: 'score', seats: null, round: null, value: null });
jeAddRoutineOperationCommands('SELECT', { type: 'all', property: 'parent', relation: '==', value: null, max: 999999, collection: 'DEFAULT', mode: 'set', source: 'all', sortBy: '###SEE jeAddRoutineOperation###'});
Expand Down Expand Up @@ -1149,6 +1150,15 @@ function jeAddCommands() {
jeAddLimitCommand('maxX');
jeAddLimitCommand('maxY');

// Default values computed dynamically.
jeAddResetPropertiesCommand('parent');
jeAddResetPropertiesCommand('x');
jeAddResetPropertiesCommand('y');
jeAddResetPropertiesCommand('rotation');
jeAddResetPropertiesCommand('activeFace');
jeAddResetPropertiesCommand('scale');
jeAddResetPropertiesCommand('display');

jeAddFieldCommand('text', 'subtitle|title|text', '');
jeAddFieldCommand('label', 'checkbox|choose|color|number|palette|select|string|switch', '');
jeAddFieldCommand('value', 'checkbox|choose|color|number|palette|select|string|switch', '');
Expand Down Expand Up @@ -1484,6 +1494,21 @@ function jeAddNumberCommand(name, key, callback) {
});
}

function jeAddResetPropertiesCommand(key) {
jeCommands.push({
id: 'rProp_' + key,
name: key,
context: '^[^ ]* ↦ resetProperties',
show: _=>typeof jeStateNow.resetProperties == "object" && jeStateNow.resetProperties !== null && !(key in jeStateNow.resetProperties),
call: async function() {
const w = widgets.get(jeStateNow.id);
jeStateNow.resetProperties[key] = '###SELECT ME###';
let rProp = w.get(key);
jeSetAndSelect(rProp);
}
});
}

function jeAddWidgetPropertyCommands(object, widgetBase) {
for(const property in object.defaults)
if(property != 'typeClasses' && !property.match(/^c[0-9]{2}$/))
Expand Down
13 changes: 12 additions & 1 deletion client/js/widgets/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export class Widget extends StateManaged {
gameStartRoutine: null,
hotkey: null,

animatePropertyChange: []
animatePropertyChange: [],
resetProperties: {},
});
this.domElement.timer = false

Expand Down Expand Up @@ -1620,6 +1621,16 @@ export class Widget extends StateManaged {
}
}

if (a.func == 'RESET') {
setDefaults(a, { property: 'resetProperties' });
for(const widget of widgets.values())
for(const [ key, value ] of Object.entries(widget.get(a.property) || {}))
await widget.set(key, value);
if (jeRoutineLogging) {
jeLoggingRoutineOperationSummary(`Reset properties for widgets with property '${a.property}'`);
}
}

if(a.func == 'ROTATE') {
setDefaults(a, { count: 1, angle: 90, mode: 'add', collection: 'DEFAULT' });
if(a.count === 'all')
Expand Down
Loading

0 comments on commit 63dc59e

Please sign in to comment.