diff --git a/assets/maps/madra/madra_side.json b/assets/maps/madra/madra_side.json index 9762d9dba9..d5316c7f0c 100644 --- a/assets/maps/madra/madra_side.json +++ b/assets/maps/madra/madra_side.json @@ -2054,8 +2054,8 @@ "properties": { "Name":"madra_side", - "interactable_object\/01":"{\n\"key_name\": \"push_pillar\",\n\"animation\": \"pillar\",\n\"x\": 14,\n\"y\": 11,\n\"allowed_tiles\": [\n{\"x\": 13, \"y\": 7, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 7, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 8, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 8, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 9, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 9, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 10, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 10, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 11, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 11, \"collision_layer\": 0}\n],\n\"base_collision_layer\": 0,\n\"events_info\": {\n \"0\": {\n \"collision_layer_shift\": 2\n }\n}\n}", - "interactable_object\/02":"{\n\"key_name\": \"push_pillar\",\n\"animation\": \"pillar\",\n\"x\": 13,\n\"y\": 11,\n\"enable\": false,\n\"entangled_by_bush\": true,\n\"allowed_tiles\": [\n{\"x\": 13, \"y\": 7, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 7, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 8, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 8, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 9, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 9, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 10, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 10, \"collision_layer\": 0},\n{\"x\": 13, \"y\": 11, \"collision_layer\": 0},\n{\"x\": 14, \"y\": 11, \"collision_layer\": 0}\n],\n\"base_collision_layer\": 0,\n\"events_info\": {\n \"0\": {\n \"collision_layer_shift\": 2\n }\n}\n}", + "interactable_object\/01":"{\n\"key_name\": \"push_pillar\",\n\"animation\": \"pillar\",\n\"x\": 14,\n\"y\": 11,\n\"allowed_tiles\": [\n {\n \"type\": \"rect\",\n \"x0\": 13,\n \"y0\": 7,\n \"x1\": 14,\n \"y1\": 11,\n \"collision_layer\": 0\n }\n],\n\"base_collision_layer\": 0,\n\"events_info\": {\n \"0\": {\n \"collision_layer_shift\": 2\n }\n}\n}", + "interactable_object\/02":"{\n\"key_name\": \"push_pillar\",\n\"animation\": \"pillar\",\n\"x\": 13,\n\"y\": 11,\n\"enable\": false,\n\"entangled_by_bush\": true,\n\"allowed_tiles\": [\n {\n \"type\": \"rect\",\n \"x0\": 13,\n \"y0\": 7,\n \"x1\": 14,\n \"y1\": 11,\n \"collision_layer\": 0\n }\n],\n\"base_collision_layer\": 0,\n\"events_info\": {\n \"0\": {\n \"collision_layer_shift\": 2\n }\n}\n}", "interactable_object\/03":"{\n\"key_name\": \"frost_pool\",\n\"x\": 12,\n\"y\": 11,\n\"base_collision_layer\": 0,\n\"events_info\": {\n \"1\": {\n \"collision_layer_shift\": 2\n }\n}\n}", "interactable_object\/04":"{\n\"key_name\": \"frost_pool\",\n\"x\": 12,\n\"y\": 10,\n\"base_collision_layer\": 0,\n\"events_info\": {\n \"1\": {\n \"collision_layer_shift\": 2\n }\n}\n}", "interactable_object\/05":"{\n\"key_name\": \"frost_pool\",\n\"x\": 10,\n\"y\": 10,\n\"base_collision_layer\": 0,\n\"events_info\": {\n \"1\": {\n \"collision_layer_shift\": 2\n }\n},\n\"not_allowed_tiles\": [\n{\"x\": 10, \"y\": 9},\n{\"x\": 10, \"y\": 11}\n]\n}", diff --git a/base/interactable_objects/InteractableObjects.ts b/base/interactable_objects/InteractableObjects.ts index d543685009..c257c4574c 100644 --- a/base/interactable_objects/InteractableObjects.ts +++ b/base/interactable_objects/InteractableObjects.ts @@ -45,7 +45,11 @@ export class InteractableObjects { protected game: Phaser.Game; protected data: GoldenSun; - private allowed_tiles: {x: number; y: number; collision_layer: number}[]; + private allowed_tiles: { + x: number; + y: number; + collision_layer: number; + }[]; private not_allowed_tiles: {x: number; y: number}[]; private events_id: Set; private collision_change_functions: Function[]; @@ -185,7 +189,7 @@ export class InteractableObjects { this._tile_x_pos = x; this._tile_y_pos = y; this._sprite_info = null; - this.allowed_tiles = allowed_tiles ?? []; + this.parse_allowed_tiles(allowed_tiles); if (this.storage_keys.base_collision_layer !== undefined) { base_collision_layer = this.data.storage.get(this.storage_keys.base_collision_layer); } @@ -441,6 +445,47 @@ export class InteractableObjects { return this._affected_by_reveal; } + parse_allowed_tiles( + allowed_tiles: { + x?: number; + y?: number; + x0?: number; + y0?: number; + x1?: number; + y1?: number; + collision_layer: number; + type: "tile" | "rect"; + }[] + ) { + this.allowed_tiles = []; + if (!allowed_tiles) { + return; + } + allowed_tiles.forEach(tile_info => { + if (tile_info.type === "tile") { + this.allowed_tiles.push({ + x: tile_info.x, + y: tile_info.y, + collision_layer: tile_info.collision_layer, + }); + } else if (tile_info.type === "rect") { + const x0 = Math.min(tile_info.x0, tile_info.x1); + const x1 = Math.max(tile_info.x0, tile_info.x1); + const y0 = Math.min(tile_info.y0, tile_info.y1); + const y1 = Math.max(tile_info.y0, tile_info.y1); + for (let x = x0; x <= x1; ++x) { + for (let y = y0; y <= y1; ++y) { + this.allowed_tiles.push({ + x: x, + y: y, + collision_layer: tile_info.collision_layer, + }); + } + } + } + }); + } + position_allowed(x: number, y: number) { if ( this.data.map.interactable_objects.filter(io => {