Skip to content

Commit

Permalink
allow ranged allowed_tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Jul 30, 2023
1 parent e78b489 commit 6c1a126
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions assets/maps/madra/madra_side.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
49 changes: 47 additions & 2 deletions base/interactable_objects/InteractableObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TileEvent["id"]>;
private collision_change_functions: Function[];
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 6c1a126

Please sign in to comment.