From 148eff81ff5936671804d9ec3a00ac0ac137703b Mon Sep 17 00:00:00 2001 From: HF Date: Sun, 18 Apr 2021 18:10:05 +0200 Subject: [PATCH] add script to move moon chunks to center --- utils/redisMoveCanvas.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 utils/redisMoveCanvas.js diff --git a/utils/redisMoveCanvas.js b/utils/redisMoveCanvas.js new file mode 100644 index 00000000..40d3f3cc --- /dev/null +++ b/utils/redisMoveCanvas.js @@ -0,0 +1,38 @@ +/* @flow */ +// this script moves chunks of a canvas, i.e. to center it after changing size + +import redis from 'redis'; +import bluebird from 'bluebird'; + + +bluebird.promisifyAll(redis.RedisClient.prototype); +bluebird.promisifyAll(redis.Multi.prototype); + +//ATTENTION Make suer to set the rdis URLs right!!! +const url = "redis://localhost:6379"; +const redis = redis.createClient(url, { return_buffers: true }); + +const CANVAS_SIZE = 4096; +const TILE_SIZE = 256; +const offset = (16384 - 4096) / 2 / 256; + +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--) { + const key = `ch:1:${x}:${y}`; + const chunk = await redis.getAsync(key); + if (chunk) { + const buffer = new Uint8Array(chunk); + const newKey = `ch:1:${x + offset}:${y + offset}` + await redis.setAsync(newKey, Buffer.from(buffer.buffer)); + await redis.delAsync(key); + console.log('Moved Chunk ', key, ' to ', newKey); + } + } + } + console.log("done"); +} + +move();