@rpg-engine/long-bow 0.1.794 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +181 -181
- package/dist/components/Button.d.ts +1 -0
- package/dist/components/Equipment/EquipmentSet.d.ts +5 -3
- package/dist/components/Item/Cards/ItemTooltip.d.ts +6 -0
- package/dist/components/Item/Inventory/ItemContainer.d.ts +4 -6
- package/dist/components/Item/Inventory/ItemContainerTypes.d.ts +6 -0
- package/dist/components/Item/Inventory/ItemSlot.d.ts +5 -9
- package/dist/components/Item/Inventory/itemContainerHelper.d.ts +2 -7
- package/dist/components/PropertySelect/PropertySelect.d.ts +12 -0
- package/dist/components/QuestInfo/QuestInfo.d.ts +14 -0
- package/dist/components/RelativeListMenu.d.ts +13 -0
- package/dist/index.d.ts +1 -1
- package/dist/long-bow.cjs.development.js +748 -1194
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +748 -1196
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/mocks/equipmentSet.mocks.d.ts +2 -2
- package/dist/stories/Button.stories.d.ts +5 -0
- package/dist/stories/Chat.stories.d.ts +5 -0
- package/dist/stories/CheckButton.stories.d.ts +5 -0
- package/dist/stories/DraggableContainer.stories.d.ts +5 -0
- package/dist/stories/Dropdown.stories.d.ts +5 -0
- package/dist/stories/EquipmentSet.stories.d.ts +5 -0
- package/dist/stories/ItemContainer.stories.d.ts +5 -0
- package/dist/stories/ListMenu.stories.d.ts +5 -0
- package/dist/stories/Multitab.stories.d.ts +6 -0
- package/dist/stories/NPCDialog.stories.d.ts +7 -0
- package/dist/stories/ProgressBar.stories.d.ts +8 -0
- package/dist/stories/PropertySelect.stories.d.ts +5 -0
- package/dist/stories/QuestInfo.stories.d.ts +5 -0
- package/dist/stories/RPGUIContainers.stories.d.ts +5 -0
- package/dist/stories/RadioButton.stories.d.ts +5 -0
- package/dist/stories/RangeSlider.stories.d.ts +5 -0
- package/dist/stories/ScrollList.stories.d.ts +5 -0
- package/dist/stories/SimpleProgressBar.stories.d.ts +5 -0
- package/dist/stories/SkillProgressBar.stories.d.ts +5 -0
- package/dist/stories/SkillsContainer.stories.d.ts +5 -0
- package/dist/stories/Text.stories.d.ts +7 -0
- package/package.json +98 -96
- package/src/components/Abstractions/SlotsContainer.tsx +42 -42
- package/src/components/Button.tsx +30 -29
- package/src/components/Chat/Chat.tsx +193 -193
- package/src/components/CheckButton.tsx +65 -65
- package/src/components/DraggableContainer.tsx +150 -150
- package/src/components/Dropdown.tsx +57 -57
- package/src/components/Equipment/EquipmentSet.tsx +138 -180
- package/src/components/Input.tsx +11 -11
- package/src/components/Item/Cards/ItemTooltip.tsx +32 -0
- package/src/components/Item/Inventory/ItemContainer.tsx +68 -113
- package/src/components/Item/Inventory/ItemContainerTypes.ts +6 -0
- package/src/components/Item/Inventory/ItemSlot.tsx +212 -158
- package/src/components/Item/Inventory/itemContainerHelper.ts +146 -81
- package/src/components/ListMenu.tsx +65 -65
- package/src/components/Multitab/Tab.tsx +57 -57
- package/src/components/Multitab/TabBody.tsx +13 -13
- package/src/components/Multitab/TabsContainer.tsx +97 -97
- package/src/components/NPCDialog/NPCDialog.tsx +145 -145
- package/src/components/NPCDialog/NPCDialogText.tsx +53 -53
- package/src/components/NPCDialog/QuestionDialog/QuestionDialog.tsx +237 -242
- package/src/components/ProgressBar.tsx +91 -91
- package/src/components/PropertySelect/PropertySelect.tsx +101 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-left-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-left.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-right-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow01-right.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-left-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-left.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-right-clicked.png +0 -0
- package/src/components/PropertySelect/img/ui-arrows/arrow02-right.png +0 -0
- package/src/components/QuestInfo/QuestInfo.tsx +143 -0
- package/src/components/QuestInfo/img/default.png +0 -0
- package/src/components/RPGUIContainer.tsx +47 -47
- package/src/components/RPGUIRoot.tsx +14 -14
- package/src/components/RadioButton.tsx +53 -53
- package/src/components/RangeSlider.tsx +68 -68
- package/src/components/RelativeListMenu.tsx +83 -0
- package/src/components/ScrollList.tsx +77 -77
- package/src/components/SimpleProgressBar.tsx +62 -62
- package/src/components/SkillProgressBar.tsx +123 -124
- package/src/components/SkillsContainer.tsx +196 -235
- package/src/components/TextArea.tsx +11 -11
- package/src/components/Truncate.tsx +25 -25
- package/src/components/shared/Column.tsx +16 -16
- package/src/components/shared/SpriteFromAtlas.tsx +99 -99
- package/src/components/typography/DynamicText.tsx +49 -49
- package/src/constants/uiColors.ts +10 -10
- package/src/hooks/useEventListener.ts +21 -21
- package/src/hooks/useOutsideAlerter.ts +25 -25
- package/src/index.tsx +25 -25
- package/src/libs/StringHelpers.ts +3 -3
- package/src/mocks/atlas/icons/icons.json +735 -303
- package/src/mocks/atlas/icons/icons.png +0 -0
- package/src/mocks/atlas/items/items.json +5215 -5195
- package/src/mocks/atlas/items/items.png +0 -0
- package/src/mocks/equipmentSet.mocks.ts +347 -347
- package/src/mocks/itemContainer.mocks.ts +281 -249
- package/src/mocks/skills.mocks.ts +122 -122
- package/src/stories/Button.stories.tsx +36 -0
- package/src/stories/Chat.stories.tsx +170 -0
- package/src/stories/CheckButton.stories.tsx +48 -0
- package/src/stories/DraggableContainer.stories.tsx +28 -0
- package/src/stories/Dropdown.stories.tsx +46 -0
- package/src/stories/EquipmentSet.stories.tsx +51 -0
- package/src/stories/ItemContainer.stories.tsx +51 -0
- package/src/stories/ListMenu.stories.tsx +56 -0
- package/src/stories/Multitab.stories.tsx +51 -0
- package/src/stories/NPCDialog.stories.tsx +130 -0
- package/src/stories/ProgressBar.stories.tsx +23 -0
- package/src/stories/PropertySelect.stories.tsx +41 -0
- package/src/stories/QuestInfo.stories.tsx +76 -0
- package/src/stories/RPGUIContainers.stories.tsx +42 -0
- package/src/stories/RadioButton.stories.tsx +49 -0
- package/src/stories/RangeSlider.stories.tsx +60 -0
- package/src/stories/ScrollList.stories.tsx +85 -0
- package/src/stories/SimpleProgressBar.stories.tsx +22 -0
- package/src/stories/SkillProgressBar.stories.tsx +30 -0
- package/src/stories/SkillsContainer.stories.tsx +31 -0
- package/src/stories/Text.stories.tsx +42 -0
- package/src/types/eventTypes.ts +4 -4
- package/src/types/index.d.ts +2 -2
- package/dist/components/Item/Cards/ItemCard.d.ts +0 -9
- package/dist/components/shared/SpriteIcon.d.ts +0 -9
- package/dist/components/store/UI.store.d.ts +0 -38
- package/src/components/Item/Cards/ItemCard.tsx +0 -36
- package/src/components/shared/SpriteIcon.tsx +0 -67
- package/src/components/store/UI.store.ts +0 -232
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
import { RPGUIContainer, RPGUIContainerTypes } from '../RPGUIContainer';
|
|
4
|
-
import aliceDefaultThumbnail from './img/npcDialog/npcThumbnails/alice.png';
|
|
5
|
-
import pressSpaceGif from './img/space.gif';
|
|
6
|
-
import { NPCDialogText } from './NPCDialogText';
|
|
7
|
-
import {
|
|
8
|
-
IQuestionDialog,
|
|
9
|
-
IQuestionDialogAnswer,
|
|
10
|
-
QuestionDialog,
|
|
11
|
-
} from './QuestionDialog/QuestionDialog';
|
|
12
|
-
|
|
13
|
-
export enum NPCDialogType {
|
|
14
|
-
TextOnly = 'TextOnly',
|
|
15
|
-
TextAndThumbnail = 'TextAndThumbnail',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface INPCDialogProps {
|
|
19
|
-
text?: string;
|
|
20
|
-
type: NPCDialogType;
|
|
21
|
-
imagePath?: string;
|
|
22
|
-
onClose?: () => void;
|
|
23
|
-
isQuestionDialog?: boolean;
|
|
24
|
-
answers?: IQuestionDialogAnswer[];
|
|
25
|
-
questions?: IQuestionDialog[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const NPCDialog: React.FC<INPCDialogProps> = ({
|
|
29
|
-
text,
|
|
30
|
-
type,
|
|
31
|
-
onClose,
|
|
32
|
-
imagePath,
|
|
33
|
-
isQuestionDialog = false,
|
|
34
|
-
questions,
|
|
35
|
-
answers,
|
|
36
|
-
}) => {
|
|
37
|
-
const [showGoNextIndicator, setShowGoNextIndicator] = useState<boolean>(
|
|
38
|
-
false
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<RPGUIContainer
|
|
43
|
-
type={RPGUIContainerTypes.FramedGold}
|
|
44
|
-
width={isQuestionDialog ? '600px' : '50%'}
|
|
45
|
-
height={'180px'}
|
|
46
|
-
>
|
|
47
|
-
{isQuestionDialog && questions && answers ? (
|
|
48
|
-
<>
|
|
49
|
-
<TextContainer
|
|
50
|
-
flex={type === NPCDialogType.TextAndThumbnail ? '70%' : '100%'}
|
|
51
|
-
>
|
|
52
|
-
<QuestionDialog
|
|
53
|
-
questions={questions}
|
|
54
|
-
answers={answers}
|
|
55
|
-
onClose={() => {
|
|
56
|
-
if (onClose) {
|
|
57
|
-
onClose();
|
|
58
|
-
}
|
|
59
|
-
}}
|
|
60
|
-
/>
|
|
61
|
-
</TextContainer>
|
|
62
|
-
{type === NPCDialogType.TextAndThumbnail && (
|
|
63
|
-
<ThumbnailContainer>
|
|
64
|
-
<NPCThumbnail src={imagePath || aliceDefaultThumbnail} />
|
|
65
|
-
</ThumbnailContainer>
|
|
66
|
-
)}
|
|
67
|
-
</>
|
|
68
|
-
) : (
|
|
69
|
-
<>
|
|
70
|
-
<Container>
|
|
71
|
-
<TextContainer
|
|
72
|
-
flex={type === NPCDialogType.TextAndThumbnail ? '70%' : '100%'}
|
|
73
|
-
>
|
|
74
|
-
<NPCDialogText
|
|
75
|
-
onStartStep={() => setShowGoNextIndicator(false)}
|
|
76
|
-
onEndStep={() => setShowGoNextIndicator(true)}
|
|
77
|
-
text={text || 'No text provided.'}
|
|
78
|
-
onClose={() => {
|
|
79
|
-
if (onClose) {
|
|
80
|
-
onClose();
|
|
81
|
-
}
|
|
82
|
-
}}
|
|
83
|
-
/>
|
|
84
|
-
</TextContainer>
|
|
85
|
-
{type === NPCDialogType.TextAndThumbnail && (
|
|
86
|
-
<ThumbnailContainer>
|
|
87
|
-
<NPCThumbnail src={imagePath || aliceDefaultThumbnail} />
|
|
88
|
-
</ThumbnailContainer>
|
|
89
|
-
)}
|
|
90
|
-
</Container>
|
|
91
|
-
{showGoNextIndicator && (
|
|
92
|
-
<PressSpaceIndicator
|
|
93
|
-
right={type === NPCDialogType.TextOnly ? '1rem' : '10.5rem'}
|
|
94
|
-
src={pressSpaceGif}
|
|
95
|
-
/>
|
|
96
|
-
)}
|
|
97
|
-
</>
|
|
98
|
-
)}
|
|
99
|
-
</RPGUIContainer>
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const Container = styled.div`
|
|
104
|
-
display: flex;
|
|
105
|
-
width: 100%;
|
|
106
|
-
height: 100%;
|
|
107
|
-
|
|
108
|
-
box-sizing: border-box;
|
|
109
|
-
justify-content: center;
|
|
110
|
-
align-items: flex-start;
|
|
111
|
-
position: relative;
|
|
112
|
-
`;
|
|
113
|
-
|
|
114
|
-
interface ITextContainerProps {
|
|
115
|
-
flex: string;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const TextContainer = styled.div<ITextContainerProps>`
|
|
119
|
-
flex: ${({ flex }) => flex} 0 0;
|
|
120
|
-
width: 355px;
|
|
121
|
-
`;
|
|
122
|
-
|
|
123
|
-
const ThumbnailContainer = styled.div`
|
|
124
|
-
flex: 30% 0 0;
|
|
125
|
-
display: flex;
|
|
126
|
-
justify-content: flex-end;
|
|
127
|
-
`;
|
|
128
|
-
|
|
129
|
-
const NPCThumbnail = styled.img`
|
|
130
|
-
image-rendering: pixelated;
|
|
131
|
-
height: 128px;
|
|
132
|
-
width: 128px;
|
|
133
|
-
`;
|
|
134
|
-
|
|
135
|
-
interface IPressSpaceIndicatorProps {
|
|
136
|
-
right: string;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const PressSpaceIndicator = styled.img<IPressSpaceIndicatorProps>`
|
|
140
|
-
position: absolute;
|
|
141
|
-
right: ${({ right }) => right};
|
|
142
|
-
bottom: 1rem;
|
|
143
|
-
height: 20.7px;
|
|
144
|
-
image-rendering: -webkit-optimize-contrast;
|
|
145
|
-
`;
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { RPGUIContainer, RPGUIContainerTypes } from '../RPGUIContainer';
|
|
4
|
+
import aliceDefaultThumbnail from './img/npcDialog/npcThumbnails/alice.png';
|
|
5
|
+
import pressSpaceGif from './img/space.gif';
|
|
6
|
+
import { NPCDialogText } from './NPCDialogText';
|
|
7
|
+
import {
|
|
8
|
+
IQuestionDialog,
|
|
9
|
+
IQuestionDialogAnswer,
|
|
10
|
+
QuestionDialog,
|
|
11
|
+
} from './QuestionDialog/QuestionDialog';
|
|
12
|
+
|
|
13
|
+
export enum NPCDialogType {
|
|
14
|
+
TextOnly = 'TextOnly',
|
|
15
|
+
TextAndThumbnail = 'TextAndThumbnail',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface INPCDialogProps {
|
|
19
|
+
text?: string;
|
|
20
|
+
type: NPCDialogType;
|
|
21
|
+
imagePath?: string;
|
|
22
|
+
onClose?: () => void;
|
|
23
|
+
isQuestionDialog?: boolean;
|
|
24
|
+
answers?: IQuestionDialogAnswer[];
|
|
25
|
+
questions?: IQuestionDialog[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const NPCDialog: React.FC<INPCDialogProps> = ({
|
|
29
|
+
text,
|
|
30
|
+
type,
|
|
31
|
+
onClose,
|
|
32
|
+
imagePath,
|
|
33
|
+
isQuestionDialog = false,
|
|
34
|
+
questions,
|
|
35
|
+
answers,
|
|
36
|
+
}) => {
|
|
37
|
+
const [showGoNextIndicator, setShowGoNextIndicator] = useState<boolean>(
|
|
38
|
+
false
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<RPGUIContainer
|
|
43
|
+
type={RPGUIContainerTypes.FramedGold}
|
|
44
|
+
width={isQuestionDialog ? '600px' : '50%'}
|
|
45
|
+
height={'180px'}
|
|
46
|
+
>
|
|
47
|
+
{isQuestionDialog && questions && answers ? (
|
|
48
|
+
<>
|
|
49
|
+
<TextContainer
|
|
50
|
+
flex={type === NPCDialogType.TextAndThumbnail ? '70%' : '100%'}
|
|
51
|
+
>
|
|
52
|
+
<QuestionDialog
|
|
53
|
+
questions={questions}
|
|
54
|
+
answers={answers}
|
|
55
|
+
onClose={() => {
|
|
56
|
+
if (onClose) {
|
|
57
|
+
onClose();
|
|
58
|
+
}
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
</TextContainer>
|
|
62
|
+
{type === NPCDialogType.TextAndThumbnail && (
|
|
63
|
+
<ThumbnailContainer>
|
|
64
|
+
<NPCThumbnail src={imagePath || aliceDefaultThumbnail} />
|
|
65
|
+
</ThumbnailContainer>
|
|
66
|
+
)}
|
|
67
|
+
</>
|
|
68
|
+
) : (
|
|
69
|
+
<>
|
|
70
|
+
<Container>
|
|
71
|
+
<TextContainer
|
|
72
|
+
flex={type === NPCDialogType.TextAndThumbnail ? '70%' : '100%'}
|
|
73
|
+
>
|
|
74
|
+
<NPCDialogText
|
|
75
|
+
onStartStep={() => setShowGoNextIndicator(false)}
|
|
76
|
+
onEndStep={() => setShowGoNextIndicator(true)}
|
|
77
|
+
text={text || 'No text provided.'}
|
|
78
|
+
onClose={() => {
|
|
79
|
+
if (onClose) {
|
|
80
|
+
onClose();
|
|
81
|
+
}
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</TextContainer>
|
|
85
|
+
{type === NPCDialogType.TextAndThumbnail && (
|
|
86
|
+
<ThumbnailContainer>
|
|
87
|
+
<NPCThumbnail src={imagePath || aliceDefaultThumbnail} />
|
|
88
|
+
</ThumbnailContainer>
|
|
89
|
+
)}
|
|
90
|
+
</Container>
|
|
91
|
+
{showGoNextIndicator && (
|
|
92
|
+
<PressSpaceIndicator
|
|
93
|
+
right={type === NPCDialogType.TextOnly ? '1rem' : '10.5rem'}
|
|
94
|
+
src={pressSpaceGif}
|
|
95
|
+
/>
|
|
96
|
+
)}
|
|
97
|
+
</>
|
|
98
|
+
)}
|
|
99
|
+
</RPGUIContainer>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const Container = styled.div`
|
|
104
|
+
display: flex;
|
|
105
|
+
width: 100%;
|
|
106
|
+
height: 100%;
|
|
107
|
+
|
|
108
|
+
box-sizing: border-box;
|
|
109
|
+
justify-content: center;
|
|
110
|
+
align-items: flex-start;
|
|
111
|
+
position: relative;
|
|
112
|
+
`;
|
|
113
|
+
|
|
114
|
+
interface ITextContainerProps {
|
|
115
|
+
flex: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const TextContainer = styled.div<ITextContainerProps>`
|
|
119
|
+
flex: ${({ flex }) => flex} 0 0;
|
|
120
|
+
width: 355px;
|
|
121
|
+
`;
|
|
122
|
+
|
|
123
|
+
const ThumbnailContainer = styled.div`
|
|
124
|
+
flex: 30% 0 0;
|
|
125
|
+
display: flex;
|
|
126
|
+
justify-content: flex-end;
|
|
127
|
+
`;
|
|
128
|
+
|
|
129
|
+
const NPCThumbnail = styled.img`
|
|
130
|
+
image-rendering: pixelated;
|
|
131
|
+
height: 128px;
|
|
132
|
+
width: 128px;
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
interface IPressSpaceIndicatorProps {
|
|
136
|
+
right: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const PressSpaceIndicator = styled.img<IPressSpaceIndicatorProps>`
|
|
140
|
+
position: absolute;
|
|
141
|
+
right: ${({ right }) => right};
|
|
142
|
+
bottom: 1rem;
|
|
143
|
+
height: 20.7px;
|
|
144
|
+
image-rendering: -webkit-optimize-contrast;
|
|
145
|
+
`;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
import { chunkString } from '../../libs/StringHelpers';
|
|
4
|
-
import { DynamicText } from '../typography/DynamicText';
|
|
5
|
-
|
|
6
|
-
interface IProps {
|
|
7
|
-
text: string;
|
|
8
|
-
onClose: () => void;
|
|
9
|
-
onEndStep: () => void;
|
|
10
|
-
onStartStep: () => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const NPCDialogText: React.FC<IProps> = ({
|
|
14
|
-
text,
|
|
15
|
-
onClose,
|
|
16
|
-
onEndStep,
|
|
17
|
-
onStartStep,
|
|
18
|
-
}) => {
|
|
19
|
-
const textChunks = chunkString(text, 85);
|
|
20
|
-
|
|
21
|
-
const [chunkIndex, setChunkIndex] = useState<number>(0);
|
|
22
|
-
|
|
23
|
-
const onHandleSpacePress = (event: KeyboardEvent) => {
|
|
24
|
-
if (event.code === 'Space') {
|
|
25
|
-
const hasNextChunk = textChunks?.[chunkIndex + 1] || false;
|
|
26
|
-
|
|
27
|
-
if (hasNextChunk) {
|
|
28
|
-
setChunkIndex(prev => prev + 1);
|
|
29
|
-
} else {
|
|
30
|
-
// if there's no more text chunks, close the dialog
|
|
31
|
-
onClose();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
document.addEventListener('keydown', onHandleSpacePress);
|
|
38
|
-
|
|
39
|
-
return () => document.removeEventListener('keydown', onHandleSpacePress);
|
|
40
|
-
}, [chunkIndex]);
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<Container>
|
|
44
|
-
<DynamicText
|
|
45
|
-
text={textChunks?.[chunkIndex] || ''}
|
|
46
|
-
onFinish={onEndStep}
|
|
47
|
-
onStart={onStartStep}
|
|
48
|
-
/>
|
|
49
|
-
</Container>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const Container = styled.div``;
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { chunkString } from '../../libs/StringHelpers';
|
|
4
|
+
import { DynamicText } from '../typography/DynamicText';
|
|
5
|
+
|
|
6
|
+
interface IProps {
|
|
7
|
+
text: string;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
onEndStep: () => void;
|
|
10
|
+
onStartStep: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const NPCDialogText: React.FC<IProps> = ({
|
|
14
|
+
text,
|
|
15
|
+
onClose,
|
|
16
|
+
onEndStep,
|
|
17
|
+
onStartStep,
|
|
18
|
+
}) => {
|
|
19
|
+
const textChunks = chunkString(text, 85);
|
|
20
|
+
|
|
21
|
+
const [chunkIndex, setChunkIndex] = useState<number>(0);
|
|
22
|
+
|
|
23
|
+
const onHandleSpacePress = (event: KeyboardEvent) => {
|
|
24
|
+
if (event.code === 'Space') {
|
|
25
|
+
const hasNextChunk = textChunks?.[chunkIndex + 1] || false;
|
|
26
|
+
|
|
27
|
+
if (hasNextChunk) {
|
|
28
|
+
setChunkIndex(prev => prev + 1);
|
|
29
|
+
} else {
|
|
30
|
+
// if there's no more text chunks, close the dialog
|
|
31
|
+
onClose();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
document.addEventListener('keydown', onHandleSpacePress);
|
|
38
|
+
|
|
39
|
+
return () => document.removeEventListener('keydown', onHandleSpacePress);
|
|
40
|
+
}, [chunkIndex]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Container>
|
|
44
|
+
<DynamicText
|
|
45
|
+
text={textChunks?.[chunkIndex] || ''}
|
|
46
|
+
onFinish={onEndStep}
|
|
47
|
+
onStart={onStartStep}
|
|
48
|
+
/>
|
|
49
|
+
</Container>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const Container = styled.div``;
|