refactor: clean architecture and remove unused code
This commit is contained in:
@@ -9,6 +9,10 @@ interface StoredDebugControls {
|
||||
sceneMode: SceneMode;
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
function isCameraMode(value: unknown): value is CameraMode {
|
||||
return value === "player" || value === "debug";
|
||||
}
|
||||
@@ -22,7 +26,8 @@ function getStoredDebugControls(): Partial<StoredDebugControls> {
|
||||
const rawValue = window.localStorage.getItem(DEBUG_CONTROLS_STORAGE_KEY);
|
||||
if (!rawValue) return {};
|
||||
|
||||
const parsedValue = JSON.parse(rawValue) as Partial<StoredDebugControls>;
|
||||
const parsedValue: unknown = JSON.parse(rawValue);
|
||||
if (!isRecord(parsedValue)) return {};
|
||||
|
||||
return {
|
||||
...(isCameraMode(parsedValue.cameraMode)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { MapNode } from "@/types/editor/editor";
|
||||
import type { MapNode } from "../../types/editor/editor";
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
function isVector3Tuple(value: unknown): value is [number, number, number] {
|
||||
return (
|
||||
@@ -8,18 +12,17 @@ function isVector3Tuple(value: unknown): value is [number, number, number] {
|
||||
);
|
||||
}
|
||||
|
||||
export function isMapNode(value: unknown): value is MapNode {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
function isMapNode(value: unknown): value is MapNode {
|
||||
if (!isRecord(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const node = value as Record<string, unknown>;
|
||||
return (
|
||||
typeof node.name === "string" &&
|
||||
typeof node.type === "string" &&
|
||||
isVector3Tuple(node.position) &&
|
||||
isVector3Tuple(node.rotation) &&
|
||||
isVector3Tuple(node.scale)
|
||||
typeof value.name === "string" &&
|
||||
typeof value.type === "string" &&
|
||||
isVector3Tuple(value.position) &&
|
||||
isVector3Tuple(value.rotation) &&
|
||||
isVector3Tuple(value.scale)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,10 @@ export class ExplodedModel {
|
||||
}
|
||||
|
||||
private createParts(model: THREE.Object3D): ExplodedPart[] {
|
||||
const root = model.children.length === 1 ? model.children[0] : model;
|
||||
const root =
|
||||
model.children.length === 1 && model.children[0]
|
||||
? model.children[0]
|
||||
: model;
|
||||
const directChildren = root.children.filter((child) => hasMesh(child));
|
||||
const sourceObjects =
|
||||
directChildren.length > 1 ? directChildren : getMeshes(root);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { Vector3Scale, Vector3Tuple } from "@/types/three/three";
|
||||
|
||||
export function toVector3Scale(scale: Vector3Scale): Vector3Tuple {
|
||||
return typeof scale === "number" ? [scale, scale, scale] : scale;
|
||||
}
|
||||
Reference in New Issue
Block a user