@rpg-engine/long-bow 0.5.7 → 0.5.8

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 { TopCharacterEntry, TopSkillEntry } from '@rpg-engine/shared';
2
+ export declare const leaderboardLevelRankingItems: Set<TopCharacterEntry>;
3
+ export declare const leaderboardClassRankingItems: Set<TopCharacterEntry>;
4
+ export declare const leaderboardSkillRankingItems: Set<TopSkillEntry>;
@@ -0,0 +1,7 @@
1
+ import { Meta } from '@storybook/react';
2
+ import { ILeaderboardProps } from '../components/Leaderboard/Leaderboard';
3
+ declare const meta: Meta;
4
+ export default meta;
5
+ export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, ILeaderboardProps>;
6
+ export declare const ClassRanking: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, ILeaderboardProps>;
7
+ export declare const SkillRanking: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, ILeaderboardProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
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.8.69",
86
+ "@rpg-engine/shared": "^0.8.72",
87
87
  "dayjs": "^1.11.2",
88
88
  "font-awesome": "^4.7.0",
89
89
  "fs-extra": "^10.1.0",
@@ -0,0 +1,111 @@
1
+ import { CharacterClass, TopCharacterEntry, TopSkillEntry } from '@rpg-engine/shared';
2
+ import React, { useEffect, useRef } from 'react';
3
+ import styled from 'styled-components';
4
+ import { Dropdown, IOptionsProps } from '../Dropdown';
5
+ import { LeaderboardTable } from './LeaderboardTable';
6
+
7
+
8
+ export interface ILeaderboardProps {
9
+ items: Set<TopCharacterEntry> | Set<TopSkillEntry> | null;
10
+ onChangeClassType: (value: string) => void;
11
+ onChangeRankType: (value: string) => void;
12
+ onChangeSkillType: (value: string) => void;
13
+ skills: string[];
14
+ rankType: string;
15
+ }
16
+
17
+ const rankTypeOptions: IOptionsProps[] = ['Level', 'Class', 'Skill'].map(
18
+ (itemType, index) => ({
19
+ id: index + 1,
20
+ value: itemType,
21
+ option: itemType,
22
+ })
23
+ );
24
+
25
+ const classTypeOptions: IOptionsProps[] = Object.keys(CharacterClass).map((itemType, index) => ({
26
+ id: index + 1,
27
+ value: itemType,
28
+ option: itemType,
29
+ }));
30
+
31
+ export const Leaderboard = (props: ILeaderboardProps) => {
32
+ const { items, onChangeRankType, onChangeClassType, rankType, skills, onChangeSkillType } = props;
33
+ const itemsContainer = useRef<HTMLDivElement>(null);
34
+
35
+ useEffect(() => {
36
+ itemsContainer.current?.scrollTo(0, 0);
37
+ }, []);
38
+
39
+ const skillTypeOptions: IOptionsProps[] = skills.map((itemType, index) => ({
40
+ id: index + 1,
41
+ value: itemType,
42
+ option: itemType,
43
+ }));
44
+
45
+ return (
46
+ <>
47
+ <WrapperContainer>
48
+ <StyledDropdown
49
+ options={rankTypeOptions}
50
+ onChange={onChangeRankType}
51
+ width="80%"
52
+ />
53
+ {rankType === 'Class' ? (
54
+ <StyledDropdown
55
+ options={classTypeOptions}
56
+ onChange={onChangeClassType}
57
+ width="100%"
58
+ />
59
+ ) : null}
60
+ {rankType === 'Skill' ? (
61
+ <StyledDropdown
62
+ options={skillTypeOptions}
63
+ onChange={onChangeSkillType}
64
+ width="100%"
65
+ />
66
+ ) : null}
67
+ </WrapperContainer>
68
+ <ItemComponentScrollWrapper
69
+ id="LeaderboardContainer"
70
+ ref={itemsContainer}
71
+ >
72
+ <TableWrapper>
73
+ <LeaderboardTable items={items} rankType={rankType} />
74
+ </TableWrapper>
75
+ </ItemComponentScrollWrapper>
76
+ </>
77
+ );
78
+ };
79
+
80
+ const WrapperContainer = styled.div`
81
+ display: grid;
82
+ grid-template-columns: 50% 50%;
83
+ justify-content: space-between;
84
+ width: calc(100% - 40px);
85
+ margin-left: 10px;
86
+
87
+ .rpgui-content .rpgui-dropdown-imp-header {
88
+ padding: 0px 10px 0 !important;
89
+ }
90
+ `;
91
+
92
+ const StyledDropdown = styled(Dropdown)`
93
+ margin: 3px !important;
94
+ width: 170px !important;
95
+ `;
96
+
97
+ const ItemComponentScrollWrapper = styled.div`
98
+ overflow-y: scroll;
99
+ height: 390px;
100
+ width: 100%;
101
+ margin-top: 1rem;
102
+
103
+ @media (max-width: 950px) {
104
+ height: 250px;
105
+ }
106
+ `;
107
+
108
+ const TableWrapper = styled.table`
109
+ margin: auto;
110
+ width: 100%;
111
+ `;
@@ -0,0 +1,97 @@
1
+ import { TopCharacterEntry, TopSkillEntry } from '@rpg-engine/shared';
2
+ import React from 'react';
3
+ import styled from 'styled-components';
4
+ import { uiColors } from '../../constants/uiColors';
5
+ import { Ellipsis } from '../shared/Ellipsis';
6
+
7
+ export interface ILeaderboardLevelProps {
8
+ items: Set<TopCharacterEntry> | Set<TopSkillEntry> | null;
9
+ rankType: string;
10
+ }
11
+
12
+ export const LeaderboardTable: React.FC<ILeaderboardLevelProps> = props => {
13
+ const { items, rankType } = props;
14
+ if (!items) return null;
15
+
16
+ function isTopSkillEntry(entry: any): entry is TopSkillEntry {
17
+ return 'skill' in entry;
18
+ }
19
+
20
+ return (
21
+ <>
22
+ <thead>
23
+ <TableRowWrapper>
24
+ <TableRowValue>
25
+ <p>
26
+ <Ellipsis maxLines={1} maxWidth="200px" fontSize="14px">
27
+ Name
28
+ </Ellipsis>
29
+ </p>
30
+ </TableRowValue>
31
+ {rankType === 'Skill' ? (
32
+ <TableRowValue>
33
+ <p>
34
+ <Ellipsis maxLines={1} maxWidth="200px" fontSize="14px">
35
+ Skill
36
+ </Ellipsis>
37
+ </p>
38
+ </TableRowValue>
39
+ ) : null}
40
+ <TableRowValue>
41
+ <p>
42
+ <Ellipsis maxLines={1} maxWidth="200px" fontSize="14px">
43
+ Level
44
+ </Ellipsis>
45
+ </p>
46
+ </TableRowValue>
47
+ </TableRowWrapper>
48
+ </thead>
49
+ <tbody>
50
+ {Array.from(items).map(entry => (
51
+ <TableRowWrapper key={entry.name}>
52
+ <TableRowValue>
53
+ <p>
54
+ <Ellipsis maxLines={1} maxWidth="200px" fontSize="10px">
55
+ {entry.name}
56
+ </Ellipsis>
57
+ </p>
58
+ </TableRowValue>
59
+ {isTopSkillEntry(entry) ? (
60
+ <TableRowValue>
61
+ <p>
62
+ <Ellipsis maxLines={1} maxWidth="200px" fontSize="10px">
63
+ {entry.skill}
64
+ </Ellipsis>
65
+ </p>
66
+ </TableRowValue>
67
+ ) : null}
68
+ <TableRowValue>
69
+ <p>
70
+ <Ellipsis maxLines={1} maxWidth="200px" fontSize="10px">
71
+ {entry.level}
72
+ </Ellipsis>
73
+ </p>
74
+ </TableRowValue>
75
+ </TableRowWrapper>
76
+ ))}
77
+ </tbody>
78
+ </>
79
+ );
80
+ };
81
+
82
+ const TableRowWrapper = styled.tr`
83
+ margin: auto;
84
+ padding: 0.5rem;
85
+
86
+ &:hover {
87
+ background-color: ${uiColors.darkGray};
88
+ }
89
+
90
+ p {
91
+ font-size: 0.8rem;
92
+ }
93
+ `;
94
+
95
+ const TableRowValue = styled.td`
96
+ padding: 0 20px;
97
+ `;
package/src/index.tsx CHANGED
@@ -15,6 +15,7 @@ export * from './components/Input';
15
15
  export { ErrorBoundary } from './components/Item/Inventory/ErrorBoundary';
16
16
  export * from './components/Item/Inventory/ItemContainer';
17
17
  export * from './components/Item/Inventory/ItemSlot';
18
+ export * from './components/Leaderboard/Leaderboard';
18
19
  export * from './components/ListMenu';
19
20
  export * from './components/Marketplace/Marketplace';
20
21
  export * from './components/Marketplace/MarketplaceRows';
@@ -0,0 +1,110 @@
1
+ import { TopCharacterEntry, TopSkillEntry } from '@rpg-engine/shared';
2
+
3
+ export const leaderboardLevelRankingItems: Set<TopCharacterEntry> = new Set([
4
+ {
5
+ name: 'Player 1',
6
+ level: 1,
7
+ },
8
+ {
9
+ name: 'Player 2',
10
+ level: 2,
11
+ },
12
+ {
13
+ name: 'Player 3',
14
+ level: 3,
15
+ },
16
+ {
17
+ name: 'Player 4',
18
+ level: 4,
19
+ },
20
+ {
21
+ name: 'Player 5',
22
+ level: 5,
23
+ },
24
+ {
25
+ name: 'Player 6',
26
+ level: 6,
27
+ },
28
+ {
29
+ name: 'Player 7',
30
+ level: 7,
31
+ },
32
+ {
33
+ name: 'Player 8',
34
+ level: 8,
35
+ },
36
+ {
37
+ name: 'Player 9',
38
+ level: 9,
39
+ },
40
+ {
41
+ name: 'Player 10',
42
+ level: 10,
43
+ },
44
+ ]);
45
+
46
+ export const leaderboardClassRankingItems: Set<TopCharacterEntry> = new Set([
47
+ {
48
+ name: 'Player 1',
49
+ level: 1,
50
+ },
51
+ {
52
+ name: 'Player 2',
53
+ level: 2,
54
+ },
55
+ {
56
+ name: 'Player 3',
57
+ level: 3,
58
+ },
59
+ {
60
+ name: 'Player 4',
61
+ level: 4,
62
+ },
63
+ {
64
+ name: 'Player 5',
65
+ level: 5,
66
+ },
67
+ {
68
+ name: 'Player 6',
69
+ level: 6,
70
+ },
71
+ {
72
+ name: 'Player 7',
73
+ level: 7,
74
+ },
75
+ {
76
+ name: 'Player 8',
77
+ level: 8,
78
+ },
79
+ {
80
+ name: 'Player 9',
81
+ level: 9,
82
+ },
83
+ {
84
+ name: 'Player 10',
85
+ level: 10,
86
+ },
87
+ ]);
88
+
89
+ export const leaderboardSkillRankingItems: Set<TopSkillEntry> = new Set([
90
+ {
91
+ name: 'Player 1',
92
+ level: 1,
93
+ skill: 'skill 1',
94
+ },
95
+ {
96
+ name: 'Player 2',
97
+ level: 2,
98
+ skill: 'skill 2',
99
+ },
100
+ {
101
+ name: 'Player 3',
102
+ level: 3,
103
+ skill: 'skill 3',
104
+ },
105
+ {
106
+ name: 'Player 4',
107
+ level: 4,
108
+ skill: 'skill 4',
109
+ },
110
+ ]);
@@ -0,0 +1,57 @@
1
+ import { Meta, Story } from '@storybook/react';
2
+ import React from 'react';
3
+ import {
4
+ ILeaderboardProps,
5
+ Leaderboard,
6
+ } from '../components/Leaderboard/Leaderboard';
7
+ import { RPGUIRoot } from '../components/RPGUIRoot';
8
+ import {
9
+ leaderboardClassRankingItems,
10
+ leaderboardLevelRankingItems,
11
+ leaderboardSkillRankingItems,
12
+ } from '../mocks/leaderboard.mocks';
13
+
14
+ const meta: Meta = {
15
+ title: 'Leaderboard',
16
+ component: Leaderboard,
17
+ };
18
+
19
+ export default meta;
20
+
21
+ const Template: Story<ILeaderboardProps> = args => {
22
+ return (
23
+ <RPGUIRoot>
24
+ <Leaderboard {...args} />
25
+ </RPGUIRoot>
26
+ );
27
+ };
28
+
29
+ export const Default = Template.bind({});
30
+
31
+ Default.args = {
32
+ items: leaderboardLevelRankingItems,
33
+ rankType: 'Level',
34
+ skills: ['Lumbarjacking'],
35
+ onChangeRankType: () => { },
36
+ onChangeClassType: () => { },
37
+ };
38
+
39
+ export const ClassRanking = Template.bind({});
40
+
41
+ ClassRanking.args = {
42
+ items: leaderboardClassRankingItems,
43
+ rankType: 'Class',
44
+ skills: ['Lumbarjacking'],
45
+ onChangeRankType: () => { },
46
+ onChangeClassType: () => { },
47
+ };
48
+
49
+ export const SkillRanking = Template.bind({});
50
+
51
+ SkillRanking.args = {
52
+ items: leaderboardSkillRankingItems,
53
+ rankType: 'Skill',
54
+ skills: ['Lumbarjacking'],
55
+ onChangeRankType: () => { },
56
+ onChangeClassType: () => { },
57
+ };