-
Notifications
You must be signed in to change notification settings - Fork 0
/
treasureStats.ts
76 lines (64 loc) · 2.48 KB
/
treasureStats.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
namespace TreasureStats {
export type TreasureStat = {
onBoat?: number
onIsland?: number
inPocket?: number
}
export type OnUpdateTreasureProps = TreasureStat & {
pulledFromIsland?: Map.Island['id']
}
const boatIcon: Image = assets.image`Boat Icon`
const islandIcon: Image = assets.image`Island Icon`
const pocketIcon: Image = assets.image`Pocket Icon`
let treasureSprites: Sprite[] = []
let iconSprites: Sprite[] = []
let currentDisplayCombo: Array<'island' | 'boat' | 'pocket'> = ['island']
let currentPosition: 'left' | 'center' = 'left'
export let currentTreasure: TreasureStat = {
onBoat: 0,
onIsland: 0,
inPocket: 0
}
export function getTotal(): number {
return currentTreasure.onBoat + currentTreasure.onIsland + currentTreasure.inPocket
}
export function show({ combination, location }: { combination?: Array<'island' | 'boat' | 'pocket'>, location?: 'left' | 'center' }) {
currentDisplayCombo = combination ? combination : currentDisplayCombo
currentPosition = location ? location : currentPosition
let currentY = 8
treasureSprites.forEach(t => t.destroy())
iconSprites.forEach(icon => icon.destroy())
currentDisplayCombo.forEach((statType) => {
let text: number
let iconSprite: Sprite
switch(statType) {
case 'boat':
text = currentTreasure.onBoat
iconSprite = sprites.create(boatIcon)
break;
case 'island':
text = currentTreasure.onIsland
iconSprite = sprites.create(islandIcon)
break;
default:
text = currentTreasure.inPocket
iconSprite = sprites.create(pocketIcon)
break;
}
const locX = currentPosition === 'center' ? 80 : 5
const scoreSprite = textsprite.create(text + '', 1, 15)
scoreSprite.x = locX + 7 + (scoreSprite.width / 2)
scoreSprite.y = currentY
scoreSprite.z = 100
treasureSprites.push(scoreSprite)
iconSprite.x = locX
iconSprite.y = currentY
iconSprites.push(iconSprite)
currentY += 9
})
}
export function hide() {
treasureSprites.forEach(t => t.destroy())
iconSprites.forEach(i => i.destroy())
}
}