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);
room.tiles[currentLayer].stampAt(where, stamp);
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 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)));
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 = (
{
@ -217,37 +191,47 @@ function TilesPage({
},
) => {
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) {
case 'touchstart':
case 'mousedown': {
switch (tilesetMode) {
case 0: {
stamp(origin);
break;
}
case 1: {
fill(origin);
break;
}
default:
}
edit();
setIsHoldingPaint(true);
break;
}
case 'touchmove':
case 'mousemove': {
if (isHoldingPaint) {
switch (tilesetMode) {
case 0: {
stamp(origin);
break;
}
case 1: {
fill(origin);
break;
}
default:
}
edit();
}
break;
}