diff --git a/eslint.config.js b/eslint.config.js
index 986a5c3..474e4d3 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -19,13 +19,12 @@ export default defineConfig([
globals: globals.browser,
},
rules: {
- "padding-line-between-statements": [
- "warn",
- { blankLine: 'always', prev: '*', next: 'block' },
- { blankLine: 'always', prev: 'block', next: '*' },
- { blankLine: 'always', prev: '*', next: 'block-like' },
- { blankLine: 'always', prev: 'block-like', next: '*' },
- ]
+ "semi": ["error", "always"],
+ "nonblock-statement-body-position": ["error", "below"],
+ "@typescript-eslint/no-unused-vars": ["error", {
+ "varsIgnorePattern": "^_",
+ "argsIgnorePattern": "^_",
+ }],
},
},
])
diff --git a/src/App.tsx b/src/App.tsx
index b56d3cc..8630c58 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,6 +1,6 @@
import { BrowserRouter, Link, Outlet, Route, Routes, useLocation, useNavigate, useParams } from 'react-router-dom';
import { VoxelEditorPage } from './components/voxelEditor/VoxelEditorPage';
-import { useEffect, useRef } from 'react';
+import { useEffect, useLayoutEffect, useRef } from 'react';
import { reaction } from 'mobx';
import { ThreeView } from './components/ThreeView';
import { state } from './state';
@@ -11,7 +11,7 @@ function StateToUrlSync() {
const navigate = useNavigate();
const { pathname } = useLocation();
const pathnameRef = useRef(pathname);
- pathnameRef.current = pathname;
+ useLayoutEffect(() => { pathnameRef.current = pathname; });
useEffect(() => reaction(
() => ({
@@ -21,22 +21,28 @@ function StateToUrlSync() {
}),
({ isGame, selectedObjectId, selectedObjectTypeId }) => {
let target: string;
- if (isGame) target = '/game';
- else if (selectedObjectId) target = `/editor/object/${selectedObjectId}`;
- else if (selectedObjectTypeId) target = `/editor/objectType/${selectedObjectTypeId}`;
- else target = '/editor';
+ if (isGame)
+ target = '/game';
+ else if (selectedObjectId)
+ target = `/editor/object/${selectedObjectId}`;
+ else if (selectedObjectTypeId)
+ target = `/editor/objectType/${selectedObjectTypeId}`;
+ else
+ target = '/editor';
const current = pathnameRef.current;
- if (current === target || current.startsWith(target + '/')) return;
+ if (current === target || current.startsWith(target + '/'))
+ return;
navigate(target);
},
- ), []);
+ ), [navigate]);
return null;
}
function EditorRoute() {
useEffect(() => {
- if (!!state.game) state.stopGame();
+ if (state.game)
+ state.stopGame();
state.worldEditor.resetSelection();
}, []);
return null;
@@ -45,8 +51,9 @@ function EditorRoute() {
function EditorObjectRoute() {
const { id } = useParams<{ id: string }>();
useEffect(() => {
- if (!id) return;
- if (!!state.game)
+ if (!id)
+ return;
+ if (state.game)
state.stopGame();
const editMode = state.worldEditor.selection?.type === 'object' && state.worldEditor.selection.id === id
? state.worldEditor.selection.editMode ?? 'translate'
@@ -59,8 +66,10 @@ function EditorObjectRoute() {
function EditorObjectTypeRoute() {
const { id } = useParams<{ id: string }>();
useEffect(() => {
- if (!id) return;
- if (!!state.game) state.stopGame();
+ if (!id)
+ return;
+ if (state.game)
+ state.stopGame();
const editMode = state.worldEditor.selection?.type === 'objectType' && state.worldEditor.selection.id === id
? state.worldEditor.selection.editMode ?? 'scripts'
: 'scripts';
diff --git a/src/blockly/actions/consoleLog.ts b/src/blockly/actions/consoleLog.ts
index 3c283be..337e982 100644
--- a/src/blockly/actions/consoleLog.ts
+++ b/src/blockly/actions/consoleLog.ts
@@ -7,7 +7,7 @@ Blockly.Blocks['console_log_action'] = {
.setAlign(Blockly.inputs.Align.RIGHT)
// .setCheck('String')
.appendField('print');
- this.setInputsInline(false)
+ this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Print value to console');
diff --git a/src/blockly/actions/physics/applyImpulse.ts b/src/blockly/actions/physics/applyImpulse.ts
index 7ae5f50..6f43360 100644
--- a/src/blockly/actions/physics/applyImpulse.ts
+++ b/src/blockly/actions/physics/applyImpulse.ts
@@ -12,7 +12,7 @@ Blockly.Blocks['physics_apply_impulse_action'] = {
.appendField(new Blockly.FieldNumber(1, -10, 10, 0.01), 'FORCE');
- this.setInputsInline(true)
+ this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Push me in a direction');
diff --git a/src/blockly/fieldTypes/objectType.ts b/src/blockly/fieldTypes/objectType.ts
index 1e57905..db145a6 100644
--- a/src/blockly/fieldTypes/objectType.ts
+++ b/src/blockly/fieldTypes/objectType.ts
@@ -1,6 +1,7 @@
import * as Blockly from "blockly";
export class ObjecTypeField extends Blockly.Field {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(value: any, validator: any) {
super(value, validator);
diff --git a/src/blockly/values/currentObject.ts b/src/blockly/values/currentObject.ts
index 9310863..8eb2019 100644
--- a/src/blockly/values/currentObject.ts
+++ b/src/blockly/values/currentObject.ts
@@ -5,7 +5,7 @@ Blockly.Blocks['current_object_value'] = {
init(this: Blockly.Block) {
this.appendEndRowInput('NAME')
.appendField('Me');
- this.setInputsInline(false)
+ this.setInputsInline(false);
this.setOutput(true, 'Object');
this.setTooltip('Returns current object instance');
this.setColour(315);
diff --git a/src/blockly/values/currentObjectType.ts b/src/blockly/values/currentObjectType.ts
index 8b72ddd..c04c6eb 100644
--- a/src/blockly/values/currentObjectType.ts
+++ b/src/blockly/values/currentObjectType.ts
@@ -5,7 +5,7 @@ Blockly.Blocks['current_object_type_value'] = {
init(this: Blockly.Block) {
this.appendEndRowInput('NAME')
.appendField('My type');
- this.setInputsInline(false)
+ this.setInputsInline(false);
this.setOutput(true, 'ObjectType');
this.setTooltip('Returns current object type');
this.setColour(315);
diff --git a/src/blockly/values/objectById.ts b/src/blockly/values/objectById.ts
index e58b34f..ff294cc 100644
--- a/src/blockly/values/objectById.ts
+++ b/src/blockly/values/objectById.ts
@@ -6,7 +6,7 @@ Blockly.Blocks['object_by_id_value'] = {
this.appendEndRowInput()
.appendField('Object with id')
.appendField(new Blockly.FieldTextInput(''), 'TARGET_ID');
- this.setInputsInline(false)
+ this.setInputsInline(false);
this.setOutput(true, 'Object');
this.setTooltip('Returns object by id, if any');
this.setColour(315);
diff --git a/src/blockly/values/playerObject.ts b/src/blockly/values/playerObject.ts
index 548e79f..ef37655 100644
--- a/src/blockly/values/playerObject.ts
+++ b/src/blockly/values/playerObject.ts
@@ -5,7 +5,7 @@ Blockly.Blocks['player_object_value'] = {
init(this: Blockly.Block) {
this.appendEndRowInput()
.appendField('Player');
- this.setInputsInline(false)
+ this.setInputsInline(false);
this.setOutput(true, 'Object');
this.setTooltip('Returns object that is controlled by player');
this.setColour(315);
diff --git a/src/components/CharacterView.tsx b/src/components/CharacterView.tsx
index eb91034..11f5b9f 100644
--- a/src/components/CharacterView.tsx
+++ b/src/components/CharacterView.tsx
@@ -46,7 +46,7 @@ export const PlayerObjectView = observer(function ({ object, objectType }: Playe
shoulderOffset: new Vector3(W * 0.1, centerY + H * 0.3, bb.max[2] + radius),
lookAtY: centerY,
};
- }, [object.id]);
+ }, [object.cache.boundingBox]);
const yawRef = useRef(0);
const pitchRef = useRef(0);
@@ -69,9 +69,11 @@ export const PlayerObjectView = observer(function ({ object, objectType }: Playe
useEffect(() => {
const canvas = gl.domElement;
- const onClick = () => { if (document.pointerLockElement !== canvas) canvas.requestPointerLock()?.catch(() => {}); };
+ const onClick = () => { if (document.pointerLockElement !== canvas)
+canvas.requestPointerLock()?.catch(() => {}); };
const onMouseMove = (e: MouseEvent) => {
- if (document.pointerLockElement !== canvas) return;
+ if (document.pointerLockElement !== canvas)
+return;
mouseRef.current.x += e.movementX;
mouseRef.current.y += e.movementY;
};
@@ -85,12 +87,16 @@ export const PlayerObjectView = observer(function ({ object, objectType }: Playe
useBeforePhysicsStep((world) => {
const rb = handleRef.current?.rb;
- if (!rb) return;
+ if (!rb)
+return;
const collider = rb.collider(0);
- if (!collider) return;
+ if (!collider)
+return;
const controller = controllerRef.current;
- if (!controller) return;
- if (state.game?.isPaused) return;
+ if (!controller)
+return;
+ if (state.game?.isPaused)
+return;
const dt = world.timestep;
const yaw = yawRef.current;
@@ -128,7 +134,8 @@ export const PlayerObjectView = observer(function ({ object, objectType }: Playe
useFrame(({ camera }, delta) => {
const rb = handleRef.current?.rb;
- if (!rb) return;
+ if (!rb)
+return;
mouseRef.current.x += joystickValues.look.x * LOOK_RATE * delta;
mouseRef.current.y += -joystickValues.look.y * LOOK_RATE * delta;
diff --git a/src/components/LeftPanel.tsx b/src/components/LeftPanel.tsx
index 5c7cd1a..22a38c3 100644
--- a/src/components/LeftPanel.tsx
+++ b/src/components/LeftPanel.tsx
@@ -24,5 +24,5 @@ export const LeftPanel = observer(function () {
{/* */}
-
+ ;
});
diff --git a/src/components/MainPanel.tsx b/src/components/MainPanel.tsx
index 180fc78..8bb4fe5 100644
--- a/src/components/MainPanel.tsx
+++ b/src/components/MainPanel.tsx
@@ -26,5 +26,5 @@ export const MainPanel = observer(function () {
{objectType?.name} ({objects.length} object{objects.length > 1 ? 's' : ''})
-
+ ;
});
diff --git a/src/components/ObjectEditorView.tsx b/src/components/ObjectEditorView.tsx
index cd2204a..6f814aa 100644
--- a/src/components/ObjectEditorView.tsx
+++ b/src/components/ObjectEditorView.tsx
@@ -36,7 +36,7 @@ const SelectionOverlay = observer(function ({ objectId, ref, onTransformEnd }: S
[ref],
);
- useHelper(isSelected ? groupRef : { current: null } as any, BoxHelper, 'white');
+ useHelper(isSelected ? groupRef : { current: null }, BoxHelper, 'white');
if (!isSelected || selectionMode === undefined || !groupRef.current)
return null;
diff --git a/src/components/ObjectViewInternal.tsx b/src/components/ObjectViewInternal.tsx
index 32c12e8..1b6d014 100644
--- a/src/components/ObjectViewInternal.tsx
+++ b/src/components/ObjectViewInternal.tsx
@@ -30,7 +30,8 @@ export const ObjectViewInternal = function ({ object, objectType, ref, ...props
useEffect(
() => {
- if (props.isPlayer) return;
+ if (props.isPlayer)
+ return;
return reaction(
() => 'version' in object ? object.version : 0,
() => {
@@ -53,19 +54,20 @@ export const ObjectViewInternal = function ({ object, objectType, ref, ...props
},
);
},
- [object.id]
+ [object, object.id, props.isPlayer]
);
+
+ const gameObj = object as RuntimeGameObjectInstance;
useEffect(
() => {
- const gameObj = object as RuntimeGameObjectInstance;
-
return reaction(
() => gameObj.pendingActions.impulse,
(impulse) => {
if (!impulse || !rbRef.current)
return;
+ // eslint-disable-next-line prefer-const
let { direction, amplitude } = impulse;
amplitude *= 100;
const v = { x: direction[0] * amplitude, y: direction[1] * amplitude, z: direction[2] * amplitude };
@@ -76,7 +78,7 @@ export const ObjectViewInternal = function ({ object, objectType, ref, ...props
},
);
},
- [object.id]
+ [gameObj.pendingActions, object.id]
);
function handleClick(e: ThreeEvent) {
@@ -126,4 +128,4 @@ export const ObjectViewInternal = function ({ object, objectType, ref, ...props
);
-}
+};
diff --git a/src/components/Panel.tsx b/src/components/Panel.tsx
index dc8f69f..ec68b85 100644
--- a/src/components/Panel.tsx
+++ b/src/components/Panel.tsx
@@ -9,5 +9,5 @@ export type PanelProps = {
export const Panel = observer(function ({ children, side = 'left' }: PanelProps) {
return
{children}
-
+ ;
});
diff --git a/src/components/Panels.tsx b/src/components/Panels.tsx
index 6ad2ad7..c94eadf 100644
--- a/src/components/Panels.tsx
+++ b/src/components/Panels.tsx
@@ -8,5 +8,5 @@ export const Panels = observer(function () {
return
-
+ ;
});
diff --git a/src/components/RenderInfoView.tsx b/src/components/RenderInfoView.tsx
index 505e813..89c45c3 100644
--- a/src/components/RenderInfoView.tsx
+++ b/src/components/RenderInfoView.tsx
@@ -9,7 +9,8 @@ export const RenderInfoView = observer(function () {
useEffect(() => {
const el = containerRef.current;
- if (!el) return;
+ if (!el)
+return;
el.appendChild(chartRef.current);
return () => { el.removeChild(chartRef.current); };
}, []);
@@ -25,5 +26,5 @@ export const RenderInfoView = observer(function () {
textures: {info.textures}
)}
- >
+ >;
});
diff --git a/src/components/ThreeView.tsx b/src/components/ThreeView.tsx
index a388325..46bd914 100644
--- a/src/components/ThreeView.tsx
+++ b/src/components/ThreeView.tsx
@@ -1,6 +1,5 @@
-import { Canvas, useFrame, useThree } from '@react-three/fiber';
+import { Canvas } from '@react-three/fiber';
import { KeyboardControls, Stats } from '@react-three/drei';
-import { action } from 'mobx';
import { chartRef } from './chartRef';
import { observer } from 'mobx-react-lite';
import { state } from '../state';
@@ -9,23 +8,7 @@ import { SceneEditorView } from './SceneEditorView';
import { JoystickView } from './JoystickView';
import type { RefObject } from 'react';
import { IconPlayerPlayFilled, IconPlayerPauseFilled, IconPlayerStopFilled } from '@tabler/icons-react';
-
-function RenderInfoUpdater() {
- const { gl } = useThree();
- useFrame(action(() => {
- const { calls, triangles } = gl.info.render;
- const shaders = gl.info.programs?.length ?? 0;
- const { geometries, textures } = gl.info.memory;
- state.setRenderInfo({
- calls,
- triangles,
- shaders,
- geometries,
- textures,
- });
- }));
- return null;
-}
+import { RenderInfoUpdater } from './renderInfo';
export const ThreeView = observer(function () {
const isGame = !!state.game;
@@ -63,5 +46,5 @@ export const ThreeView = observer(function () {
- )
+ );
});
diff --git a/src/components/renderInfo.tsx b/src/components/renderInfo.tsx
new file mode 100644
index 0000000..d9ff861
--- /dev/null
+++ b/src/components/renderInfo.tsx
@@ -0,0 +1,20 @@
+import { useFrame, useThree } from "@react-three/fiber";
+import { state } from "../state";
+import { action } from "mobx";
+
+export function RenderInfoUpdater() {
+ const { gl } = useThree();
+ useFrame(action(() => {
+ const { calls, triangles } = gl.info.render;
+ const shaders = gl.info.programs?.length ?? 0;
+ const { geometries, textures } = gl.info.memory;
+ state.setRenderInfo({
+ calls,
+ triangles,
+ shaders,
+ geometries,
+ textures,
+ });
+ }));
+ return null;
+}
diff --git a/src/components/scriptEditor/ScriptEditorView.tsx b/src/components/scriptEditor/ScriptEditorView.tsx
index 42896fd..c181ab9 100644
--- a/src/components/scriptEditor/ScriptEditorView.tsx
+++ b/src/components/scriptEditor/ScriptEditorView.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef } from "react";
+import { useEffect, useLayoutEffect, useRef } from "react";
import { observer } from "mobx-react-lite";
import { runInAction } from "mobx";
import * as Blockly from "blockly";
@@ -68,10 +68,11 @@ export const ScriptEditorView = observer(function ({ objectType }: ScriptEditorV
const containerRef = useRef(null);
const workspaceRef = useRef(null);
const objectTypeRef = useRef(objectType);
- objectTypeRef.current = objectType;
+ useLayoutEffect(() => { objectTypeRef.current = objectType; });
useEffect(() => {
- if (!containerRef.current) return;
+ if (!containerRef.current)
+ return;
const workspace = Blockly.inject(containerRef.current, { toolbox: TOOLBOX, theme: gameTheme });
workspaceRef.current = workspace;
@@ -116,11 +117,12 @@ export const ScriptEditorView = observer(function ({ objectType }: ScriptEditorV
workspace.dispose();
workspaceRef.current = null;
};
- }, []);
+ }, [objectType.program]);
useEffect(() => {
const workspace = workspaceRef.current;
- if (!workspace) return;
+ if (!workspace)
+ return;
try {
Blockly.Events.disable();
@@ -132,7 +134,7 @@ export const ScriptEditorView = observer(function ({ objectType }: ScriptEditorV
} finally {
Blockly.Events.enable();
}
- }, [objectType.id]);
+ }, [objectType.id, objectType.program]);
return
diff --git a/src/components/voxelEditor/VoxelEditorPage.tsx b/src/components/voxelEditor/VoxelEditorPage.tsx
index 7cbcd96..fbc82af 100644
--- a/src/components/voxelEditor/VoxelEditorPage.tsx
+++ b/src/components/voxelEditor/VoxelEditorPage.tsx
@@ -32,7 +32,8 @@ export const VoxelEditorPage = observer(function () {
useEffect(() => {
return () => {
- if (id) state.worldEditor.refreshObjectTypeCaches(id);
+ if (id)
+state.worldEditor.refreshObjectTypeCaches(id);
};
}, [id]);
diff --git a/src/main.tsx b/src/main.tsx
index 0d14946..4f416ec 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,10 +1,10 @@
-import { StrictMode } from 'react'
-import { createRoot } from 'react-dom/client'
-import { App } from './App.tsx'
-import './index.scss'
+import { StrictMode } from 'react';
+import { createRoot } from 'react-dom/client';
+import { App } from './App.tsx';
+import './index.scss';
createRoot(document.getElementById('root')!).render(
,
-)
+);
diff --git a/src/model/GameScheduler.ts b/src/model/GameScheduler.ts
index 637237b..02cd33b 100644
--- a/src/model/GameScheduler.ts
+++ b/src/model/GameScheduler.ts
@@ -15,8 +15,10 @@ export class GameScheduler {
tick(deltaTime: number): void {
const next: Coroutine[] = [];
for (const co of this.coroutines) {
- if (this.isReady(co)) this.step(co, next);
- else next.push(this.countdown(co, deltaTime));
+ if (this.isReady(co))
+this.step(co, next);
+ else
+next.push(this.countdown(co, deltaTime));
}
this.coroutines = next;
}
@@ -47,7 +49,8 @@ export class GameScheduler {
private step(co: Coroutine, list: Coroutine[]): void {
const result = co.gen.next();
- if (!result.done) list.push(this.make(co.gen, result.value));
+ if (!result.done)
+list.push(this.make(co.gen, result.value));
}
private make(gen: Generator
, cmd: YieldCommand): Coroutine {
diff --git a/src/model/defaultVoxelTypes.ts b/src/model/defaultVoxelTypes.ts
index ac87511..8c90aee 100644
--- a/src/model/defaultVoxelTypes.ts
+++ b/src/model/defaultVoxelTypes.ts
@@ -37,6 +37,6 @@ export const DEFAULT_VOXEL_TYPES = {
[dirt.id]: dirt,
[water.id]: water,
[glass.id]: glass,
-}
+};
export const DEFAULT_VOXEL_TYPE = stone;
diff --git a/src/model/gameFactory.ts b/src/model/gameFactory.ts
index 2653fc3..82fc9b0 100644
--- a/src/model/gameFactory.ts
+++ b/src/model/gameFactory.ts
@@ -1,9 +1,9 @@
import type { Game, RuntimeGameScene, RuntimeScene, World } from "../types";
-import type { GameEventContext, GameEventHandler, InternalGameEventBus } from "../types/runtime/gameBus";
+import type { GameEventContext, GameEventHandler, GeneratorEventHandler, InternalGameEventBus } from "../types/runtime/gameBus";
import { clone } from "../utils";
import { populateRuntimeScene } from "../utils/runtime";
import { ObjectApi } from "../utils/runtime/objectApi";
-import type { GameScheduler, YieldCommand } from "./GameScheduler";
+import type { GameScheduler, YieldCommand } from "./gameScheduler";
export class GameEventBus {
private handlers = new Map();
@@ -70,7 +70,7 @@ export class GameFactory {
scheduler: GameScheduler,
): void {
- const handlerWrappers = new WeakMap void>();
+ const handlerWrappers = new WeakMap();
const wait = (seconds: number): YieldCommand => ({ type: 'waitSeconds', seconds });
const waitFrames = (frames: number): YieldCommand => ({ type: 'waitFrames', frames });
@@ -102,11 +102,11 @@ export class GameFactory {
.forEach((o) => {
const api = new ObjectApi(o, ot, world, scene);
gameScript({ ...internalBus, wait, waitFrames, waitUntil }, { api, object: o, objectType: ot });
- })
+ });
});
}
catch (err) {
- console.log('Error running game script:\n' + err)
+ console.log('Error running game script:\n' + err);
}
}
}
diff --git a/src/state/gameState.ts b/src/state/gameState.ts
index b558dfa..1a11b5b 100644
--- a/src/state/gameState.ts
+++ b/src/state/gameState.ts
@@ -3,7 +3,7 @@ import type { WorldState } from "./worldState";
import type { Game, Pos3, RuntimeGameScene } from "../types";
import type { CameraProps } from "@react-three/fiber";
import { GameEventBus, GameFactory } from "../model/gameFactory";
-import { GameScheduler } from "../model/GameScheduler";
+import { GameScheduler } from "../model/gameScheduler";
import type { GameEventContext } from "../types/runtime/gameBus";
export class GameState {
@@ -25,8 +25,7 @@ export class GameState {
);
}
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- // @ts-ignore
+ // @ts-expect-error -- for future use
private withoutAutoSave(fn: () => void) {
this._stopAutoSave();
fn();
@@ -72,7 +71,7 @@ export class GameState {
paused: toJS(this.isPaused),
time: toJS(this.time),
scene: toJS(this.scene),
- }
+ };
}
public setGame(value: Game) {
@@ -95,7 +94,7 @@ export class GameState {
position: cam.position,
fov: 50,
rotation: cam.look,
- }
+ };
}
// public load() {
diff --git a/src/state/menuState.tsx b/src/state/menuState.tsx
index 66a2bf4..031ddb9 100644
--- a/src/state/menuState.tsx
+++ b/src/state/menuState.tsx
@@ -61,7 +61,7 @@ export class MenuState {
>,
className: isPlayer ? 'player-controlled-object' : undefined,
actions,
- onClick: () => { state.worldEditor.setSelectedObject({ id: o.id, editMode: 'translate' }) },
+ onClick: () => { state.worldEditor.setSelectedObject({ id: o.id, editMode: 'translate' }); },
selected: () => state.worldEditor.selection?.type === 'object' && state.worldEditor.selection?.id === o.id,
} as MenuNode;
});
@@ -89,10 +89,10 @@ export class MenuState {
onClick: () => { editor.deleteObjectType(ot.id); },
},
],
- onClick: () => { editor.setSelectedObjectType({ id: ot.id, editMode: 'scripts' }) },
+ onClick: () => { editor.setSelectedObjectType({ id: ot.id, editMode: 'scripts' }); },
selected: () => editor.selection?.type === 'objectType' && editor.selection?.id === ot.id,
children,
- } as MenuNode
+ } as MenuNode;
});
}
@@ -101,7 +101,7 @@ export class MenuState {
{
id: 'editor-scene-menu',
title: 'Scene',
- onClick: () => { state.worldEditor.resetSelection() },
+ onClick: () => { state.worldEditor.resetSelection(); },
selected: () => !state.worldEditor.selection,
children: this.editorObjectTypesMenu,
actions: [{
@@ -111,13 +111,13 @@ export class MenuState {
onClick: () => { state.worldEditor.addObjectType(); },
}],
}
- ]
+ ];
}
public get nodes(): MenuNode[] {
return [
...this.editorMenu,
- ]
+ ];
}
public nodeContainsSelected(node: MenuNode): boolean {
diff --git a/src/state/worldEditorState.ts b/src/state/worldEditorState.ts
index b4a6dc5..61a30ed 100644
--- a/src/state/worldEditorState.ts
+++ b/src/state/worldEditorState.ts
@@ -165,33 +165,39 @@ export class WorldEditorState {
public addVoxelToObjectType(typeId: string, voxel: Voxel): void {
const objectType = this.world.getObjectTypeById(typeId);
- if (!objectType) return;
+ if (!objectType)
+return;
const occupied = objectType.voxels.some(v =>
v.position[0] === voxel.position[0] &&
v.position[1] === voxel.position[1] &&
v.position[2] === voxel.position[2]
);
- if (!occupied) objectType.voxels.push(voxel);
+ if (!occupied)
+objectType.voxels.push(voxel);
}
public removeVoxelFromObjectType(typeId: string, position: V3): void {
const objectType = this.world.getObjectTypeById(typeId);
- if (!objectType) return;
+ if (!objectType)
+return;
const idx = objectType.voxels.findIndex(v =>
v.position[0] === position[0] &&
v.position[1] === position[1] &&
v.position[2] === position[2]
);
- if (idx !== -1) objectType.voxels.splice(idx, 1);
+ if (idx !== -1)
+objectType.voxels.splice(idx, 1);
}
public refreshObjectTypeCaches(typeId: string): void {
const objectType = this.world.getObjectTypeById(typeId);
- if (!objectType) return;
+ if (!objectType)
+return;
const world = this.world.data;
const now = Date.now();
for (const obj of Object.values(this.scene.objects)) {
- if (obj.typeId !== typeId) continue;
+ if (obj.typeId !== typeId)
+continue;
obj.cache.voxelGroups = getObjectVoxelGroups(objectType, world.voxelTypes);
obj.cache.colliderMesh = buildObjectTrimesh(objectType, world.voxelTypes);
obj.cache.boundingBox = computeBoundingBox(objectType);
@@ -207,7 +213,7 @@ export class WorldEditorState {
if (this.scene.objects[id].typeId === typeId)
this.deleteObject(id);
- delete (this.world.data.objectTypes[typeId])
+ delete (this.world.data.objectTypes[typeId]);
}
}
diff --git a/src/state/worldState.ts b/src/state/worldState.ts
index b0593db..9c1da66 100644
--- a/src/state/worldState.ts
+++ b/src/state/worldState.ts
@@ -51,7 +51,7 @@ export class WorldState {
} as ObjectInstance));
const objectMap = Object.fromEntries(
objects.map((obj) => [obj.id, obj]),
- ) as Record
+ ) as Record;
this.data = populateRuntimeWorld({
objectTypes: {
@@ -106,7 +106,7 @@ export class WorldState {
private saveData(data: World): void {
console.log('Saving world...');
const stack = new Error('Saving world...').stack!.split('\n').slice(1);
- const { voxelTypes, initialScene, ...debug } = toJS(data);
+ const { voxelTypes: _vts, initialScene: _is, ...debug } = toJS(data);
console.dir({ stack, debug });
WorldFactory.save(toJS(this.data));
}
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 5b71639..501c67f 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -15,5 +15,5 @@ export function v3toRapier(value: V3): Vector3Object {
x: value[0],
y: value[1],
z: value[2],
- }
+ };
}
diff --git a/src/utils/runtime/object.ts b/src/utils/runtime/object.ts
index eb12c76..4fcea2d 100644
--- a/src/utils/runtime/object.ts
+++ b/src/utils/runtime/object.ts
@@ -34,6 +34,6 @@ export function populateRuntimeObject(object: ObjectInstance, world: World): Run
}
export function depopulateRuntimeObject(object: RuntimeObjectInstance, _world: World): ObjectInstance {
- const { cache, ...result } = object;
+ const { cache: _cache, ...result } = object;
return result;
}
diff --git a/src/utils/runtime/objectApi.ts b/src/utils/runtime/objectApi.ts
index 109ed13..e0953f0 100644
--- a/src/utils/runtime/objectApi.ts
+++ b/src/utils/runtime/objectApi.ts
@@ -24,7 +24,8 @@ export class ObjectApi {
const dy = targetPosition[1] - py;
const dz = targetPosition[2] - pz;
const len = Math.sqrt(dx * dx + dy * dy + dz * dz);
- if (len < 1e-6) return;
+ if (len < 1e-6)
+ return;
const direction: V3 = [dx / len, dy / len, dz / len];
this.object.pendingActions.impulse = { direction, amplitude };
}
diff --git a/src/utils/runtime/scene.ts b/src/utils/runtime/scene.ts
index 11f59a1..802c587 100644
--- a/src/utils/runtime/scene.ts
+++ b/src/utils/runtime/scene.ts
@@ -5,12 +5,12 @@ export function populateRuntimeScene(scene: Scene, world: World): RuntimeScene {
return {
...scene,
objects: Object.fromEntries(Object.entries(scene.objects).map(([id, obj]) => [id, populateRuntimeObject(obj, world)])),
- }
+ };
}
export function depopulateRuntimeScene(scene: RuntimeScene, world: World): Scene {
return {
...scene,
objects: Object.fromEntries(Object.entries(scene.objects).map(([id, obj]) => [id, depopulateRuntimeObject(obj, world)])),
- }
+ };
}
diff --git a/vite.config.ts b/vite.config.ts
index 8b0f57b..4a5def4 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,7 +1,7 @@
-import { defineConfig } from 'vite'
-import react from '@vitejs/plugin-react'
+import { defineConfig } from 'vite';
+import react from '@vitejs/plugin-react';
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
-})
+});