refactor: efficiency

This commit is contained in:
cha0s 2022-04-08 09:40:10 -05:00
parent a7a2169b67
commit 16959f5798

View File

@ -127,19 +127,6 @@ function TilesPage({
const where = Rectangle.compose(origin, size); const where = Rectangle.compose(origin, size);
room.tiles[currentLayer].stampAt(where, stamp); room.tiles[currentLayer].stampAt(where, stamp);
room.tiles[currentLayer].emit('update', where); room.tiles[currentLayer].emit('update', where);
const {data} = room.tiles[currentLayer].toJSON();
if (!data) {
patch({
op: 'remove',
path: `/tiles/${currentLayer}/data`,
});
}
else {
patch({
path: `/tiles/${currentLayer}/data`,
value: data,
});
}
}; };
const fill = (origin) => { const fill = (origin) => {
const position = Vector.div([selection[0], selection[1]], tileSize); const position = Vector.div([selection[0], selection[1]], tileSize);
@ -196,19 +183,6 @@ function TilesPage({
} }
const where = Rectangle.compose(min, Vector.add([1, 1], Vector.sub(max, min))); const where = Rectangle.compose(min, Vector.add([1, 1], Vector.sub(max, min)));
room.tiles[currentLayer].emit('update', where); room.tiles[currentLayer].emit('update', where);
const {data} = room.tiles[currentLayer].toJSON();
if (!data) {
patch({
op: 'remove',
path: `/tiles/${currentLayer}/data`,
});
}
else {
patch({
path: `/tiles/${currentLayer}/data`,
value: data,
});
}
}; };
const onValue = ( const onValue = (
{ {
@ -217,37 +191,47 @@ function TilesPage({
}, },
) => { ) => {
const origin = Vector.floor(Vector.div(position, tileSize)); const origin = Vector.floor(Vector.div(position, tileSize));
const edit = () => {
const {data: originalData} = room.tiles[currentLayer].toJSON();
switch (tilesetMode) {
case 0: {
stamp(origin);
break;
}
case 1: {
fill(origin);
break;
}
default:
}
const {data} = room.tiles[currentLayer].toJSON();
if (data === originalData) {
return;
}
if (!data) {
patch({
op: 'remove',
path: `/tiles/${currentLayer}/data`,
});
}
else {
patch({
path: `/tiles/${currentLayer}/data`,
value: data,
});
}
};
switch (type) { switch (type) {
case 'touchstart': case 'touchstart':
case 'mousedown': { case 'mousedown': {
switch (tilesetMode) { edit();
case 0: {
stamp(origin);
break;
}
case 1: {
fill(origin);
break;
}
default:
}
setIsHoldingPaint(true); setIsHoldingPaint(true);
break; break;
} }
case 'touchmove': case 'touchmove':
case 'mousemove': { case 'mousemove': {
if (isHoldingPaint) { if (isHoldingPaint) {
switch (tilesetMode) { edit();
case 0: {
stamp(origin);
break;
}
case 1: {
fill(origin);
break;
}
default:
}
} }
break; break;
} }