Skip to content

Commit 60f70eb

Browse files
feat(commands): refactor handleInput with ON/OFF split, BAR validation, Aura1/2 commands, and post-change snapshot
Split !aura on/off into two explicit cases so on always enables and off always disables, replacing the previous toggle on the on case. Add input validation for !aura bar: accepts only 1, 2, or 3; whispers confirmation and immediately calls menuForceUpdate on a valid change; whispers a clear error on an invalid value. Add new Aura 1/2 commands: !aura a1shape, !aura a1tint, !aura a2size, !aura a2shape, !aura a2tint — each validated through normalizeShape or normalizeHex6 before updating state. Add !aura reset-fx and !aura reset-all recovery commands backed by resetDefaultFxObjects and runResetAllFlow respectively. Add !aura settings to output the current settings snapshot on demand. Introduce a changedSetting flag: when any setting changes, call showSettingsInGameChat instead of showMenu to post a single read-only snapshot to game chat; non-mutating commands still show the GM menu. Call syncDefaultFxObjects immediately after HEAL and HURT color changes. Signed-off-by: Steve Roberts <steve@shadowcomputers.co.uk>
1 parent 7b4cba4 commit 60f70eb

File tree

1 file changed

+84
-4
lines changed

1 file changed

+84
-4
lines changed

HealthColors/2.0.0/HealthColors.js

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,70 +1258,146 @@
12581258
}
12591259

12601260
const option = (parts[1] || "MENU").toUpperCase();
1261+
let changedSetting = false;
12611262
if (option !== "MENU") gmWhisper("UPDATING TOKENS...");
12621263

12631264
switch (option) {
12641265
case "MENU":
12651266
break;
1267+
case "SETTINGS":
1268+
showSettingsInGameChat();
1269+
return;
12661270
case "ON":
1267-
state.HealthColors.auraColorOn = !state.HealthColors.auraColorOn;
1271+
state.HealthColors.auraColorOn = true;
1272+
changedSetting = true;
1273+
break;
1274+
case "OFF":
1275+
state.HealthColors.auraColorOn = false;
1276+
changedSetting = true;
12681277
break;
12691278
case "BAR":
1270-
state.HealthColors.auraBar = `bar${parts[2]}`;
1279+
if (/^[123]$/.test(parts[2] || "")) {
1280+
state.HealthColors.auraBar = `bar${parts[2]}`;
1281+
changedSetting = true;
1282+
gmWhisper(`Health bar set to ${state.HealthColors.auraBar}. Forcing sync...`);
1283+
menuForceUpdate();
1284+
} else {
1285+
gmWhisper(
1286+
`Invalid bar "${parts[2] || ""}". Use !aura bar 1, !aura bar 2, or !aura bar 3.`,
1287+
);
1288+
}
12711289
break;
12721290
case "TINT":
12731291
state.HealthColors.auraTint = !state.HealthColors.auraTint;
1292+
changedSetting = true;
12741293
break;
12751294
case "PERC":
12761295
state.HealthColors.auraPercPC = Number.parseInt(parts[2], 10);
12771296
state.HealthColors.auraPerc = Number.parseInt(parts[3], 10);
1297+
changedSetting = true;
12781298
break;
12791299
case "PC":
12801300
state.HealthColors.PCAura = !state.HealthColors.PCAura;
1301+
changedSetting = true;
12811302
break;
12821303
case "NPC":
12831304
state.HealthColors.NPCAura = !state.HealthColors.NPCAura;
1305+
changedSetting = true;
12841306
break;
12851307
case "GMNPC":
12861308
state.HealthColors.GM_NPCNames = parts[2];
1309+
changedSetting = true;
12871310
break;
12881311
case "GMPC":
12891312
state.HealthColors.GM_PCNames = parts[2];
1313+
changedSetting = true;
12901314
break;
12911315
case "PCNPC":
12921316
state.HealthColors.NPCNames = parts[2];
1317+
changedSetting = true;
12931318
break;
12941319
case "PCPC":
12951320
state.HealthColors.PCNames = parts[2];
1321+
changedSetting = true;
12961322
break;
12971323
case "DEAD":
12981324
state.HealthColors.auraDead = !state.HealthColors.auraDead;
1325+
changedSetting = true;
12991326
break;
13001327
case "DEADPC":
13011328
state.HealthColors.auraDeadPC = !state.HealthColors.auraDeadPC;
1329+
changedSetting = true;
13021330
break;
13031331
case "DEADFX":
13041332
state.HealthColors.auraDeadFX = parts[2];
1333+
changedSetting = true;
13051334
break;
13061335
case "SIZE":
13071336
state.HealthColors.AuraSize = Number.parseFloat(parts[2]);
1337+
changedSetting = true;
1338+
break;
1339+
case "A1SHAPE":
1340+
state.HealthColors.Aura1Shape = normalizeShape(
1341+
parts[2],
1342+
state.HealthColors.Aura1Shape,
1343+
);
1344+
changedSetting = true;
1345+
break;
1346+
case "A1TINT":
1347+
state.HealthColors.Aura1Color = normalizeHex6(
1348+
parts[2],
1349+
state.HealthColors.Aura1Color,
1350+
);
1351+
changedSetting = true;
1352+
break;
1353+
case "A2SIZE":
1354+
state.HealthColors.Aura2Size = Number.parseFloat(parts[2]);
1355+
changedSetting = true;
1356+
break;
1357+
case "A2SHAPE":
1358+
state.HealthColors.Aura2Shape = normalizeShape(
1359+
parts[2],
1360+
state.HealthColors.Aura2Shape,
1361+
);
1362+
changedSetting = true;
1363+
break;
1364+
case "A2TINT":
1365+
state.HealthColors.Aura2Color = normalizeHex6(
1366+
parts[2],
1367+
state.HealthColors.Aura2Color,
1368+
);
1369+
changedSetting = true;
13081370
break;
13091371
case "ONEOFF":
13101372
state.HealthColors.OneOff = !state.HealthColors.OneOff;
1373+
changedSetting = true;
13111374
break;
13121375
case "FX":
13131376
state.HealthColors.FX = !state.HealthColors.FX;
1377+
changedSetting = true;
13141378
break;
13151379
case "HEAL":
13161380
state.HealthColors.HealFX = parts[2].toUpperCase();
1381+
syncDefaultFxObjects();
1382+
changedSetting = true;
13171383
break;
13181384
case "HURT":
13191385
state.HealthColors.HurtFX = parts[2].toUpperCase();
1386+
syncDefaultFxObjects();
1387+
changedSetting = true;
13201388
break;
13211389
case "RESET":
13221390
delete state.HealthColors;
13231391
gmWhisper("STATE RESET");
13241392
checkInstall();
1393+
changedSetting = true;
1394+
break;
1395+
case "RESET-FX":
1396+
resetDefaultFxObjects();
1397+
break;
1398+
case "RESET-ALL":
1399+
runResetAllFlow();
1400+
changedSetting = true;
13251401
break;
13261402
case "FORCEALL":
13271403
menuForceUpdate();
@@ -1331,12 +1407,16 @@
13311407
return;
13321408
}
13331409

1334-
showMenu();
1410+
if (changedSetting) {
1411+
showSettingsInGameChat();
1412+
} else {
1413+
showMenu();
1414+
}
13351415
}
13361416

13371417
// ————— OUTSIDE API —————
13381418
/**
1339-
* Public entry point for external scripts to request a token colour update.
1419+
* Public entry point for external scripts to request a token color update.
13401420
* Validates that the object is a graphic before delegating to handleToken.
13411421
* @param {object} obj - Roll20 object to update.
13421422
* @param {object} prev - Previous attribute snapshot (passed through to handleToken).

0 commit comments

Comments
 (0)