draft wall builder

This commit is contained in:
wass08
2026-01-16 13:58:01 +09:00
parent 1b954d3416
commit 536c2e94cc
11 changed files with 225 additions and 16 deletions
+4 -2
View File
@@ -1,5 +1,5 @@
import mitt from "mitt";
import { ItemNode, WallNode } from "../schema";
import { BuildingNode, ItemNode, WallNode } from "../schema";
import { AnyNode } from "../schema/types";
// Base event interfaces
@@ -16,6 +16,7 @@ export interface NodeEvent<T extends AnyNode = AnyNode> {
export type WallEvent = NodeEvent<WallNode>;
export type ItemEvent = NodeEvent<ItemNode>;
export type BuildingEvent = NodeEvent<BuildingNode>;
// Event suffixes - exported for use in hooks
export const eventSuffixes = [
@@ -41,6 +42,7 @@ type GridEvents = {
type EditorEvents = GridEvents &
NodeEvents<"wall", WallEvent> &
NodeEvents<"item", ItemEvent>;
NodeEvents<"item", ItemEvent> &
NodeEvents<"building", BuildingEvent>;
export const emitter = mitt<EditorEvents>();
+23
View File
@@ -20,6 +20,8 @@ type SceneState = {
loadScene: () => void;
markDirty: (id: AnyNodeId) => void;
clearDirty: (id: AnyNodeId) => void;
createNode: (node: AnyNode, parentId?: AnyNodeId) => void;
};
const useScene = create<SceneState>()((set, get) => ({
@@ -123,6 +125,27 @@ const useScene = create<SceneState>()((set, get) => ({
clearDirty: (id) => {
get().dirtyNodes.delete(id);
},
createNode: (node, parentId) => {
set((state) => {
const newNodes = { ...state.nodes, [node.id]: node };
if (parentId) {
const parent = state.nodes[parentId];
if (parent) {
newNodes[parentId] = {
...parent,
children: [...parent.children, node.id],
};
}
}
return { nodes: newNodes };
});
get().markDirty(node.id);
if (parentId) get().markDirty(parentId);
}
}));
useScene.getState().loadScene();