Make map editor more like pico 8
This commit is contained in:
23
util.ts
23
util.ts
@@ -46,10 +46,27 @@ export const drawTransparentRect = (x: number, y: number, w: number, h: number)
|
||||
})
|
||||
}
|
||||
|
||||
export const subgrid = <T>(array: Array<T>, gridW: number, x: number, y: number, w: number, h: number): Array<T> => {
|
||||
export const drawVoidRect = (x: number, y: number, w: number, h: number) => {
|
||||
Array(w*h).fill(0).map((_z, j) => {
|
||||
const jx = j%w;
|
||||
const jy = Math.floor(j/w);
|
||||
setPixelColor(x+jx, y+jy, (jx+jy)%2 ? COLOR.BLACK : COLOR.DARKERBLUE);
|
||||
})
|
||||
}
|
||||
|
||||
export const subgrid = <T>(array: Array<T>, gridW: number, x: number, y: number, w: number, h: number): Array<T|undefined> => {
|
||||
return Array(h).fill(0).flatMap((_, i) => {
|
||||
const start = (y+i)*gridW+x;
|
||||
return array.slice(start, start+w);
|
||||
if (y+i < 0 || y+i > array.length/gridW) {
|
||||
return Array(w).fill(undefined);
|
||||
}
|
||||
const x0 = Math.max(0, x);
|
||||
const x1 = Math.min(x+w, gridW);
|
||||
const start = (y+i)*gridW+x0;
|
||||
const end = (y+i)*gridW+x1;
|
||||
const before = Array(x0 - x).fill(undefined);
|
||||
const after = Array((x+w) - x1).fill(undefined);
|
||||
const middle = array.slice(start, end);
|
||||
return [...before, ...middle, ...after];
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user