Skip to content

Commit 27f63b2

Browse files
committed
fix: merge develop-1.13
2 parents 31cdea6 + b3783c1 commit 27f63b2

17 files changed

Lines changed: 423 additions & 379 deletions

src/ActionPanel.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
3838

3939
let stepNumber = this.props.pressedStepIndex + 1;
4040
const cachedCurrentStepLoopData = currentStep.cache;
41-
if (cachedCurrentStepLoopData != null && cachedCurrentStepLoopData.get('containingLoopPosition') != null) {
42-
stepNumber = cachedCurrentStepLoopData.get('containingLoopPosition');
41+
if (cachedCurrentStepLoopData != null) {
42+
stepNumber = cachedCurrentStepLoopData.getContainingLoopPosition();
4343
}
4444

4545
let stepName = '';
@@ -74,9 +74,8 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
7474
if (this.props.pressedStepIndex > 0) {
7575
const prevStep = this.props.programSequence.getProgramStepAt(this.props.pressedStepIndex - 1);
7676
const cachedPreviousStepLoopData = prevStep.cache;
77-
const prevStepName = prevStep.block;
7877
// When previous step is startLoop, aria-label communicates that movePrevious will move out of the current loop
79-
if (prevStepName === 'startLoop' && currentStep.block !== 'endLoop') {
78+
if (prevStep.block === 'startLoop' && currentStep.block !== 'endLoop') {
8079
return this.props.intl.formatMessage({id: 'ActionPanel.action.moveToPreviousStep.startLoop'},
8180
{
8281
stepNumber,
@@ -85,7 +84,7 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
8584
}
8685
);
8786
// When previous step is endLoop, aria-label communicates that movePrevious will move into a loop
88-
} else if (prevStepName === 'endLoop') {
87+
} else if (prevStep.block === 'endLoop') {
8988
return this.props.intl.formatMessage({id: 'ActionPanel.action.moveToPreviousStep.endLoop'},
9089
{
9190
stepNumber,
@@ -110,16 +109,14 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
110109
)
111110
}
112111
// When previous step is wrapped in a loop, aria-label communicates position within a loop
113-
} else if (cachedPreviousStepLoopData != null &&
114-
cachedPreviousStepLoopData.get('containingLoopPosition') != null &&
115-
cachedPreviousStepLoopData.get('containingLoopLabel') != null) {
112+
} else if (cachedPreviousStepLoopData != null) {
116113
return this.props.intl.formatMessage({id: 'ActionPanel.action.moveToPreviousStep.inLoop'},
117114
{
118115
stepNumber,
119116
stepName,
120-
previousStepNumber: cachedPreviousStepLoopData.get('containingLoopPosition'),
121-
command: this.props.intl.formatMessage({id: `Command.${prevStepName}`}),
122-
loopLabel: cachedPreviousStepLoopData.get('containingLoopLabel'),
117+
previousStepNumber: cachedPreviousStepLoopData.getContainingLoopPosition(),
118+
command: this.props.intl.formatMessage({id: `Command.${prevStep.block}`}),
119+
loopLabel: cachedPreviousStepLoopData.getContainingLoopLabel(),
123120
}
124121
)
125122
// When previous step is a movements step and not in a loop, aria-label communicates position within the program
@@ -129,7 +126,7 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
129126
stepNumber,
130127
stepName,
131128
previousStepNumber: this.props.pressedStepIndex,
132-
command: this.props.intl.formatMessage({id: `Command.${prevStepName}`})
129+
command: this.props.intl.formatMessage({id: `Command.${prevStep.block}`})
133130
}
134131
);
135132
}
@@ -148,9 +145,8 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
148145
if (this.props.pressedStepIndex < (this.props.programSequence.getProgramLength() - 1)) {
149146
const nextStep = this.props.programSequence.getProgramStepAt(this.props.pressedStepIndex + 1);
150147
const cachedNextStepLoopData = nextStep.cache;
151-
const nextStepName = nextStep.block;
152148
// When next step is startLoop, aria-label communicates that moveNext will move into a loop
153-
if (nextStepName === 'startLoop') {
149+
if (nextStep.block === 'startLoop') {
154150
return this.props.intl.formatMessage({id: 'ActionPanel.action.moveToNextStep.startLoop'},
155151
{
156152
stepNumber,
@@ -159,7 +155,7 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
159155
}
160156
);
161157
// When next step is endLoop, aria-label communicates that moveNext will move out of the current loop
162-
} else if (nextStepName === 'endLoop' && currentStep.block !== 'startLoop') {
158+
} else if (nextStep.block === 'endLoop' && currentStep.block !== 'startLoop') {
163159
return this.props.intl.formatMessage({id: 'ActionPanel.action.moveToNextStep.endLoop'},
164160
{
165161
stepNumber,
@@ -184,16 +180,14 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
184180
);
185181
}
186182
// When next step is wrapped in a loop, aria-label communicates position within a loop
187-
} else if (cachedNextStepLoopData != null &&
188-
cachedNextStepLoopData.get('containingLoopPosition') != null &&
189-
cachedNextStepLoopData.get('containingLoopLabel') != null) {
183+
} else if (cachedNextStepLoopData != null) {
190184
return this.props.intl.formatMessage({id: 'ActionPanel.action.moveToNextStep.inLoop'},
191185
{
192186
stepNumber,
193187
stepName,
194-
nextStepNumber: cachedNextStepLoopData.get('containingLoopPosition'),
195-
command: this.props.intl.formatMessage({id: `Command.${nextStepName}`}),
196-
loopLabel: cachedNextStepLoopData.get('containingLoopLabel')
188+
nextStepNumber: cachedNextStepLoopData.getContainingLoopPosition(),
189+
command: this.props.intl.formatMessage({id: `Command.${nextStep.block}`}),
190+
loopLabel: cachedNextStepLoopData.getContainingLoopLabel()
197191
}
198192
);
199193
// When next step is a movements step and not in a loop, aria-label communicates position within the program

src/ActionPanel.test.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Adapter from 'enzyme-adapter-react-16';
55
import { configure, mount } from 'enzyme';
66
import { IntlProvider } from 'react-intl';
77
import ActionPanel from './ActionPanel';
8+
import ProgramBlockCache from './ProgramBlockCache';
89
import ProgramSequence from './ProgramSequence';
910
import messages from './messages.json';
1011

@@ -233,10 +234,7 @@ describe('ActionPanel options', () => {
233234
},
234235
{
235236
block: 'forward1',
236-
cache: new Map([
237-
['containingLoopPosition', 1],
238-
['containingLoopLabel', 'A']
239-
])
237+
cache: new ProgramBlockCache('A', 1)
240238
},
241239
{
242240
block: 'endLoop',
@@ -288,17 +286,11 @@ describe('ActionPanel options', () => {
288286
},
289287
{
290288
block: 'forward1',
291-
cache: new Map([
292-
['containingLoopPosition', 1],
293-
['containingLoopLabel', 'A']
294-
])
289+
cache: new ProgramBlockCache('A', 1)
295290
},
296291
{
297292
block: 'forward2',
298-
cache: new Map([
299-
['containingLoopPosition', 2],
300-
['containingLoopLabel', 'A']
301-
])
293+
cache: new ProgramBlockCache('A', 2)
302294
},
303295
{
304296
block: 'endLoop',
@@ -443,10 +435,7 @@ describe('ActionPanel options', () => {
443435
},
444436
{
445437
block: 'forward1',
446-
cache: new Map([
447-
['containingLoopPosition', 1],
448-
['containingLoopLabel', 'A']
449-
])
438+
cache: new ProgramBlockCache('A', 1)
450439
},
451440
{
452441
block: 'endLoop',
@@ -498,17 +487,11 @@ describe('ActionPanel options', () => {
498487
},
499488
{
500489
block: 'forward1',
501-
cache: new Map([
502-
['containingLoopPosition', 1],
503-
['containingLoopLabel', 'A']
504-
])
490+
cache: new ProgramBlockCache('A', 1)
505491
},
506492
{
507493
block: 'forward2',
508-
cache: new Map([
509-
['containingLoopPosition', 2],
510-
['containingLoopLabel', 'A']
511-
])
494+
cache: new ProgramBlockCache('A', 2)
512495
},
513496
{
514497
block: 'endLoop',

src/ActionsHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import CharacterMessageBuilder from './CharacterMessageBuilder';
66
import type { CharacterUpdate } from './CharacterState';
77
import type { IntlShape } from 'react-intl';
88
import SceneDimensions from './SceneDimensions';
9-
import type { AudioManager, BlockName } from './types';
9+
import type { AudioManager, MovementBlockName } from './types';
1010

1111
// The ActionsHandler is called by the Interpreter for each program
1212
// step action as the program is running, and is responsible for
@@ -27,7 +27,7 @@ export default class ActionsHandler {
2727
this.characterMessageBuilder = new CharacterMessageBuilder(sceneDimensions, intl);
2828
}
2929

30-
doAction(action: BlockName, stepTimeMs: number): Promise<ActionResult> {
30+
doAction(action: MovementBlockName, stepTimeMs: number): Promise<ActionResult> {
3131
switch(action) {
3232
case 'forward1':
3333
return this.forward(1, action, stepTimeMs);

src/ActionsHandler.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import CharacterState from './CharacterState';
88
import CustomBackground from './CustomBackground';
99
import { createIntl } from 'react-intl';
1010
import SceneDimensions from './SceneDimensions';
11-
import type { BlockName } from './types';
11+
import type { MovementBlockName } from './types';
1212

1313
import messages from './messages.json';
1414

@@ -49,7 +49,7 @@ function createActionsHandler() {
4949
}
5050

5151
type MovementTestCase = {|
52-
action: BlockName,
52+
action: MovementBlockName,
5353
x: number,
5454
y: number,
5555
direction: number,

src/AnnouncementBuilder.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,38 @@ export default class AnnouncementBuilder {
6060
}
6161

6262
buildDeleteStepAnnouncement(programBlock: ProgramBlock): AnnouncementData {
63-
let commandType = null;
6463
if (programBlock.block === 'startLoop' || programBlock.block === 'endLoop') {
65-
commandType = this.intl.formatMessage({
66-
id: "Announcement.control"
67-
});
64+
return {
65+
messageIdSuffix: 'delete',
66+
values: {
67+
commandType: this.intl.formatMessage({
68+
id: "Announcement.control"
69+
}),
70+
command: this.intl.formatMessage(
71+
{
72+
id: `Announcement.${programBlock.block}`
73+
},
74+
{
75+
loopLabel: programBlock.label
76+
}
77+
)
78+
}
79+
};
6880
} else {
69-
commandType = this.intl.formatMessage({
70-
id: "Announcement.movement"
71-
});
81+
return {
82+
messageIdSuffix: 'delete',
83+
values: {
84+
commandType: this.intl.formatMessage({
85+
id: "Announcement.movement"
86+
}),
87+
command: this.intl.formatMessage(
88+
{
89+
id: `Announcement.${programBlock.block}`
90+
}
91+
)
92+
}
93+
};
7294
}
73-
return {
74-
messageIdSuffix: 'delete',
75-
values: {
76-
commandType: commandType,
77-
command: this.intl.formatMessage(
78-
{
79-
id: `Announcement.${programBlock.block}`
80-
},
81-
{
82-
loopLabel: programBlock.label
83-
}
84-
)
85-
}
86-
};
8795
}
8896

8997
buildReplaceStepAnnouncement(programBlock: ProgramBlock,

src/AnnouncementBuilder.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ describe('Test buildDeleteStepAnnouncement()', () => {
6464

6565
const startLoopBlock = {
6666
block: 'startLoop',
67-
label: 'A'
67+
label: 'A',
68+
iterations: 1
6869
};
6970

7071
expect(announcementBuilder.buildDeleteStepAnnouncement(startLoopBlock)).toStrictEqual({

src/Interpreter.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { App } from './App';
44
import ActionsHandler from './ActionsHandler';
55
import type { ActionResult } from './ActionsHandler';
66
import ProgramSequence from './ProgramSequence';
7-
import type { ProgramBlock } from './types';
7+
import type { MovementProgramBlock } from './types';
88

99
export default class Interpreter {
1010
stepTimeMs: number;
@@ -84,14 +84,13 @@ export default class Interpreter {
8484
resolve('success');
8585
} else {
8686
const currentProgramStep = programSequence.getCurrentProgramStep();
87-
const block = currentProgramStep.block;
88-
if (block === 'startLoop') {
87+
if (currentProgramStep.block === 'startLoop') {
8988
this.doStartLoop(programSequence).then(() => {
9089
this.app.advanceProgramCounter(() => {
9190
resolve('success');
9291
});
9392
});
94-
} else if (block === 'endLoop') {
93+
} else if (currentProgramStep.block === 'endLoop') {
9594
// We don't intend for the programCounter to ever be on an
9695
// 'endLoop' block, but we might have a bug that would
9796
// cause that case to happen and we want to handle it
@@ -131,7 +130,7 @@ export default class Interpreter {
131130
}
132131
}
133132

134-
doAction(programStep: ProgramBlock): Promise<ActionResult> {
133+
doAction(programStep: MovementProgramBlock): Promise<ActionResult> {
135134
return this.actionsHandler.doAction(programStep.block, this.stepTimeMs);
136135
}
137136
}

src/Interpreter.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Interpreter from './Interpreter';
66
import ProgramSequence from './ProgramSequence';
77
import type { IntlShape } from 'react-intl';
88
import SceneDimensions from './SceneDimensions';
9-
import type { AudioManager, BlockName } from './types';
9+
import type { AudioManager, MovementBlockName } from './types';
1010

1111
jest.mock('./ActionsHandler');
1212
jest.mock('./App');
@@ -30,7 +30,7 @@ function createInterpreter() {
3030
((null: any): IntlShape)
3131
);
3232

33-
actionsHandlerMock.doAction.mockImplementation((action: BlockName) => {
33+
actionsHandlerMock.doAction.mockImplementation((action: MovementBlockName) => {
3434
// Mock ActionsHandler behaviour to test handling of different
3535
// Promise results
3636
switch(action) {

src/ProgramBlockCache.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @flow
2+
3+
export default class ProgramBlockCache {
4+
containingLoopLabel: string;
5+
containingLoopPosition: number;
6+
7+
constructor(containingLoopLabel: string, containingLoopPosition: number) {
8+
this.containingLoopLabel = containingLoopLabel;
9+
this.containingLoopPosition = containingLoopPosition;
10+
}
11+
12+
getContainingLoopLabel(): string {
13+
return this.containingLoopLabel;
14+
}
15+
16+
getContainingLoopPosition(): number {
17+
return this.containingLoopPosition;
18+
}
19+
};

0 commit comments

Comments
 (0)