@rpg-engine/long-bow 0.2.8 → 0.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { IQuest } from '@rpg-engine/shared';
2
- import React, { useState } from 'react';
2
+ import React, { useEffect, useState } from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { Button, ButtonTypes } from '../Button';
5
5
  import { DraggableContainer } from '../DraggableContainer';
@@ -11,26 +11,34 @@ import { RPGUIContainerTypes } from '../RPGUIContainer';
11
11
  import { Column } from '../shared/Column';
12
12
  import thumbnailDefault from './img/default.png';
13
13
 
14
- export interface IQuestInfoProps {
15
- onClose?: () => void;
16
- button?: Array<IQuestsButtonProps>;
17
- quests: IQuest[];
18
- }
19
-
20
14
  export interface IQuestsButtonProps {
21
15
  disabled: boolean;
22
16
  title: string;
23
- onClick: (QuestId: string, NPCId: string) => void;
17
+ onClick: (questId: string, npcId: string) => void;
18
+ }
19
+
20
+ export interface IQuestInfoProps {
21
+ onClose?: () => void;
22
+ buttons?: IQuestsButtonProps[];
23
+ quests: IQuest[];
24
+ onChangeQuest: (currentQuestIndex: number, currentQuestId: string) => void;
24
25
  }
25
26
 
26
27
  export const QuestInfo: React.FC<IQuestInfoProps> = ({
27
28
  quests,
28
29
  onClose,
29
- button,
30
+ buttons,
31
+ onChangeQuest,
30
32
  }) => {
31
33
  const [currentIndex, setCurrentIndex] = useState(0);
32
34
  const questsLength = quests.length - 1;
33
35
 
36
+ useEffect(() => {
37
+ if (onChangeQuest) {
38
+ onChangeQuest(currentIndex, quests[currentIndex]._id);
39
+ }
40
+ }, [currentIndex]);
41
+
34
42
  const onLeftClick = () => {
35
43
  if (currentIndex === 0) setCurrentIndex(questsLength);
36
44
  else setCurrentIndex(index => index - 1);
@@ -72,21 +80,21 @@ export const QuestInfo: React.FC<IQuestInfoProps> = ({
72
80
  <p>{quests[currentIndex].description}</p>
73
81
  </Content>
74
82
  <QuestColumn className="dark-background" justifyContent="flex-end">
75
- {button &&
76
- button.map((item, index) => (
83
+ {buttons &&
84
+ buttons.map((button, index) => (
77
85
  <Button
78
86
  key={index}
79
87
  onClick={() =>
80
- item.onClick(
88
+ button.onClick(
81
89
  quests[currentIndex]._id,
82
90
  quests[currentIndex].npcId
83
91
  )
84
92
  }
85
- disabled={item.disabled}
93
+ disabled={button.disabled}
86
94
  buttonType={ButtonTypes.RPGUIButton}
87
95
  id={`button-${index}`}
88
96
  >
89
- {item.title}
97
+ {button.title}
90
98
  </Button>
91
99
  ))}
92
100
  </QuestColumn>
@@ -108,16 +116,18 @@ export const QuestInfo: React.FC<IQuestInfoProps> = ({
108
116
  <p>{quests[0].description}</p>
109
117
  </Content>
110
118
  <QuestColumn className="dark-background" justifyContent="flex-end">
111
- {button &&
112
- button.map((item, index) => (
119
+ {buttons &&
120
+ buttons.map((button, index) => (
113
121
  <Button
114
122
  key={index}
115
- onClick={() => item.onClick(quests[0]._id, quests[0].npcId)}
116
- disabled={item.disabled}
123
+ onClick={() =>
124
+ button.onClick(quests[0]._id, quests[0].npcId)
125
+ }
126
+ disabled={button.disabled}
117
127
  buttonType={ButtonTypes.RPGUIButton}
118
128
  id={`button-${index}`}
119
129
  >
120
- {item.title}
130
+ {button.title}
121
131
  </Button>
122
132
  ))}
123
133
  </QuestColumn>
@@ -100,6 +100,8 @@ const IQuestMock = [
100
100
 
101
101
  Default.args = {
102
102
  onClose: () => console.log('closing'),
103
- button: buttonMock,
103
+ buttons: buttonMock,
104
104
  quests: IQuestMock,
105
+ onChangeQuest: (index: number, questId: string) =>
106
+ console.log(index, questId),
105
107
  };