Skip to content

Commit 9dad9e4

Browse files
committed
Use template strings instead of concatenation
This whole codebase is clearly in need of some modernization. I might even rewrite the menu code at some point...
1 parent bfa45a4 commit 9dad9e4

File tree

16 files changed

+82
-459
lines changed

16 files changed

+82
-459
lines changed

scripts/autoBattlers/robert2.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,49 @@ class RobertIIAI extends AutoBattler
262262
}
263263
}
264264

265+
on_phaseChanged(newPhase, lastPhase)
266+
{
267+
switch (newPhase) {
268+
case 1: {
269+
this.queueSkill('omni');
270+
this.doChargeSlashNext = true;
271+
this.isComboStarted = false;
272+
this.isNecromancyPending = true;
273+
break;
274+
}
275+
case 2: {
276+
this.queueSkill('upheaval');
277+
this.isComboStarted = false;
278+
this.isStatusHealPending = true;
279+
this.wasHolyWaterUsed = false;
280+
this.wasTonicUsed = false;
281+
break;
282+
}
283+
case 3: {
284+
this.queueSkill('protectiveAura');
285+
this.queueSkill(this.nextElementalMove !== null ? this.nextElementalMove : 'jolt');
286+
this.necroTonicItem = this.nextElementalMove === null ? 'tonic' : null;
287+
this.doChargeSlashNext = false;
288+
this.elementalsTillRevenge = 2;
289+
this.isChargeSlashPending = true;
290+
this.isComboStarted = false;
291+
break;
292+
}
293+
case 4: {
294+
this.queueSkill('crackdown');
295+
break;
296+
}
297+
case 5: {
298+
this.queueSkill('desperationSlash');
299+
if (this.unit.hasStatus('zombie') && this.isItemUsable('vaccine'))
300+
this.queueItem('vaccine');
301+
this.isAlcoholPending = true;
302+
this.isComboStarted = false;
303+
break;
304+
}
305+
}
306+
}
307+
265308
async on_itemUsed(userID, itemID, targetIDs)
266309
{
267310
if (this.unit.hasStatus('drunk') || this.unit.hasStatus('offGuard'))
@@ -343,49 +386,6 @@ class RobertIIAI extends AutoBattler
343386
}
344387
}
345388

346-
on_phaseChanged(newPhase, lastPhase)
347-
{
348-
switch (newPhase) {
349-
case 1: {
350-
this.queueSkill('omni');
351-
this.doChargeSlashNext = true;
352-
this.isComboStarted = false;
353-
this.isNecromancyPending = true;
354-
break;
355-
}
356-
case 2: {
357-
this.queueSkill('upheaval');
358-
this.isComboStarted = false;
359-
this.isStatusHealPending = true;
360-
this.wasHolyWaterUsed = false;
361-
this.wasTonicUsed = false;
362-
break;
363-
}
364-
case 3: {
365-
this.queueSkill('protectiveAura');
366-
this.queueSkill(this.nextElementalMove !== null ? this.nextElementalMove : 'jolt');
367-
this.necroTonicItem = this.nextElementalMove === null ? 'tonic' : null;
368-
this.doChargeSlashNext = false;
369-
this.elementalsTillRevenge = 2;
370-
this.isChargeSlashPending = true;
371-
this.isComboStarted = false;
372-
break;
373-
}
374-
case 4: {
375-
this.queueSkill('crackdown');
376-
break;
377-
}
378-
case 5: {
379-
this.queueSkill('desperationSlash');
380-
if (this.unit.hasStatus('zombie') && this.isItemUsable('vaccine'))
381-
this.queueItem('vaccine');
382-
this.isAlcoholPending = true;
383-
this.isComboStarted = false;
384-
break;
385-
}
386-
}
387-
}
388-
389389
on_skillUsed(userID, skillID, stance, targetIDs)
390390
{
391391
if (this.unit.hasStatus('drunk') || this.unit.hasStatus('offGuard'))

scripts/battleSystem/autoBattler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ class AutoBattler
259259
let lastPhase = this.currentPhase;
260260
this.currentPhase = Math.max(phaseToEnter, this.currentPhase); // ratcheting
261261
if (this.currentPhase > lastPhase) {
262-
console.log(`${this.unit.name} is entering phase ${this.currentPhase}`,
262+
console.log(
263+
`${this.unit.name} is entering Phase ${this.currentPhase}`,
263264
`prev: ${lastPhase > 0 ? lastPhase : "none"}`);
264265
this.on_phaseChanged(this.currentPhase, lastPhase);
265266
}

scripts/battleSystem/battleActor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class BattleActor
117117
break;
118118
case 'sleep':
119119
await new Scene()
120-
.talk("maggie", 2.0, this.name + " fell asleep! Hey, does that mean I get to eat him now?")
120+
.talk("maggie", 1.0, Infinity, `${this.name} fell asleep! Hey, does that mean I get to eat him now?`)
121121
.run();
122122
break;
123123
}

scripts/battleSystem/battleEngine.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { clone } from '../utilities.js';
1010

1111
import BattleScreen from './battleScreen.js';
1212
import BattleUnit, { Row } from './battleUnit.js';
13-
import FieldCondition from './fieldCondition.js';
1413
import MPPool from './mpPool.js';
1514

1615
export
@@ -45,22 +44,6 @@ class BattleEngine extends Thread
4544
: session.party.level;
4645
}
4746

48-
addCondition(conditionID)
49-
{
50-
if (this.hasCondition(conditionID))
51-
return; // nop if already installed
52-
let eventData = { conditionID: conditionID, cancel: false };
53-
this.raiseEvent('conditionInstalled', eventData);
54-
if (!eventData.cancel) {
55-
let effect = new FieldCondition(eventData.conditionID, this);
56-
this.conditions.push(effect);
57-
console.log(`install field condition ${effect.name}`);
58-
}
59-
else {
60-
console.log(`cancel FC '${conditionID}' per existing FC`);
61-
}
62-
}
63-
6447
alliesOf(unit)
6548
{
6649
if (unit.isPartyMember())
@@ -109,7 +92,7 @@ class BattleEngine extends Thread
10992
let battlerInfo = this.session.party.members[key].getInfo();
11093
let mpDonated = Math.round(Maths.mp.capacity(battlerInfo));
11194
partyMaxMP += mpDonated;
112-
console.log(Characters[battlerInfo.characterID].name + " donated " + mpDonated + " MP to shared pool");
95+
console.log(`${Characters[battlerInfo.characterID].name} contributes ${mpDonated} MP`);
11396
}
11497
partyMaxMP = Math.min(Math.max(partyMaxMP, 0), 9999);
11598
let partyMPPool = new MPPool('partyMP', Math.min(Math.max(partyMaxMP, 0), 9999));

scripts/battleSystem/battleUnit.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,19 @@ class BattleUnit
514514
},
515515
'inv'(instruction) {
516516
if (instruction === undefined) {
517-
console.log("'" + this.id + " inv': No instruction provided");
517+
console.log(`'${this.id} inv' - no instruction provided`);
518518
return;
519519
}
520520
let itemCount, itemID;
521521
switch (instruction) {
522522
case 'add': {
523523
if (arguments.length < 2) {
524-
console.log("'" + this.id + " inv add': Item ID required");
524+
console.log(`'${this.id} inv add' - item ID required`);
525525
return;
526526
}
527527
itemID = arguments[1];
528528
if (!(itemID in Items))
529-
return console.log("no such item ID '" + itemID + "'");
529+
return console.log(`no such item ID '${itemID}'`);
530530
let defaultUses = 'uses' in Items[itemID] ? Items[itemID].uses : 1;
531531
itemCount = arguments[2] > 0 ? arguments[2] : defaultUses;
532532
let usables = from(this.items)
@@ -542,33 +542,32 @@ class BattleUnit
542542
this.items.push(usable);
543543
addCount = itemCount;
544544
}
545-
console.log(addCount + "x " + Items[itemID].name + " added to " + this.name + "'s inventory");
545+
console.log(`${addCount}x ${Items[itemID].name} added to ${this.name}'s inventory`);
546546
break;
547547
}
548548
case 'munch': {
549549
new Scene().playSound('Munch.wav').run();
550550
this.items.length = 0;
551-
console.log("maggie ate " + this.name + "'s entire inventory");
551+
console.log(`maggie ate ${this.name}'s entire inventory`);
552552
break;
553553
}
554554
case 'rm': {
555555
if (arguments.length < 2)
556-
return console.log("'" + this.id + " inv add': Item ID required");
556+
return console.log(`'${this.id} inv add' - item ID required`);
557557
itemID = arguments[1];
558558
itemCount = 0;
559559
from(this.items)
560560
.where(it => it.itemID === itemID)
561561
.besides(it => itemCount += it.usesLeft)
562562
.remove();
563563
if (itemCount > 0)
564-
console.log(itemCount + "x " + Items[itemID].name
565-
+ " deleted from " + this.name + "'s inventory");
564+
console.log(`${itemCount}x ${Items[itemID].name} removed from ${this.name}'s inventory`);
566565
else
567-
console.log("No " + Items[itemID].name + " in " + this.name + "'s inventory");
566+
console.log(`no ${Items[itemID].name} in ${this.name}'s inventory`);
568567
break;
569568
}
570569
default: {
571-
return console.log("'" + this.id + " inv': Unknown instruction '" + instruction + "'");
570+
return console.log(`'${this.id} inv' - unknown instruction '${instruction}'`);
572571
}
573572
}
574573
},

scripts/battleSystem/fieldCondition.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

scripts/battleSystem/targetMenu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ class TargetMenu extends Thread
226226
for (let i = 0; i < this.statusNames.length; ++i)
227227
drawTextEx(this.infoFont, 80, y + 16 + 12 * i, this.statusNames[i], statusColor, 1, 'center');
228228
this.drawInfoBox(0, y + nameBoxHeight, 80, 20, 0.5);
229-
drawTextEx(this.infoFont, 40, y + nameBoxHeight + 4, "HP: " + this.unitToShowInfo.hp, statColor, 1, 'center');
229+
drawTextEx(this.infoFont, 40, y + nameBoxHeight + 4, `${this.unitToShowInfo.hp} HP`, statColor, 1, 'center');
230230
this.drawInfoBox(80, y + nameBoxHeight, 80, 20, 0.5);
231-
drawTextEx(this.infoFont, 120, y + nameBoxHeight + 4, "MP: " + this.unitToShowInfo.mpPool.availableMP, statColor, 1, 'center');
231+
drawTextEx(this.infoFont, 120, y + nameBoxHeight + 4, `${this.unitToShowInfo.mpPool.availableMP} MP`, statColor, 1, 'center');
232232
}
233233
else {
234234
let y = 16 - 20 * this.infoBoxFadeness;

scripts/battleSystem/turnPreview.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Prim, Scene, Thread } from 'sphere-runtime';
88
const
99
BoxColor = Color.Black.fadeTo(0.75),
1010
BorderColor = Color.Black.fadeTo(0.85),
11-
TextColor = Color.Gray,
11+
TextColor = Color.Silver,
1212
TextShadowColor = Color.Black;
1313

1414
export default
@@ -60,10 +60,8 @@ class TurnPreview extends Thread
6060
ensureEntries(unit)
6161
{
6262
if (!(unit.tag in this.entries)) {
63-
let iconColor = unit.isPartyMember()
64-
? Color.RoyalBlue
65-
: Color.FireBrick;
66-
let entry = {
63+
const iconColor = unit.isPartyMember() ? Color.RoyalBlue : Color.FireBrick;
64+
const entry = {
6765
icon: new BattlerIcon(unit, iconColor),
6866
turnBoxes: [],
6967
};

scripts/battleSystem/weaponUsable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class WeaponUsable
5757
if (!this.isUsable(unit, unit.stance))
5858
throw new RangeError(`${unit.name} tried to change weapons, which is not currently possible`);
5959

60-
console.log(unit.name + " is equipping " + this.name,
60+
console.log(
61+
`${unit.name} is equipping ${this.name}`,
6162
`targ: ${targets.length > 1 ? "[multi]" : targets[0].name}`);
6263
for (const target of targets)
6364
target.setWeapon(this.weaponID);

scripts/dayNightClock.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ class InGameTime
127127

128128
toString()
129129
{
130-
let hourText = ("0" + this.hour).slice(-2);
131-
let minuteText = ("0" + this.minute).slice(-2);
132-
let secondText = ("0" + this.second).slice(-2);
130+
let hourText = `0${this.hour}`.slice(-2);
131+
let minuteText = `0${this.minute}`.slice(-2);
132+
let secondText = `0${this.second}`.slice(-2);
133133
return `${hourText}:${minuteText}:${secondText}`;
134134
}
135135
}

0 commit comments

Comments
 (0)