aboutsummaryrefslogtreecommitdiff
path: root/features/dungeonMap2/DungeonMapRoom.js
blob: d6ee01473fdec5ad04ca1baa3b6ba33091331140 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import DungeonRoomStaticData from "./DungeonRoomStaticData"

const Color = Java.type("java.awt.Color")

class DungeonMapRoom {

    static TYPE_SPAWN = 0
    static TYPE_NORMAL = 1
    static TYPE_PUZZLE = 2
    static TYPE_MINIBOSS = 3
    static TYPE_FAIRY = 4
    static TYPE_BLOOD = 5
    static TYPE_TRAP = 7
    static TYPE_UNKNOWN = 6

    static SHAPE_1X1 = 0
    static SHAPE_1X2 = 1
    static SHAPE_1X3 = 2
    static SHAPE_1X4 = 3
    static SHAPE_2X2 = 4
    static SHAPE_L = 5

    static fromId(roomId, x, y, rotation) {
        let data = DungeonRoomStaticData.getDataFromId(roomId)
        let type = DungeonMapRoom.TYPE_NORMAL
        switch (data.type) {
            case "mobs":
                type = DungeonMapRoom.TYPE_NORMAL
                break
            case "miniboss":
                type = DungeonMapRoom.TYPE_NORMAL
                break
            case "spawn":
                type = DungeonMapRoom.TYPE_SPAWN
                break
            case "puzzle":
                type = DungeonMapRoom.TYPE_PUZZLE
                break
            case "gold":
                type = DungeonMapRoom.TYPE_MINIBOSS
                break
            case "fairy":
                type = DungeonMapRoom.TYPE_FAIRY
                break
            case "blood":
                type = DungeonMapRoom.TYPE_BLOOD
                break
            case "trap":
                type = DungeonMapRoom.TYPE_TRAP
                break
        }

        let shape = DungeonMapRoom.SHAPE_1X1
        switch (data.shape) {
            case "1x1":
                shape = DungeonMapRoom.SHAPE_1X1
                break
            case "1x2":
                shape = DungeonMapRoom.SHAPE_1X2
                break
            case "1x3":
                shape = DungeonMapRoom.SHAPE_1X3
                break
            case "1x4":
                shape = DungeonMapRoom.SHAPE_1X4
                break
            case "2x2":
                shape = DungeonMapRoom.SHAPE_2X2
                break
            case "L":
                shape = DungeonMapRoom.SHAPE_L
                break
        }
        return new DungeonMapRoom(type, shape, rotation, x, y, roomId)
    }

    /**
     * 
     * @param {Number} type 
     * @param {Number} shape 
     * @param {Number} rotation 0-3
     * @param {Number} x 
     * @param {Number} y 
     * @param {String} roomId 
     */
    constructor(type, shape, rotation, x, y, roomId) {
        this.type = type
        this.shape = shape
        this.rotation = rotation
        this.roomId = roomId
        this.maxSecrets = roomId ? DungeonRoomStaticData.getDataFromId(roomId).secrets : 0
        this.secrets = 0

        this.checkedState = 0

        this.location = [x, y]
    }

    setSecrets(curr, max) {
        if (this.maxSecrets === 0) return
        this.maxSecrets = max
        this.secrets = curr
    }

    getSecrets() {
        let checkColor = "&8"
        if (this.checkedState === 1) checkColor = "&f"
        if (this.checkedState === 2) checkColor = "&a"
        return checkColor + this.secrets + "/" + this.maxSecrets
    }

    setId(id) {
        if (this.roomId !== id) {
            this.roomId = id

            let newRoomData = DungeonMapRoom.fromId(id)
            this.type = newRoomData.type
            this.shape = newRoomData.shape
            this.maxSecrets = newRoomData.maxSecrets
        }
    }

    setCheckedState(state) { }

    /**
     * Renders this room onto the given Graphics2D
     * @param {Graphics2D} graphics 
     */
    draw(graphics, renderTicks) {

        let [roomWidth, roomHeight] = this.getRoomWidthHeight()

        let translateX = this.location[0] + 3 + roomWidth / 2
        let translateY = this.location[1] + 3 + roomHeight / 2

        graphics.translate(translateX, translateY)

        graphics.setColor(this.getRoomRenderColor())

        switch (this.shape) {
            case DungeonMapRoom.SHAPE_1X1:
            case DungeonMapRoom.SHAPE_1X2:
            case DungeonMapRoom.SHAPE_1X3:
            case DungeonMapRoom.SHAPE_1X4:
            case DungeonMapRoom.SHAPE_2X2:
                graphics.fillRect(-roomWidth / 2 + 3, -roomHeight / 2 + 3, roomWidth - 6, roomHeight - 6)
                break;
            case DungeonMapRoom.SHAPE_L:
                graphics.rotate(this.rotation * Math.PI / 2)
                graphics.fillRect(-(26 + 32) / 2, -(26 + 32) / 2, 26, 26 + 32)
                graphics.fillRect(-(26 + 32) / 2, -(26 + 32) / 2, 26 + 32, 26)
                graphics.rotate(-this.rotation * Math.PI / 2)
                break;
        }

        graphics.translate(-translateX, -translateY)

        if (renderTicks || this.maxSecrets === 0) {
            if (this.checkedState === 1) {
                let loc = this.getIconLocation()
                graphics.drawImage(whiteCheck, loc[0] - 2, loc[1] - 2, 10, 10, null)
            }
            if (this.checkedState === 2) {
                let loc = this.getIconLocation()
                graphics.drawImage(greenCheck, loc[0] - 2, loc[1] - 2, 10, 10, null)
            }
        }
    }

    getRoomWidthHeight() {
        let roomWidth = 32
        let roomHeight = 32

        switch (this.shape) {
            case DungeonMapRoom.SHAPE_1X2:
                roomWidth = 64
                break;
            case DungeonMapRoom.SHAPE_1X3:
                roomWidth = 96
                break;
            case DungeonMapRoom.SHAPE_1X4:
                roomWidth = 128
                break;
            case DungeonMapRoom.SHAPE_2X2:
            case DungeonMapRoom.SHAPE_L:
                roomWidth = 64
                roomHeight = 64
                break;
        }

        if (this.rotation === 1 || this.rotation === 3) {
            let tmp = roomWidth
            roomWidth = roomHeight
            roomHeight = tmp
        }

        return [roomWidth, roomHeight]
    }

    getRoomRenderColor() {
        return roomColorMap.get(this.type)
    }

    getIconLocation() {
        let [width, height] = this.getRoomWidthHeight()
        if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 0) {
            return [this.location[0] + 16, this.location[1] + 16]
        }
        if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 1) {
            return [this.location[0] + 16 + 32, this.location[1] + 16]
        }
        if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 2) {
            return [this.location[0] + 16 + 31, this.location[1] + 16 + 31]
        }
        if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 2) {
            return [this.location[0] + 16, this.location[1] + 16 + 32]
        }

        return [this.location[0] + width / 2, this.location[1] + height / 2]
    }

    static drawUnknownRoom(graphics, x, y) {
        let roomWidth = 32
        let roomHeight = 32

        let translateX = x + 3 + roomWidth / 2
        let translateY = y + 3 + roomHeight / 2

        graphics.translate(translateX, translateY)

        graphics.setColor(roomColorMap.get(DungeonMapRoom.TYPE_UNKNOWN))

        graphics.fillRect(-13, -13, 26, 26)

        graphics.drawImage(questionMark, -4, -7, 8, 14, null)

        graphics.translate(-translateX, -translateY)
    }
}

let roomColorMap = new Map()
roomColorMap.set(DungeonMapRoom.TYPE_SPAWN, new Color(Renderer.color(0, 124, 0, 255)))
roomColorMap.set(DungeonMapRoom.TYPE_NORMAL, new Color(Renderer.color(114, 67, 27, 255)))
roomColorMap.set(DungeonMapRoom.TYPE_PUZZLE, new Color(Renderer.color(178, 76, 216, 255)))
roomColorMap.set(DungeonMapRoom.TYPE_MINIBOSS, new Color(Renderer.color(229, 229, 51, 255)))
roomColorMap.set(DungeonMapRoom.TYPE_FAIRY, new Color(Renderer.color(242, 127, 165, 255)))
roomColorMap.set(DungeonMapRoom.TYPE_BLOOD, new Color(Renderer.color(255, 0, 0, 255)))
roomColorMap.set(DungeonMapRoom.TYPE_TRAP, new Color(Renderer.color(216, 127, 51, 255)))
roomColorMap.set(DungeonMapRoom.TYPE_UNKNOWN, new Color(Renderer.color(65, 65, 65, 255)))

const greenCheck = new Image("greenCheckVanilla.png", "https://i.imgur.com/h2WM1LO.png").image
const whiteCheck = new Image("whiteCheckVanilla.png", "https://i.imgur.com/hwEAcnI.png").image
const failedRoom = new Image("failedRoomVanilla.png", "https://i.imgur.com/WqW69z3.png").image
const questionMark = new Image("questionMarkVanilla.png", "https://i.imgur.com/1jyxH9I.png").image

export default DungeonMapRoom