Skip to content

Commit b89d1c4

Browse files
committed
Merge branch 'develop-1.13' into language-selector
2 parents 57915b7 + b3783c1 commit b89d1c4

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 = '';
@@ -78,15 +78,14 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
7878
if (this.props.pressedStepIndex > 0) {
7979
const prevStep = this.props.programSequence.getProgramStepAt(this.props.pressedStepIndex - 1);
8080
const cachedPreviousStepLoopData = prevStep.cache;
81-
const prevStepName = prevStep.block;
8281
// When previous step is startLoop, aria-label communicates that movePrevious will move out of the current loop
83-
if (prevStepName === 'startLoop' && currentStep.block !== 'endLoop') {
82+
if (prevStep.block === 'startLoop' && currentStep.block !== 'endLoop') {
8483
return this.props.intl.formatMessage(
8584
{ id: 'CommandInfo.previousStep.startLoop' },
8685
{ loopLabel: prevStep.label }
8786
);
8887
// When previous step is endLoop, aria-label communicates that movePrevious will move into a loop
89-
} else if (prevStepName === 'endLoop') {
88+
} else if (prevStep.block === 'endLoop') {
9089
return this.props.intl.formatMessage(
9190
{ id: 'CommandInfo.previousStep.endLoop'},
9291
{ loopLabel: prevStep.label }
@@ -107,15 +106,13 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
107106
)
108107
}
109108
// When previous step is wrapped in a loop, aria-label communicates position within a loop
110-
} else if (cachedPreviousStepLoopData != null &&
111-
cachedPreviousStepLoopData.get('containingLoopPosition') != null &&
112-
cachedPreviousStepLoopData.get('containingLoopLabel') != null) {
109+
} else if (cachedPreviousStepLoopData != null) {
113110
return this.props.intl.formatMessage(
114111
{ id: 'CommandInfo.previousStep.inLoop'},
115112
{
116-
previousStepNumber: cachedPreviousStepLoopData.get('containingLoopPosition'),
117-
command: this.props.intl.formatMessage({id: `Command.${prevStepName}`}),
118-
loopLabel: cachedPreviousStepLoopData.get('containingLoopLabel')
113+
previousStepNumber: cachedPreviousStepLoopData.getContainingLoopPosition(),
114+
command: this.props.intl.formatMessage({id: `Command.${prevStep.block}`}),
115+
loopLabel: cachedPreviousStepLoopData.getContainingLoopLabel(),
119116
}
120117
)
121118
// When previous step is a movements step and not in a loop, aria-label communicates position within the program
@@ -124,7 +121,7 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
124121
{ id: 'CommandInfo.previousStep'},
125122
{
126123
previousStepNumber: this.props.pressedStepIndex,
127-
command: this.props.intl.formatMessage({id: `Command.${prevStepName}`})
124+
command: this.props.intl.formatMessage({id: `Command.${prevStep.block}`})
128125
}
129126
);
130127
}
@@ -137,15 +134,14 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
137134
if (this.props.pressedStepIndex < (this.props.programSequence.getProgramLength() - 1)) {
138135
const nextStep = this.props.programSequence.getProgramStepAt(this.props.pressedStepIndex + 1);
139136
const cachedNextStepLoopData = nextStep.cache;
140-
const nextStepName = nextStep.block;
141137
// When next step is startLoop, aria-label communicates that moveNext will move into a loop
142-
if (nextStepName === 'startLoop') {
138+
if (nextStep.block === 'startLoop') {
143139
return this.props.intl.formatMessage(
144140
{ id: 'CommandInfo.nextStep.startLoop'},
145141
{ loopLabel: nextStep.label }
146142
);
147143
// When next step is endLoop, aria-label communicates that moveNext will move out of the current loop
148-
} else if (nextStepName === 'endLoop' && currentStep.block !== 'startLoop') {
144+
} else if (nextStep.block === 'endLoop' && currentStep.block !== 'startLoop') {
149145
return this.props.intl.formatMessage(
150146
{ id: 'CommandInfo.nextStep.endLoop'},
151147
{ loopLabel: nextStep.label }
@@ -166,15 +162,13 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
166162
);
167163
}
168164
// When next step is wrapped in a loop, aria-label communicates position within a loop
169-
} else if (cachedNextStepLoopData != null &&
170-
cachedNextStepLoopData.get('containingLoopPosition') != null &&
171-
cachedNextStepLoopData.get('containingLoopLabel') != null) {
165+
} else if (cachedNextStepLoopData != null) {
172166
return this.props.intl.formatMessage(
173167
{ id: 'CommandInfo.nextStep.inLoop'},
174168
{
175-
nextStepNumber: cachedNextStepLoopData.get('containingLoopPosition'),
176-
command: this.props.intl.formatMessage({id: `Command.${nextStepName}`}),
177-
loopLabel: cachedNextStepLoopData.get('containingLoopLabel')
169+
nextStepNumber: cachedNextStepLoopData.getContainingLoopPosition(),
170+
command: this.props.intl.formatMessage({id: `Command.${nextStep.block}`}),
171+
loopLabel: cachedNextStepLoopData.getContainingLoopLabel()
178172
}
179173
);
180174
// 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)