codestyle fixes
This commit is contained in:
parent
1d13cfac36
commit
830c2bdde6
|
|
@ -45,7 +45,8 @@ export const VoxelEditorPage = observer(function () {
|
||||||
|
|
||||||
const undo = useCallback(() => {
|
const undo = useCallback(() => {
|
||||||
const entry = history.current.pop();
|
const entry = history.current.pop();
|
||||||
if (!entry || !id) return;
|
if (!entry || !id)
|
||||||
|
return;
|
||||||
if (entry.type === 'add') {
|
if (entry.type === 'add') {
|
||||||
state.worldEditor.removeVoxelFromObjectType(id, entry.voxel.position);
|
state.worldEditor.removeVoxelFromObjectType(id, entry.voxel.position);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -58,7 +59,8 @@ export const VoxelEditorPage = observer(function () {
|
||||||
|
|
||||||
const redo = useCallback(() => {
|
const redo = useCallback(() => {
|
||||||
const entry = future.current.pop();
|
const entry = future.current.pop();
|
||||||
if (!entry || !id) return;
|
if (!entry || !id)
|
||||||
|
return;
|
||||||
if (entry.type === 'add') {
|
if (entry.type === 'add') {
|
||||||
state.worldEditor.addVoxelToObjectType(id, entry.voxel);
|
state.worldEditor.addVoxelToObjectType(id, entry.voxel);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -71,7 +73,8 @@ export const VoxelEditorPage = observer(function () {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onKeyDown(e: KeyboardEvent) {
|
function onKeyDown(e: KeyboardEvent) {
|
||||||
if (!e.ctrlKey) return;
|
if (!e.ctrlKey)
|
||||||
|
return;
|
||||||
if (e.key === 'z' && !e.shiftKey) { e.preventDefault(); undo(); }
|
if (e.key === 'z' && !e.shiftKey) { e.preventDefault(); undo(); }
|
||||||
if (e.key === 'y' || (e.key === 'z' && e.shiftKey)) { e.preventDefault(); redo(); }
|
if (e.key === 'y' || (e.key === 'z' && e.shiftKey)) { e.preventDefault(); redo(); }
|
||||||
}
|
}
|
||||||
|
|
@ -80,19 +83,22 @@ export const VoxelEditorPage = observer(function () {
|
||||||
}, [undo, redo]);
|
}, [undo, redo]);
|
||||||
|
|
||||||
function handleAdd(voxel: Voxel) {
|
function handleAdd(voxel: Voxel) {
|
||||||
if (!id) return;
|
if (!id)
|
||||||
|
return;
|
||||||
state.worldEditor.addVoxelToObjectType(id, voxel);
|
state.worldEditor.addVoxelToObjectType(id, voxel);
|
||||||
pushHistory({ type: 'add', voxel });
|
pushHistory({ type: 'add', voxel });
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRemove(position: V3) {
|
function handleRemove(position: V3) {
|
||||||
if (!id || !objectType) return;
|
if (!id || !objectType)
|
||||||
|
return;
|
||||||
const voxel = objectType.voxels.find(v =>
|
const voxel = objectType.voxels.find(v =>
|
||||||
v.position[0] === position[0] &&
|
v.position[0] === position[0] &&
|
||||||
v.position[1] === position[1] &&
|
v.position[1] === position[1] &&
|
||||||
v.position[2] === position[2]
|
v.position[2] === position[2]
|
||||||
);
|
);
|
||||||
if (!voxel) return;
|
if (!voxel)
|
||||||
|
return;
|
||||||
state.worldEditor.removeVoxelFromObjectType(id, position);
|
state.worldEditor.removeVoxelFromObjectType(id, position);
|
||||||
pushHistory({ type: 'remove', voxel });
|
pushHistory({ type: 'remove', voxel });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,15 @@ export function VoxelEditorScene({ voxels, mode, color, typeId, onAdd, onRemove
|
||||||
const [ghost, setGhost] = useState<V3 | null>(null);
|
const [ghost, setGhost] = useState<V3 | null>(null);
|
||||||
|
|
||||||
function handleVoxelClick(e: ThreeEvent<MouseEvent>, voxel: Voxel) {
|
function handleVoxelClick(e: ThreeEvent<MouseEvent>, voxel: Voxel) {
|
||||||
if (e.delta > DRAG_THRESHOLD) return;
|
if (e.delta > DRAG_THRESHOLD)
|
||||||
|
return;
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (mode === 'remove') {
|
if (mode === 'remove') {
|
||||||
onRemove(voxel.position);
|
onRemove(voxel.position);
|
||||||
setGhost(null);
|
setGhost(null);
|
||||||
} else {
|
} else {
|
||||||
if (!e.face) return;
|
if (!e.face)
|
||||||
|
return;
|
||||||
const { x, y, z } = e.face.normal;
|
const { x, y, z } = e.face.normal;
|
||||||
const pos = adjPosition(voxel.position, x, y, z);
|
const pos = adjPosition(voxel.position, x, y, z);
|
||||||
onAdd({ typeId, position: pos, color });
|
onAdd({ typeId, position: pos, color });
|
||||||
|
|
@ -51,14 +53,16 @@ export function VoxelEditorScene({ voxels, mode, color, typeId, onAdd, onRemove
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFloorClick(e: ThreeEvent<MouseEvent>) {
|
function handleFloorClick(e: ThreeEvent<MouseEvent>) {
|
||||||
if (e.delta > DRAG_THRESHOLD || mode !== 'add') return;
|
if (e.delta > DRAG_THRESHOLD || mode !== 'add')
|
||||||
|
return;
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const pos: V3 = [Math.floor(e.point.x), 0, Math.floor(e.point.z)];
|
const pos: V3 = [Math.floor(e.point.x), 0, Math.floor(e.point.z)];
|
||||||
onAdd({ typeId, position: pos, color });
|
onAdd({ typeId, position: pos, color });
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFloorMove(e: ThreeEvent<PointerEvent>) {
|
function handleFloorMove(e: ThreeEvent<PointerEvent>) {
|
||||||
if (mode !== 'add') return;
|
if (mode !== 'add')
|
||||||
|
return;
|
||||||
setGhost([Math.floor(e.point.x), 0, Math.floor(e.point.z)]);
|
setGhost([Math.floor(e.point.x), 0, Math.floor(e.point.z)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue