Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions src/ActionPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {

let stepNumber = this.props.pressedStepIndex + 1;
const cachedCurrentStepLoopData = currentStep.cache;
if (cachedCurrentStepLoopData != null && cachedCurrentStepLoopData.get('containingLoopPosition') != null) {
stepNumber = cachedCurrentStepLoopData.get('containingLoopPosition');
if (cachedCurrentStepLoopData != null) {
stepNumber = cachedCurrentStepLoopData.getContainingLoopPosition();
}

let stepName = '';
Expand Down Expand Up @@ -78,15 +78,14 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
if (this.props.pressedStepIndex > 0) {
const prevStep = this.props.programSequence.getProgramStepAt(this.props.pressedStepIndex - 1);
const cachedPreviousStepLoopData = prevStep.cache;
const prevStepName = prevStep.block;
// When previous step is startLoop, aria-label communicates that movePrevious will move out of the current loop
if (prevStepName === 'startLoop' && currentStep.block !== 'endLoop') {
if (prevStep.block === 'startLoop' && currentStep.block !== 'endLoop') {
return this.props.intl.formatMessage(
{ id: 'CommandInfo.previousStep.startLoop' },
{ loopLabel: prevStep.label }
);
// When previous step is endLoop, aria-label communicates that movePrevious will move into a loop
} else if (prevStepName === 'endLoop') {
} else if (prevStep.block === 'endLoop') {
return this.props.intl.formatMessage(
{ id: 'CommandInfo.previousStep.endLoop'},
{ loopLabel: prevStep.label }
Expand All @@ -107,15 +106,13 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
)
}
// When previous step is wrapped in a loop, aria-label communicates position within a loop
} else if (cachedPreviousStepLoopData != null &&
cachedPreviousStepLoopData.get('containingLoopPosition') != null &&
cachedPreviousStepLoopData.get('containingLoopLabel') != null) {
} else if (cachedPreviousStepLoopData != null) {
return this.props.intl.formatMessage(
{ id: 'CommandInfo.previousStep.inLoop'},
{
previousStepNumber: cachedPreviousStepLoopData.get('containingLoopPosition'),
command: this.props.intl.formatMessage({id: `Command.${prevStepName}`}),
loopLabel: cachedPreviousStepLoopData.get('containingLoopLabel')
previousStepNumber: cachedPreviousStepLoopData.getContainingLoopPosition(),
command: this.props.intl.formatMessage({id: `Command.${prevStep.block}`}),
loopLabel: cachedPreviousStepLoopData.getContainingLoopLabel(),
}
)
// When previous step is a movements step and not in a loop, aria-label communicates position within the program
Expand All @@ -124,7 +121,7 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
{ id: 'CommandInfo.previousStep'},
{
previousStepNumber: this.props.pressedStepIndex,
command: this.props.intl.formatMessage({id: `Command.${prevStepName}`})
command: this.props.intl.formatMessage({id: `Command.${prevStep.block}`})
}
);
}
Expand All @@ -137,15 +134,14 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
if (this.props.pressedStepIndex < (this.props.programSequence.getProgramLength() - 1)) {
const nextStep = this.props.programSequence.getProgramStepAt(this.props.pressedStepIndex + 1);
const cachedNextStepLoopData = nextStep.cache;
const nextStepName = nextStep.block;
// When next step is startLoop, aria-label communicates that moveNext will move into a loop
if (nextStepName === 'startLoop') {
if (nextStep.block === 'startLoop') {
return this.props.intl.formatMessage(
{ id: 'CommandInfo.nextStep.startLoop'},
{ loopLabel: nextStep.label }
);
// When next step is endLoop, aria-label communicates that moveNext will move out of the current loop
} else if (nextStepName === 'endLoop' && currentStep.block !== 'startLoop') {
} else if (nextStep.block === 'endLoop' && currentStep.block !== 'startLoop') {
return this.props.intl.formatMessage(
{ id: 'CommandInfo.nextStep.endLoop'},
{ loopLabel: nextStep.label }
Expand All @@ -166,15 +162,13 @@ class ActionPanel extends React.Component<ActionPanelProps, {}> {
);
}
// When next step is wrapped in a loop, aria-label communicates position within a loop
} else if (cachedNextStepLoopData != null &&
cachedNextStepLoopData.get('containingLoopPosition') != null &&
cachedNextStepLoopData.get('containingLoopLabel') != null) {
} else if (cachedNextStepLoopData != null) {
return this.props.intl.formatMessage(
{ id: 'CommandInfo.nextStep.inLoop'},
{
nextStepNumber: cachedNextStepLoopData.get('containingLoopPosition'),
command: this.props.intl.formatMessage({id: `Command.${nextStepName}`}),
loopLabel: cachedNextStepLoopData.get('containingLoopLabel')
nextStepNumber: cachedNextStepLoopData.getContainingLoopPosition(),
command: this.props.intl.formatMessage({id: `Command.${nextStep.block}`}),
loopLabel: cachedNextStepLoopData.getContainingLoopLabel()
}
);
// When next step is a movements step and not in a loop, aria-label communicates position within the program
Expand Down
31 changes: 7 additions & 24 deletions src/ActionPanel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Adapter from 'enzyme-adapter-react-16';
import { configure, mount } from 'enzyme';
import { IntlProvider } from 'react-intl';
import ActionPanel from './ActionPanel';
import ProgramBlockCache from './ProgramBlockCache';
import ProgramSequence from './ProgramSequence';
import messages from './messages.json';

Expand Down Expand Up @@ -233,10 +234,7 @@ describe('ActionPanel options', () => {
},
{
block: 'forward1',
cache: new Map([
['containingLoopPosition', 1],
['containingLoopLabel', 'A']
])
cache: new ProgramBlockCache('A', 1)
},
{
block: 'endLoop',
Expand Down Expand Up @@ -288,17 +286,11 @@ describe('ActionPanel options', () => {
},
{
block: 'forward1',
cache: new Map([
['containingLoopPosition', 1],
['containingLoopLabel', 'A']
])
cache: new ProgramBlockCache('A', 1)
},
{
block: 'forward2',
cache: new Map([
['containingLoopPosition', 2],
['containingLoopLabel', 'A']
])
cache: new ProgramBlockCache('A', 2)
},
{
block: 'endLoop',
Expand Down Expand Up @@ -443,10 +435,7 @@ describe('ActionPanel options', () => {
},
{
block: 'forward1',
cache: new Map([
['containingLoopPosition', 1],
['containingLoopLabel', 'A']
])
cache: new ProgramBlockCache('A', 1)
},
{
block: 'endLoop',
Expand Down Expand Up @@ -498,17 +487,11 @@ describe('ActionPanel options', () => {
},
{
block: 'forward1',
cache: new Map([
['containingLoopPosition', 1],
['containingLoopLabel', 'A']
])
cache: new ProgramBlockCache('A', 1)
},
{
block: 'forward2',
cache: new Map([
['containingLoopPosition', 2],
['containingLoopLabel', 'A']
])
cache: new ProgramBlockCache('A', 2)
},
{
block: 'endLoop',
Expand Down
4 changes: 2 additions & 2 deletions src/ActionsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CharacterMessageBuilder from './CharacterMessageBuilder';
import type { CharacterUpdate } from './CharacterState';
import type { IntlShape } from 'react-intl';
import SceneDimensions from './SceneDimensions';
import type { AudioManager, BlockName } from './types';
import type { AudioManager, MovementBlockName } from './types';

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

doAction(action: BlockName, stepTimeMs: number): Promise<ActionResult> {
doAction(action: MovementBlockName, stepTimeMs: number): Promise<ActionResult> {
switch(action) {
case 'forward1':
return this.forward(1, action, stepTimeMs);
Expand Down
4 changes: 2 additions & 2 deletions src/ActionsHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CharacterState from './CharacterState';
import CustomBackground from './CustomBackground';
import { createIntl } from 'react-intl';
import SceneDimensions from './SceneDimensions';
import type { BlockName } from './types';
import type { MovementBlockName } from './types';

import messages from './messages.json';

Expand Down Expand Up @@ -49,7 +49,7 @@ function createActionsHandler() {
}

type MovementTestCase = {|
action: BlockName,
action: MovementBlockName,
x: number,
y: number,
direction: number,
Expand Down
50 changes: 29 additions & 21 deletions src/AnnouncementBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,38 @@ export default class AnnouncementBuilder {
}

buildDeleteStepAnnouncement(programBlock: ProgramBlock): AnnouncementData {
let commandType = null;
if (programBlock.block === 'startLoop' || programBlock.block === 'endLoop') {
commandType = this.intl.formatMessage({
id: "Announcement.control"
});
return {
messageIdSuffix: 'delete',
values: {
commandType: this.intl.formatMessage({
id: "Announcement.control"
}),
command: this.intl.formatMessage(
{
id: `Announcement.${programBlock.block}`
},
{
loopLabel: programBlock.label
}
)
}
};
} else {
commandType = this.intl.formatMessage({
id: "Announcement.movement"
});
return {
messageIdSuffix: 'delete',
values: {
commandType: this.intl.formatMessage({
id: "Announcement.movement"
}),
command: this.intl.formatMessage(
{
id: `Announcement.${programBlock.block}`
}
)
}
};
}
return {
messageIdSuffix: 'delete',
values: {
commandType: commandType,
command: this.intl.formatMessage(
{
id: `Announcement.${programBlock.block}`
},
{
loopLabel: programBlock.label
}
)
}
};
}

buildReplaceStepAnnouncement(programBlock: ProgramBlock,
Expand Down
3 changes: 2 additions & 1 deletion src/AnnouncementBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ describe('Test buildDeleteStepAnnouncement()', () => {

const startLoopBlock = {
block: 'startLoop',
label: 'A'
label: 'A',
iterations: 1
};

expect(announcementBuilder.buildDeleteStepAnnouncement(startLoopBlock)).toStrictEqual({
Expand Down
9 changes: 4 additions & 5 deletions src/Interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { App } from './App';
import ActionsHandler from './ActionsHandler';
import type { ActionResult } from './ActionsHandler';
import ProgramSequence from './ProgramSequence';
import type { ProgramBlock } from './types';
import type { MovementProgramBlock } from './types';

export default class Interpreter {
stepTimeMs: number;
Expand Down Expand Up @@ -84,14 +84,13 @@ export default class Interpreter {
resolve('success');
} else {
const currentProgramStep = programSequence.getCurrentProgramStep();
const block = currentProgramStep.block;
if (block === 'startLoop') {
if (currentProgramStep.block === 'startLoop') {
this.doStartLoop(programSequence).then(() => {
this.app.advanceProgramCounter(() => {
resolve('success');
});
});
} else if (block === 'endLoop') {
} else if (currentProgramStep.block === 'endLoop') {
// We don't intend for the programCounter to ever be on an
// 'endLoop' block, but we might have a bug that would
// cause that case to happen and we want to handle it
Expand Down Expand Up @@ -131,7 +130,7 @@ export default class Interpreter {
}
}

doAction(programStep: ProgramBlock): Promise<ActionResult> {
doAction(programStep: MovementProgramBlock): Promise<ActionResult> {
return this.actionsHandler.doAction(programStep.block, this.stepTimeMs);
}
}
4 changes: 2 additions & 2 deletions src/Interpreter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Interpreter from './Interpreter';
import ProgramSequence from './ProgramSequence';
import type { IntlShape } from 'react-intl';
import SceneDimensions from './SceneDimensions';
import type { AudioManager, BlockName } from './types';
import type { AudioManager, MovementBlockName } from './types';

jest.mock('./ActionsHandler');
jest.mock('./App');
Expand All @@ -30,7 +30,7 @@ function createInterpreter() {
((null: any): IntlShape)
);

actionsHandlerMock.doAction.mockImplementation((action: BlockName) => {
actionsHandlerMock.doAction.mockImplementation((action: MovementBlockName) => {
// Mock ActionsHandler behaviour to test handling of different
// Promise results
switch(action) {
Expand Down
19 changes: 19 additions & 0 deletions src/ProgramBlockCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow

export default class ProgramBlockCache {
containingLoopLabel: string;
containingLoopPosition: number;

constructor(containingLoopLabel: string, containingLoopPosition: number) {
this.containingLoopLabel = containingLoopLabel;
this.containingLoopPosition = containingLoopPosition;
}

getContainingLoopLabel(): string {
return this.containingLoopLabel;
}

getContainingLoopPosition(): number {
return this.containingLoopPosition;
}
};
Loading