2021-04-18 16:10:05 +00:00
|
|
|
// this script moves chunks of a canvas, i.e. to center it after changing size
|
|
|
|
|
2022-06-27 22:36:19 +00:00
|
|
|
import { createClient } from 'redis';
|
2021-04-18 16:10:05 +00:00
|
|
|
|
|
|
|
//ATTENTION Make suer to set the rdis URLs right!!!
|
|
|
|
const url = "redis://localhost:6379";
|
2022-06-27 22:36:19 +00:00
|
|
|
const redisc = createClient({ url });
|
2021-04-18 16:10:05 +00:00
|
|
|
|
2022-06-27 22:36:19 +00:00
|
|
|
const CANVAS_SIZE = 1024;
|
2021-04-18 16:10:05 +00:00
|
|
|
const TILE_SIZE = 256;
|
2022-06-27 22:36:19 +00:00
|
|
|
const offset = (2048 - 1024) / 2 / 256;
|
2021-04-18 16:10:05 +00:00
|
|
|
|
|
|
|
const CHUNKS_XY = CANVAS_SIZE / TILE_SIZE;
|
|
|
|
|
|
|
|
async function move() {
|
|
|
|
for (let x = CHUNKS_XY - 1; x >= 0; x--) {
|
|
|
|
for (let y = CHUNKS_XY - 1; y >= 0; y--) {
|
2022-06-27 22:36:19 +00:00
|
|
|
const key = `ch:8:${x}:${y}`;
|
|
|
|
const chunk = await redisc.get(key, { returnBuffers: true });
|
2021-04-18 16:10:05 +00:00
|
|
|
if (chunk) {
|
2022-06-27 22:36:19 +00:00
|
|
|
const newKey = `ch:8:${x + offset}:${y + offset}`
|
2022-06-28 11:13:09 +00:00
|
|
|
await redisc.set(newKey, chunk);
|
2022-04-05 19:37:33 +00:00
|
|
|
await redisc.del(key);
|
2021-04-18 16:10:05 +00:00
|
|
|
console.log('Moved Chunk ', key, ' to ', newKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("done");
|
|
|
|
}
|
|
|
|
|
2022-04-06 19:50:34 +00:00
|
|
|
redisc.connect()
|
|
|
|
.then(() => move());
|