forked from codelearncreate/c2lc-coding-environment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterDescriptionBuilder.js
More file actions
58 lines (50 loc) · 1.74 KB
/
CharacterDescriptionBuilder.js
File metadata and controls
58 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// @flow
import CharacterState from './CharacterState';
import CustomBackground from './CustomBackground';
import type { IntlShape } from 'react-intl';
import { getBackgroundSquareDescription } from './Utils';
import type { WorldName } from './Worlds';
export default class CharacterDescriptionBuilder {
intl: IntlShape;
constructor(intl: IntlShape) {
this.intl = intl;
}
buildDescription(characterState: CharacterState,
world: WorldName, customBackground: CustomBackground): string {
const columnLabel = characterState.getColumnLabel();
const rowLabel = characterState.getRowLabel();
const itemLabel = getBackgroundSquareDescription(
characterState.xPos,
characterState.yPos,
characterState.sceneDimensions,
world,
customBackground,
this.intl
);
const directionLabel = this.intl.formatMessage({id: `Direction.${characterState.direction}`});
if (itemLabel) {
return this.intl.formatMessage(
{
id:'CharacterDescriptionBuilder.positionAndDirectionAndItem'
},
{
columnLabel: columnLabel,
rowLabel: rowLabel,
backgroundItem: itemLabel,
direction: directionLabel
}
);
} else {
return this.intl.formatMessage(
{
id:'CharacterDescriptionBuilder.positionAndDirection'
},
{
columnLabel: columnLabel,
rowLabel: rowLabel,
direction: directionLabel
}
);
}
}
};