implement the Turntable

Rotates anything entering this tile (counter)clockwise. Frame blocks are rotated too. If connected to wire, only functions while receiving power.
This commit is contained in:
Timothy Stiles 2021-02-07 21:47:52 +11:00
parent 76c34007a2
commit 1040646393
5 changed files with 91 additions and 1 deletions

View File

@ -857,6 +857,14 @@ const TILE_ENCODING = {
name: 'fire_sticks', name: 'fire_sticks',
is_extension: true, is_extension: true,
}, },
0xef: {
name: 'turntable_cw',
is_extension: true,
},
0xf0: {
name: 'turntable_ccw',
is_extension: true,
},
}; };
const REVERSE_TILE_ENCODING = {}; const REVERSE_TILE_ENCODING = {};
for (let [tile_byte, spec] of Object.entries(TILE_ENCODING)) { for (let [tile_byte, spec] of Object.entries(TILE_ENCODING)) {

View File

@ -1602,6 +1602,8 @@ const EDITOR_PALETTE = [{
'global_cycler', 'global_cycler',
'halo', 'halo',
'fire_sticks', 'fire_sticks',
'turntable_cw',
'turntable_ccw',
], ],
}]; }];
@ -2192,6 +2194,14 @@ const EDITOR_TILE_DESCRIPTIONS = {
name: "Dormant Lava", name: "Dormant Lava",
desc: "Acts like dirt. However, fireballs will enter it and turn it into Fire in the process.", desc: "Acts like dirt. However, fireballs will enter it and turn it into Fire in the process.",
}, },
turntable_cw: {
name: "Turntable (Clockwise)",
desc: "Rotates anything entering this tile clockwise. Frame blocks are rotated too. If connected to wire, only functions while receiving power.",
},
turntable_ccw: {
name: "Turntable (Counterclockwise)",
desc: "Rotates anything entering this tile counterclockwise. Frame blocks are rotated too. If connected to wire, only functions while receiving power.",
},
}; };
const SPECIAL_PALETTE_ENTRIES = { const SPECIAL_PALETTE_ENTRIES = {
@ -2439,6 +2449,7 @@ for (let cycle of [
['ice_nw', 'ice_ne', 'ice_se', 'ice_sw'], ['ice_nw', 'ice_ne', 'ice_se', 'ice_sw'],
['swivel_nw', 'swivel_ne', 'swivel_se', 'swivel_sw'], ['swivel_nw', 'swivel_ne', 'swivel_se', 'swivel_sw'],
['terraformer_n', 'terraformer_e', 'terraformer_s', 'terraformer_w'], ['terraformer_n', 'terraformer_e', 'terraformer_s', 'terraformer_w'],
['turntable_cw', 'turntable_ccw'],
]) { ]) {
for (let [i, name] of cycle.entries()) { for (let [i, name] of cycle.entries()) {
let left = cycle[(i - 1 + cycle.length) % cycle.length]; let left = cycle[(i - 1 + cycle.length) % cycle.length];

View File

@ -1038,7 +1038,16 @@ export const LL_TILESET_LAYOUT = Object.assign({}, CC2_TILESET_LAYOUT, {
global_cycler: [4, 43], global_cycler: [4, 43],
halo: [5, 43], halo: [5, 43],
fire_sticks: [6, 43], fire_sticks: [6, 43],
turntable_cw: {
__special__: 'visual-state',
active: [7, 43],
inactive: [9, 43],
},
turntable_ccw: {
__special__: 'visual-state',
active: [8, 43],
inactive: [10, 43],
},
}); });
export const TILESET_LAYOUTS = { export const TILESET_LAYOUTS = {

View File

@ -705,6 +705,68 @@ const TILE_TYPES = {
} }
}, },
}, },
turntable_cw: {
layer: LAYERS.terrain,
//note: should be wireable in exactly the same way as a transmogrifier
wire_propagation_mode: 'none',
on_begin(me, level) {
// TODO if wire destruction is ever allowed, this will need to update somehow
me.is_wired = level.is_tile_wired(me, false);
me.is_active = ! me.is_wired;
},
on_arrive(me, level, other) {
if (! me.is_active)
return;
other.direction = DIRECTIONS[other.direction].right;
if (other.type.on_rotate) {
other.type.on_rotate(other, level, 'right');
}
},
on_power(me, level) {
if (me.is_wired) {
level._set_tile_prop(me, 'is_active', true);
}
},
on_depower(me, level) {
if (me.is_wired) {
level._set_tile_prop(me, 'is_active', false);
}
},
visual_state(me) {
return ! me || me.is_active ? 'active' : 'inactive';
},
},
turntable_ccw: {
layer: LAYERS.terrain,
//note: should be wireable in exactly the same way as a transmogrifier
wire_propagation_mode: 'none',
on_begin(me, level) {
// TODO if wire destruction is ever allowed, this will need to update somehow
me.is_wired = level.is_tile_wired(me, false);
me.is_active = ! me.is_wired;
},
on_arrive(me, level, other) {
if (! me.is_active)
return;
other.direction = DIRECTIONS[other.direction].left;
if (other.type.on_rotate) {
other.type.on_rotate(other, level, 'left');
}
},
on_power(me, level) {
if (me.is_wired) {
level._set_tile_prop(me, 'is_active', true);
}
},
on_depower(me, level) {
if (me.is_wired) {
level._set_tile_prop(me, 'is_active', false);
}
},
visual_state(me) {
return ! me || me.is_active ? 'active' : 'inactive';
},
},
// Hazards // Hazards
fire: { fire: {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB