silphius/resources/watering-can/start.js
2024-09-17 01:25:39 -05:00

63 lines
1.4 KiB
JavaScript

const {Direction, Position, Wielder} = wielder
const projected = Wielder.activeItem()?.project(Position.tile, Direction.quantize(4))
if (projected?.length > 0) {
const {Controlled, Emitter, Sound, Sprite} = wielder
const {TileLayers, Water} = ecs.get(1)
const layer = TileLayers.layer(0)
Controlled.locked = 1
const [, direction] = Sprite.animation.split(':')
Sprite.animation = ['idle', direction].join(':');
Sound.play('/resources/watering-can/water.wav');
for (const {x, y} of projected) {
Emitter.emit({
entity: {
Forces: {forceY: 100},
Position: {
x: x * layer.tileSize.x + (layer.tileSize.x / 2),
y: y * layer.tileSize.y - (layer.tileSize.y / 4),
},
Sprite: {
scaleX: 0.05,
scaleY: 0.15,
tint: 0x0022aa,
},
Ttl: {ttl: 0.1},
},
fields: [
{
path: ['Sprite', 'lightness'],
value: [0.111, 0.666],
},
],
frequency: 0.01,
shape: {
type: 'circle',
payload: {radius: 4},
},
ttl: 0.5,
});
}
await wait(0.5);
for (const {x, y} of projected) {
const tileIndex = layer.area.x * y + x
let w;
if (Water.water[tileIndex]) {
w = Water.water[tileIndex]
}
else {
w = 0
}
Water.water[tileIndex] = Math.min(255, 64 + w);
}
ecs.system('Water').schedule();
Controlled.locked = 0;
}