Skip to content

Commit b801e15

Browse files
committed
chore: move structure files
1 parent 27fa57e commit b801e15

11 files changed

Lines changed: 124 additions & 6 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/node_modules
33
/dist
44
**/*.ignore*
5-
**/*.local*
65
/_site
76
/.vscode
87
/_features
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Collection from '../utils/collection.js';
2-
import Base from './base.js';
1+
import Base from '../base.js';
2+
import Collection from '../../utils/collection.js';
33
import Message from './message.js';
44

55
export default class Channel extends Base {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Collection from '../utils/collection.js';
21
import Channel from './channel.js';
2+
import Collection from '../../utils/collection.js';
33

44
export default class Chat {
55
constructor(data) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Base from './base.js';
1+
import Base from '../base.js';
22
import User from './user.js';
33

44
export default class Message extends Base {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Base from './base.js';
1+
import Base from '../base.js';
22

33
export default class User extends Base {
44
constructor(data) {

src/structures.local/vault/deck.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { global } from '../../utils/global.js';
2+
3+
export default class Deck {
4+
constructor(owner, soul = '', index = 0) {
5+
this.owner = owner;
6+
this.soul = soul;
7+
this.index = index;
8+
}
9+
10+
get key() {
11+
this.checkLocal();
12+
return `${this.owner.key}.${this.soul}.${this.index}`;
13+
}
14+
15+
get raw() {
16+
const cards = [{
17+
id: 0,
18+
shiny: false,
19+
}];
20+
const artifacts = [0];
21+
// Clear typings
22+
cards.shift();
23+
artifacts.shift();
24+
25+
const data = JSON.parse(this.getRaw());
26+
if (Array.isArray(data.cards)) {
27+
cards.concat(data.cards);
28+
}
29+
if (Array.isArray(data.artifacts)) {
30+
artifacts.concat(data.artifacts);
31+
}
32+
return {
33+
artifacts,
34+
cards,
35+
name: this.name,
36+
};
37+
}
38+
39+
get name() {
40+
return this.getRaw('name') || '';
41+
}
42+
43+
set name(to) {
44+
this.setRaw('name', to);
45+
}
46+
47+
get cards() {
48+
return this.raw.cards;
49+
}
50+
51+
get artifacts() {
52+
return this.raw.artifacts;
53+
}
54+
55+
getCards() {
56+
const allCards = global('allCards', { throws: false });
57+
const cards = this.cards;
58+
59+
if (!allCards) return cards;
60+
61+
return cards.map(({ id, shiny }) => {
62+
const card = allCards.find((c) => c.id === id && c.shiny === shiny);
63+
if (!card) return {};
64+
return { ...card }; // TODO: use card structure
65+
});
66+
}
67+
68+
getArtifacts() {
69+
const allArtifacts = global('allArtifacts', { throws: false });
70+
const artifacts = this.artifacts;
71+
72+
if (!allArtifacts) return artifacts;
73+
74+
const arts = artifacts.map((id) => {
75+
const artifact = allArtifacts.find(({ id: artID }) => artID === id);
76+
if (!artifact) return undefined;
77+
return { ...artifact }; // TODO: use artifact structure
78+
}).filter((_) => _); // Strip empty entries
79+
if (arts.length > 1) { // Only 1 legendary allowed
80+
const legend = arts.find(({ legendary }) => legendary);
81+
if (legend) return [legend];
82+
}
83+
return arts;
84+
}
85+
86+
meta() {
87+
// TODO - Object that allows getting/setting of metadata items
88+
// this.getRaw(`meta.${key}`);
89+
// this.setRaw(`meta.${key}`, value);
90+
}
91+
92+
getRaw(key) {
93+
this.checkLocal();
94+
return localStorage.getItem(key ? `${this.key}.${key}` : this.key) || '';
95+
}
96+
97+
setRaw(key, value = null) {
98+
this.checkLocal();
99+
const storageKey = key ? `${this.key}.${key}` : this.key;
100+
if (value === null) {
101+
localStorage.removeItem(storageKey);
102+
} else {
103+
localStorage.setItem(storageKey, value);
104+
}
105+
}
106+
107+
checkLocal() {
108+
if (!this.owner || !this.soul || !this.index) throw new Error('Not a local deck');
109+
}
110+
}

0 commit comments

Comments
 (0)