Skip to content

Commit

Permalink
Add support for resetProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
96LawDawg committed Jan 15, 2025
1 parent 1610ced commit 5a8f04f
Show file tree
Hide file tree
Showing 2 changed files with 45 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', collection: 'DEFAULT' });
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
21 changes: 20 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,24 @@ export class Widget extends StateManaged {
}
}

if (a.func == 'RESET') {
setDefaults(a, { property: 'resetProperties' });

const widgetsToReset = Array.from(widgets.values()).filter(widget => {
const propertyValue = widget.get(a.property) ?? {};
return Object.keys(propertyValue).length > 0;
});
for (const widget of widgetsToReset) {
const propertyValue = widget.get(a.property) ?? {};
for (const [key, value] of Object.entries(propertyValue)) {
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

0 comments on commit 5a8f04f

Please sign in to comment.