@rpg-engine/long-bow 0.2.3 → 0.2.6

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,4 @@
1
+ import { Meta } from '@storybook/react';
2
+ declare const meta: Meta;
3
+ export default meta;
4
+ export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.2.3",
3
+ "version": "0.2.6",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@rollup/plugin-image": "^2.1.1",
86
- "@rpg-engine/shared": "^0.4.22",
86
+ "@rpg-engine/shared": "^0.4.31",
87
87
  "dayjs": "^1.11.2",
88
88
  "fs-extra": "^10.1.0",
89
89
  "lodash": "^4.17.21",
@@ -0,0 +1,94 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import { SpriteFromAtlas } from '../shared/SpriteFromAtlas';
5
+
6
+ import entitiesJSON from '../../mocks/atlas/entities/entities.json';
7
+ import entitiesIMG from '../../mocks/atlas/entities/entities.png';
8
+ import PropertySelect, {
9
+ IPropertiesProps,
10
+ } from '../PropertySelect/PropertySelect';
11
+
12
+ export interface ICharacterProps {
13
+ id: string;
14
+ name: string;
15
+ spriteKey: string;
16
+ }
17
+
18
+ export interface ICharacterSelectionProps {
19
+ availableCharacters: ICharacterProps[];
20
+ onChange: (characterSpriteKey: string) => void;
21
+ }
22
+
23
+ export const CharacterSelection: React.FC<ICharacterSelectionProps> = ({
24
+ availableCharacters,
25
+ onChange,
26
+ }) => {
27
+ const getPropertySelectValues = () => {
28
+ return availableCharacters.map(item => {
29
+ return {
30
+ id: item.id,
31
+ name: item.name,
32
+ };
33
+ });
34
+ };
35
+
36
+ const [propertySelectValues] = useState<IPropertiesProps[]>(
37
+ getPropertySelectValues()
38
+ );
39
+
40
+ const [selectedSpriteKey, setSelectedSpriteKey] = useState('');
41
+ const [selectedValue, setSelectedValue] = useState<IPropertiesProps>(
42
+ propertySelectValues[0]
43
+ );
44
+
45
+ const getSelectedCharacterSpriteKey = () => {
46
+ const character = availableCharacters.filter(
47
+ item => item.id === selectedValue.id
48
+ )[0];
49
+ return character ? character.spriteKey : '';
50
+ };
51
+
52
+ const onSelectedValueChange = () => {
53
+ const spriteKey = getSelectedCharacterSpriteKey();
54
+ setSelectedSpriteKey(spriteKey);
55
+ onChange(spriteKey);
56
+ };
57
+
58
+ useEffect(() => {
59
+ onSelectedValueChange();
60
+ }, [selectedValue]);
61
+
62
+ return (
63
+ <Container>
64
+ {selectedSpriteKey && (
65
+ <SpriteFromAtlas
66
+ spriteKey={selectedSpriteKey}
67
+ atlasIMG={entitiesIMG}
68
+ atlasJSON={entitiesJSON}
69
+ imgScale={4}
70
+ height={50}
71
+ width={50}
72
+ containerStyle={{
73
+ padding: '25px 10px 5px 28px',
74
+ }}
75
+ />
76
+ )}
77
+ <PropertySelect
78
+ availableProperties={propertySelectValues}
79
+ onChange={value => {
80
+ setSelectedValue(value);
81
+ }}
82
+ />
83
+ </Container>
84
+ );
85
+ };
86
+
87
+ const Container = styled.div`
88
+ display: flex;
89
+ flex-direction: column;
90
+ align-items: center;
91
+ image-rendering: pixelated;
92
+ `;
93
+
94
+ export default CharacterSelection;
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import LeftArrowClickIcon from './img/ui-arrows/arrow01-left-clicked.png';
4
4
  import LeftArrowIcon from './img/ui-arrows/arrow01-left.png';
@@ -7,8 +7,9 @@ import RightArrowIcon from './img/ui-arrows/arrow01-right.png';
7
7
 
8
8
  export interface IPropertySelectProps {
9
9
  availableProperties: Array<IPropertiesProps>;
10
- selectedProperty: object;
10
+ selectedProperty?: IPropertiesProps;
11
11
  children?: React.ReactNode;
12
+ onChange: (selectedProperty: IPropertiesProps) => void;
12
13
  }
13
14
 
14
15
  export interface IPropertiesProps {
@@ -18,6 +19,7 @@ export interface IPropertiesProps {
18
19
 
19
20
  export const PropertySelect: React.FC<IPropertySelectProps> = ({
20
21
  availableProperties,
22
+ onChange,
21
23
  }) => {
22
24
  const [currentIndex, setCurrentIndex] = useState(0);
23
25
  const propertiesLength = availableProperties.length - 1;
@@ -30,6 +32,11 @@ export const PropertySelect: React.FC<IPropertySelectProps> = ({
30
32
  if (currentIndex === propertiesLength) setCurrentIndex(0);
31
33
  else setCurrentIndex(index => index + 1);
32
34
  };
35
+
36
+ useEffect(() => {
37
+ onChange(availableProperties[currentIndex]);
38
+ }, [currentIndex]);
39
+
33
40
  return (
34
41
  <Container>
35
42
  <TextOverlay>
package/src/index.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './components/Button';
2
+ export * from './components/Character/CharacterSelection';
2
3
  export * from './components/Chat/Chat';
3
4
  export * from './components/CheckButton';
4
5
  export * from './components/DraggableContainer';
@@ -12,6 +13,7 @@ export * from './components/NPCDialog/NPCDialog';
12
13
  export * from './components/NPCDialog/QuestionDialog/QuestionDialog';
13
14
  export * from './components/ProgressBar';
14
15
  export * from './components/PropertySelect/PropertySelect';
16
+ export * from './components/QuestInfo/QuestInfo';
15
17
  export * from './components/RadioButton';
16
18
  export * from './components/RangeSlider';
17
19
  export * from './components/RPGUIContainer';