aboutsummaryrefslogtreecommitdiff
path: root/features/dungeonMap2/DungeonMapData.js
diff options
context:
space:
mode:
Diffstat (limited to 'features/dungeonMap2/DungeonMapData.js')
-rw-r--r--features/dungeonMap2/DungeonMapData.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/features/dungeonMap2/DungeonMapData.js b/features/dungeonMap2/DungeonMapData.js
new file mode 100644
index 0000000..15ffcca
--- /dev/null
+++ b/features/dungeonMap2/DungeonMapData.js
@@ -0,0 +1,80 @@
+import { m } from "../../../mappings/mappings"
+import DungeonMapRoom from "./DungeonMapRoom"
+
+const BufferedImage = Java.type("java.awt.image.BufferedImage")
+
+class DungeonMapData {
+ constructor(floor) {
+ this.floor = floor
+
+ this.greenRoom = undefined
+ /**
+ * @type {Map<String,DungeonMapRoom>}
+ */
+ this.rooms = new Map()
+
+ this.image = undefined
+ }
+
+ setRoom(x, y, rotation, id) {
+ let locstr = x + "," + y
+
+ if (this.rooms.get(locstr) && this.rooms.get(locstr).roomId !== id) {
+ this.rooms.get(locstr).setId(id)
+ this.mapChanged()
+ return
+ }
+
+ let room = DungeonMapRoom.fromId(id, x, y, rotation)
+
+ if (room.type === DungeonMapRoom.TYPE_SPAWN) {
+ this.greenRoom = locstr
+ }
+ console.log(room.type)
+
+ this.rooms.set(locstr, room)
+
+ this.mapChanged()
+ }
+
+ mapChanged() {
+ if (this.image) {
+ this.image.getTexture()[m.deleteGlTexture]()
+ this.image = undefined
+ }
+ }
+
+ /**
+ * @returns {Image}
+ */
+ getImage() {
+ if (!this.image) {
+ this.image = new Image(this.render())
+ }
+ return this.image
+ }
+
+ /**
+ * @returns {BufferedImage}
+ */
+ render() {
+ //create 256x256 image
+ let image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB)
+
+ //if green room data not found yet then map should be empty
+ if (!this.greenRoom) return image
+
+ //create graphics rendering context
+ let graphics = image.createGraphics()
+
+ //render rooms
+ for (let data of this.rooms.entries()) {
+ let room = data[1]
+ room.draw(graphics, 256, 256)
+ }
+
+ return image
+ }
+}
+
+export default DungeonMapData \ No newline at end of file