dev: tile dump

This commit is contained in:
cha0s 2024-07-23 15:06:32 -05:00
parent b04392756b
commit df0e012338
6 changed files with 81 additions and 4 deletions

View File

@ -0,0 +1,3 @@
import Packet from '@/net/packet.js';
export default class Download extends Packet {}

View File

@ -98,6 +98,25 @@ export default function PlaySpecific() {
client.removePacketListener('ConnectionStatus', onConnectionStatus);
};
}, [client]);
useEffect(() => {
if (!client) {
return;
}
function onDownload({data, filename}) {
var blob = new Blob(
[(new TextEncoder()).encode(JSON.stringify(data))],
{type: 'application/json'},
);
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = filename;
link.click();
}
client.addPacketListener('Download', onDownload);
return () => {
client.removePacketListener('Download', onDownload);
};
}, [client]);
useEffect(() => {
if (!client || !disconnected) {
return;

View File

@ -1,3 +1,5 @@
import data from '../../../public/assets/dev/homestead.json';
export default async function createHomestead(id) {
const area = {x: 100, y: 60};
const entities = [];
@ -8,7 +10,7 @@ export default async function createHomestead(id) {
layers: [
{
area,
data: Array(area.x * area.y).fill(0).map(() => 1 + Math.floor(Math.random() * 4)),
data,
source: '/assets/tileset.json',
tileSize: {x: 16, y: 16},
},
@ -152,5 +154,33 @@ export default async function createHomestead(id) {
for (let i = 0; i < 30; ++i) {
entities.push(kitty);
}
entities.push({
Collider: {
bodies: [
{
points: [
{x: -8, y: -16},
{x: 7, y: -16},
{x: 7, y: 15},
{x: -8, y: 15},
],
},
],
collisionStartScript: `
ecs.switchEcs(
other,
['houses', ${id}].join('/'),
{
Position: {
x: 72,
y: 304,
},
},
);
`,
},
Position: {x: 8, y: 432},
Ticking: {},
});
return entities;
}

View File

@ -48,7 +48,7 @@ export default async function createPlayer(id) {
Light: {},
Magnet: {strength: 24},
Player: {},
Position: {x: 128, y: 128},
Position: {x: 128, y: 448},
Speed: {speed: 100},
Sound: {},
Sprite: {

View File

@ -127,9 +127,35 @@ export default class Engine {
Inventory,
Wielder,
} = entity;
const ecs = this.ecses[Ecs.path];
for (const payload of payloads) {
switch (payload.type) {
case 'chat': {
if (payload.value.startsWith('/')) {
const [command, ...args] = payload.value.slice(1).split(' ');
switch (command) {
case 'dump': {
switch (args[0]) {
case 'tiles': {
const {TileLayers} = ecs.get(1);
this.server.send(
connection,
{
type: 'Download',
payload: {
data: TileLayers.layer(0).data,
filename: 'tiles.json',
},
},
);
break;
}
}
break;
}
}
break;
}
Interlocutor.dialogue({
body: payload.value,
linger: 5,
@ -140,7 +166,6 @@ export default class Engine {
break;
}
case 'paint': {
const ecs = this.ecses[Ecs.path];
const {TileLayers} = ecs.get(1);
const {brush, layer: paintLayer, stamp} = payload.value;
const layer = TileLayers.layer(paintLayer);
@ -181,7 +206,6 @@ export default class Engine {
if (!Controlled.locked) {
if (payload.value) {
if (Interacts.willInteractWith) {
const ecs = this.ecses[Ecs.path];
const subject = ecs.get(Interacts.willInteractWith);
subject.Interactive.interact(entity);
}

File diff suppressed because one or more lines are too long