@rpg-engine/long-bow 0.2.99 → 0.3.23

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.
@@ -0,0 +1,5 @@
1
+ import { IChatMessage } from '@rpg-engine/shared';
2
+ import { Meta } from '@storybook/react';
3
+ declare const meta: Meta;
4
+ export default meta;
5
+ export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, IChatMessage>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.2.99",
3
+ "version": "0.3.23",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -85,6 +85,7 @@
85
85
  "@rollup/plugin-image": "^2.1.1",
86
86
  "@rpg-engine/shared": "^0.6.57",
87
87
  "dayjs": "^1.11.2",
88
+ "font-awesome": "^4.7.0",
88
89
  "fs-extra": "^10.1.0",
89
90
  "is-mobile": "^3.1.1",
90
91
  "lodash": "^4.17.21",
@@ -93,6 +94,7 @@
93
94
  "mobx-react": "^7.5.0",
94
95
  "react-draggable": "^4.4.5",
95
96
  "react-error-boundary": "^3.1.4",
97
+ "react-icons": "^4.7.1",
96
98
  "rollup-plugin-image-files": "^1.4.2",
97
99
  "rpgui": "^1.0.3"
98
100
  }
package/src/.DS_Store ADDED
Binary file
@@ -2,18 +2,15 @@ import { IChatMessage } from '@rpg-engine/shared';
2
2
  import dayjs from 'dayjs';
3
3
  import React, { useEffect, useState } from 'react';
4
4
  import { ErrorBoundary } from 'react-error-boundary';
5
+ import { CiPaperplane } from 'react-icons/ci';
5
6
  import styled from 'styled-components';
6
- import { uiColors } from '../../constants/uiColors';
7
- import { uiFonts } from '../../constants/uiFonts';
8
- import { Button, ButtonTypes } from '../Button';
9
- import { Input } from '../Input';
10
- import { RPGUIContainer, RPGUIContainerTypes } from '../RPGUIContainer';
11
7
  import { Column } from '../shared/Column';
12
8
 
13
9
  interface IEmitter {
14
10
  _id: string;
15
11
  name: string;
16
12
  }
13
+
17
14
  export interface IChatProps {
18
15
  chatMessages: IChatMessage[];
19
16
  onSendChatMessage: (message: string) => void;
@@ -23,17 +20,22 @@ export interface IChatProps {
23
20
  opacity?: number;
24
21
  width?: string;
25
22
  height?: string;
23
+ sendMessage: boolean;
24
+ color?: string;
25
+ buttonColor?: string;
26
+ buttonBackgroundColor?: string;
26
27
  }
27
28
 
28
29
  export const Chat: React.FC<IChatProps> = ({
29
30
  chatMessages,
30
31
  onSendChatMessage,
31
- opacity = 1,
32
- width = '100%',
32
+ width = '80%',
33
33
  height = '250px',
34
- onCloseButton,
35
34
  onFocus,
36
35
  onBlur,
36
+ color = '#c65102',
37
+ buttonColor = '#005b96',
38
+ buttonBackgroundColor = '#FFF',
37
39
  }) => {
38
40
  const [message, setMessage] = useState('');
39
41
 
@@ -74,114 +76,90 @@ export const Chat: React.FC<IChatProps> = ({
74
76
  const onRenderChatMessages = (chatMessages: IChatMessage[]) => {
75
77
  return chatMessages?.length ? (
76
78
  chatMessages?.map(({ _id, createdAt, emitter, message }, index) => (
77
- <MessageText key={`${_id}_${index}`}>
79
+ <Message color={color} key={`${_id}_${index}`}>
78
80
  {onRenderMessageLines(emitter, createdAt, message)}
79
- </MessageText>
81
+ </Message>
80
82
  ))
81
83
  ) : (
82
- <MessageText>No messages available.</MessageText>
84
+ <Message color={color}>No messages available.</Message>
83
85
  );
84
86
  };
85
87
 
86
88
  return (
87
- <Container>
88
- <CustomContainer
89
- type={RPGUIContainerTypes.FramedGrey}
90
- width={width}
91
- height={height}
92
- className="chat-container"
93
- opacity={opacity}
94
- >
95
- <ErrorBoundary fallback={<p>Oops! Your chat has crashed.</p>}>
96
- {onCloseButton && (
97
- <CloseButton onClick={onCloseButton} onTouchStart={onCloseButton}>
98
- X
99
- </CloseButton>
100
- )}
101
- <RPGUIContainer
102
- type={RPGUIContainerTypes.FramedGrey}
103
- width={'100%'}
104
- height={'80%'}
105
- className="chat-body dark-background"
106
- >
107
- {onRenderChatMessages(chatMessages)}
108
- </RPGUIContainer>
109
-
110
- <Form onSubmit={handleSubmit}>
111
- <Column flex={70}>
112
- <CustomInput
113
- value={message}
114
- id="inputMessage"
115
- onChange={e => getInputValue(e.target.value)}
116
- height={20}
117
- className="chat-input dark-background"
118
- type="text"
119
- autoComplete="off"
120
- onFocus={onFocus}
121
- onBlur={onBlur}
122
- />
123
- </Column>
124
- <Column justifyContent="flex-end">
125
- <Button
126
- buttonType={ButtonTypes.RPGUIButton}
127
- id="chat-send-button"
128
- >
129
- Send
130
- </Button>
131
- </Column>
132
- </Form>
133
- </ErrorBoundary>
134
- </CustomContainer>
135
- </Container>
89
+ <ChatContainer width={width} height={height}>
90
+ <ErrorBoundary fallback={<p>Oops! Your chat has crashed.</p>}>
91
+ <MessagesContainer>
92
+ {onRenderChatMessages(chatMessages)}
93
+ </MessagesContainer>
94
+
95
+ <Form onSubmit={handleSubmit}>
96
+ <Column flex={70}>
97
+ <TextField
98
+ value={message}
99
+ id="inputMessage"
100
+ onChange={e => getInputValue(e.target.value)}
101
+ height={20}
102
+ className="chat-input dark-background"
103
+ type="text"
104
+ autoComplete="off"
105
+ onFocus={onFocus}
106
+ onBlur={onBlur}
107
+ />
108
+ </Column>
109
+ <Column justifyContent="flex-end">
110
+ <Button
111
+ buttonColor={buttonColor}
112
+ buttonBackgroundColor={buttonBackgroundColor}
113
+ id="chat-send-button"
114
+ style={{ borderRadius: '20%' }}
115
+ >
116
+ <CiPaperplane size={20} />
117
+ </Button>
118
+ </Column>
119
+ </Form>
120
+ </ErrorBoundary>
121
+ </ChatContainer>
136
122
  );
137
123
  };
138
124
 
139
- const Container = styled.div`
140
- position: relative;
141
- `;
142
-
143
- const CloseButton = styled.div`
144
- position: absolute;
145
- top: 2px;
146
- right: 0px;
147
- color: white;
148
- z-index: 22;
149
- font-size: 0.7rem;
150
- `;
151
-
152
- const CustomInput = styled(Input)`
153
- height: 30px;
154
- width: 100%;
155
-
156
- .rpgui-content .input {
157
- min-height: 39px;
158
- }
159
- `;
125
+ interface IContainerProps {
126
+ width: string;
127
+ height: string;
128
+ }
160
129
 
161
- interface ICustomContainerProps {
162
- opacity: number;
130
+ interface IMessageProps {
131
+ color: string;
163
132
  }
164
133
 
165
- const CustomContainer = styled(RPGUIContainer)`
166
- display: block;
134
+ interface IButtonProps {
135
+ buttonColor: string;
136
+ buttonBackgroundColor: string;
137
+ }
167
138
 
168
- opacity: ${(props: ICustomContainerProps) => props.opacity};
139
+ const ChatContainer = styled.div<IContainerProps>`
140
+ height: ${props => props.height};
141
+ width: ${({ width }) => width};
142
+ border-radius: 10px;
143
+ padding: 40px 30px;
144
+ margin-top: 100px;
145
+ box-shadow: -3px -3px 9px #aaa9a9a2, 3px 3px 7px rgba(147, 149, 151, 0.671);
146
+ `;
169
147
 
170
- &:hover {
171
- opacity: 1;
172
- }
148
+ const TextField = styled.input`
149
+ width: 100%;
150
+ border-radius: 10px;
151
+ box-shadow: -3px -3px 9px #aaa9a9a2, 3px 3px 7px rgba(147, 149, 151, 0.671);
152
+ `;
173
153
 
174
- .dark-background {
175
- background-color: ${uiColors.darkGray} !important;
176
- }
154
+ const MessagesContainer = styled.div`
155
+ overflow: hidden;
156
+ height: 70%;
157
+ margin-bottom: 20px;
158
+ `;
177
159
 
178
- .chat-body {
179
- &.rpgui-container.framed-grey {
180
- background: unset;
181
- }
182
- max-height: 170px;
183
- overflow-y: auto;
184
- }
160
+ const Message = styled.div<IMessageProps>`
161
+ margin-bottom: 8px;
162
+ color: ${({ color }) => color};
185
163
  `;
186
164
 
187
165
  const Form = styled.form`
@@ -191,10 +169,9 @@ const Form = styled.form`
191
169
  align-items: center;
192
170
  `;
193
171
 
194
- const MessageText = styled.p`
195
- display: block !important;
196
- width: 100%;
197
- font-size: ${uiFonts.size.xsmall} !important;
198
- overflow-y: auto;
199
- margin: 0;
172
+ const Button = styled.button<IButtonProps>`
173
+ color: ${({ buttonColor }) => buttonColor};
174
+ background-color: ${({ buttonBackgroundColor }) => buttonBackgroundColor};
175
+ width: 50px;
176
+ height: 40px;
200
177
  `;
@@ -0,0 +1,200 @@
1
+ import { IChatMessage } from '@rpg-engine/shared';
2
+ import dayjs from 'dayjs';
3
+ import React, { useEffect, useState } from 'react';
4
+ import { ErrorBoundary } from 'react-error-boundary';
5
+ import styled from 'styled-components';
6
+ import { uiColors } from '../../constants/uiColors';
7
+ import { uiFonts } from '../../constants/uiFonts';
8
+ import { Button, ButtonTypes } from '../Button';
9
+ import { Input } from '../Input';
10
+ import { RPGUIContainer, RPGUIContainerTypes } from '../RPGUIContainer';
11
+ import { Column } from '../shared/Column';
12
+
13
+ interface IEmitter {
14
+ _id: string;
15
+ name: string;
16
+ }
17
+ export interface IChatDeprecatedProps {
18
+ chatMessages: IChatMessage[];
19
+ onSendChatMessage: (message: string) => void;
20
+ onCloseButton: () => void;
21
+ onFocus?: () => void;
22
+ onBlur?: () => void;
23
+ opacity?: number;
24
+ width?: string;
25
+ height?: string;
26
+ }
27
+
28
+ export const ChatDeprecated: React.FC<IChatDeprecatedProps> = ({
29
+ chatMessages,
30
+ onSendChatMessage,
31
+ opacity = 1,
32
+ width = '100%',
33
+ height = '250px',
34
+ onCloseButton,
35
+ onFocus,
36
+ onBlur,
37
+ }) => {
38
+ const [message, setMessage] = useState('');
39
+
40
+ useEffect(() => {
41
+ scrollChatToBottom();
42
+ }, []);
43
+
44
+ useEffect(() => {
45
+ scrollChatToBottom();
46
+ }, [chatMessages]);
47
+
48
+ const scrollChatToBottom = () => {
49
+ const scrollingElement = document.querySelector('.chat-body');
50
+ if (scrollingElement) {
51
+ scrollingElement.scrollTop = scrollingElement.scrollHeight;
52
+ }
53
+ };
54
+
55
+ const handleSubmit = (event: React.SyntheticEvent<HTMLFormElement>) => {
56
+ event.preventDefault();
57
+ onSendChatMessage(message);
58
+ setMessage('');
59
+ };
60
+ const getInputValue = (value: string) => {
61
+ setMessage(value);
62
+ };
63
+
64
+ const onRenderMessageLines = (
65
+ emitter: IEmitter,
66
+ createdAt: string | undefined,
67
+ message: string
68
+ ) => {
69
+ return `${dayjs(createdAt || new Date()).format('HH:mm')} ${
70
+ emitter?.name ? `${emitter.name}: ` : 'Unknown: '
71
+ } ${message}`;
72
+ };
73
+
74
+ const onRenderChatMessages = (chatMessages: IChatMessage[]) => {
75
+ return chatMessages?.length ? (
76
+ chatMessages?.map(({ _id, createdAt, emitter, message }, index) => (
77
+ <MessageText key={`${_id}_${index}`}>
78
+ {onRenderMessageLines(emitter, createdAt, message)}
79
+ </MessageText>
80
+ ))
81
+ ) : (
82
+ <MessageText>No messages available.</MessageText>
83
+ );
84
+ };
85
+
86
+ return (
87
+ <Container>
88
+ <CustomContainer
89
+ type={RPGUIContainerTypes.FramedGrey}
90
+ width={width}
91
+ height={height}
92
+ className="chat-container"
93
+ opacity={opacity}
94
+ >
95
+ <ErrorBoundary fallback={<p>Oops! Your chat has crashed.</p>}>
96
+ {onCloseButton && (
97
+ <CloseButton onClick={onCloseButton} onTouchStart={onCloseButton}>
98
+ X
99
+ </CloseButton>
100
+ )}
101
+ <RPGUIContainer
102
+ type={RPGUIContainerTypes.FramedGrey}
103
+ width={'100%'}
104
+ height={'80%'}
105
+ className="chat-body dark-background"
106
+ >
107
+ {onRenderChatMessages(chatMessages)}
108
+ </RPGUIContainer>
109
+
110
+ <Form onSubmit={handleSubmit}>
111
+ <Column flex={70}>
112
+ <CustomInput
113
+ value={message}
114
+ id="inputMessage"
115
+ onChange={e => getInputValue(e.target.value)}
116
+ height={20}
117
+ className="chat-input dark-background"
118
+ type="text"
119
+ autoComplete="off"
120
+ onFocus={onFocus}
121
+ onBlur={onBlur}
122
+ />
123
+ </Column>
124
+ <Column justifyContent="flex-end">
125
+ <Button
126
+ buttonType={ButtonTypes.RPGUIButton}
127
+ id="chat-send-button"
128
+ >
129
+ Send
130
+ </Button>
131
+ </Column>
132
+ </Form>
133
+ </ErrorBoundary>
134
+ </CustomContainer>
135
+ </Container>
136
+ );
137
+ };
138
+
139
+ const Container = styled.div`
140
+ position: relative;
141
+ `;
142
+
143
+ const CloseButton = styled.div`
144
+ position: absolute;
145
+ top: 2px;
146
+ right: 0px;
147
+ color: white;
148
+ z-index: 22;
149
+ font-size: 0.7rem;
150
+ `;
151
+
152
+ const CustomInput = styled(Input)`
153
+ height: 30px;
154
+ width: 100%;
155
+
156
+ .rpgui-content .input {
157
+ min-height: 39px;
158
+ }
159
+ `;
160
+
161
+ interface ICustomContainerProps {
162
+ opacity: number;
163
+ }
164
+
165
+ const CustomContainer = styled(RPGUIContainer)`
166
+ display: block;
167
+
168
+ opacity: ${(props: ICustomContainerProps) => props.opacity};
169
+
170
+ &:hover {
171
+ opacity: 1;
172
+ }
173
+
174
+ .dark-background {
175
+ background-color: ${uiColors.darkGray} !important;
176
+ }
177
+
178
+ .chat-body {
179
+ &.rpgui-container.framed-grey {
180
+ background: unset;
181
+ }
182
+ max-height: 170px;
183
+ overflow-y: auto;
184
+ }
185
+ `;
186
+
187
+ const Form = styled.form`
188
+ display: flex;
189
+ width: 100%;
190
+ justify-content: center;
191
+ align-items: center;
192
+ `;
193
+
194
+ const MessageText = styled.p`
195
+ display: block !important;
196
+ width: 100%;
197
+ font-size: ${uiFonts.size.xsmall} !important;
198
+ overflow-y: auto;
199
+ margin: 0;
200
+ `;
@@ -40,7 +40,7 @@ export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
40
40
  const options: IOptionsProps[] = [];
41
41
 
42
42
  Object.keys(ItemSubType).forEach(key => {
43
- if (key === 'CraftingResource') {
43
+ if (key === 'CraftingResource' || key === 'DeadBody') {
44
44
  return; // we can't craft crafting resouces...
45
45
  }
46
46
 
package/src/index.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './components/Button';
2
2
  export * from './components/Character/CharacterSelection';
3
3
  export * from './components/Chat/Chat';
4
+ export * from './components/Chatdeprecated/ChatDeprecated';
4
5
  export * from './components/CheckButton';
5
6
  export * from './components/CraftBook/CraftBook';
6
7
  export * from './components/DraggableContainer';
@@ -12,6 +13,7 @@ export * from './components/Input';
12
13
  export { ErrorBoundary } from './components/Item/Inventory/ErrorBoundary';
13
14
  export * from './components/Item/Inventory/ItemContainer';
14
15
  export * from './components/Item/Inventory/ItemSlot';
16
+ export * from './components/itemSelector/ItemSelector';
15
17
  export * from './components/ListMenu';
16
18
  export * from './components/NPCDialog/NPCDialog';
17
19
  export * from './components/NPCDialog/NPCMultiDialog';
@@ -20,17 +22,16 @@ export * from './components/ProgressBar';
20
22
  export * from './components/PropertySelect/PropertySelect';
21
23
  export * from './components/QuestInfo/QuestInfo';
22
24
  export * from './components/QuestList';
23
- export * from './components/RPGUIContainer';
24
- export * from './components/RPGUIRoot';
25
25
  export * from './components/RadioButton';
26
26
  export * from './components/RangeSlider';
27
+ export * from './components/RPGUIContainer';
28
+ export * from './components/RPGUIRoot';
29
+ export * from './components/shared/SpriteFromAtlas';
27
30
  export * from './components/SkillProgressBar';
28
31
  export * from './components/SkillsContainer';
29
32
  export * from './components/TextArea';
30
33
  export * from './components/TimeWidget/TimeWidget';
31
34
  export * from './components/TradingMenu/TradingMenu';
32
35
  export * from './components/Truncate';
33
- export * from './components/itemSelector/ItemSelector';
34
- export * from './components/shared/SpriteFromAtlas';
35
36
  export * from './components/typography/DynamicText';
36
37
  export { useEventListener } from './hooks/useEventListener';
Binary file
Binary file
@@ -1,8 +1,8 @@
1
1
  import { ChatMessageType, IChatMessage } from '@rpg-engine/shared';
2
2
  import { Meta, Story } from '@storybook/react';
3
3
  import React from 'react';
4
- import { Chat } from '../../src/components/Chat/Chat';
5
- import { RPGUIRoot } from '../../src/components/RPGUIRoot';
4
+ import { Chat } from '../components/Chat/Chat';
5
+ import { RPGUIRoot } from '../components/RPGUIRoot';
6
6
 
7
7
  const meta: Meta = {
8
8
  title: 'Chat',
@@ -152,6 +152,20 @@ const chatMessagesMock = [
152
152
  createdAt: '2020-08-20T16:00:00.000Z',
153
153
  updatedAt: '2020-08-20T16:00:00.000Z',
154
154
  },
155
+ {
156
+ _id: 'test-id-9',
157
+ message: '22222EEECT!',
158
+ emitter: {
159
+ _id: 'someid',
160
+ name: 'Guilherme',
161
+ },
162
+ type: ChatMessageType.Global,
163
+ x: 128,
164
+ y: 128,
165
+ scene: 'MainScene',
166
+ createdAt: '2020-08-20T16:00:00.000Z',
167
+ updatedAt: '2020-08-20T16:00:00.000Z',
168
+ },
155
169
  ];
156
170
 
157
171
  const Template: Story<IChatMessage> = args => (
@@ -162,6 +176,7 @@ const Template: Story<IChatMessage> = args => (
162
176
  opacity={0.5}
163
177
  height={'200px'}
164
178
  onCloseButton={() => console.log('closing chat...')}
179
+ sendMessage={true}
165
180
  {...args}
166
181
  />
167
182
  </RPGUIRoot>