diff --git a/.gitignore b/.gitignore index 72bfa4c..4746b85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ node_modules/ +dist/ *.env \ No newline at end of file diff --git a/package.json b/package.json index 926467b..5a18729 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "type": "module", "scripts": { - "start:ui": "vite preview --host --port 4000", + "start:ui": "vite preview --host --port 3000", "start:server": "NODE_ENV=production tsx ./src/server/main.ts", "build:ui": "vite build", "dev:ui": "vite --host", diff --git a/src/App.vue b/src/App.vue index de8295f..66d6827 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,9 +2,6 @@
-
- Verbindung wird hergestellt… -
diff --git a/src/game.ts b/src/game.ts index f39acbd..be3a99e 100644 --- a/src/game.ts +++ b/src/game.ts @@ -64,6 +64,7 @@ export const useGame = defineStore("gameState", () => { trpcClient.director.setObjectVisibility.mutate({ id, isVisible }) }, handleGameEvent(event: GameEvent) { + console.log(event) switch (event.type) { case "room-changed": currentInteraction.value = null diff --git a/src/screens/InteractionsScreen.vue b/src/screens/InteractionsScreen.vue index 9659781..f59b4ae 100644 --- a/src/screens/InteractionsScreen.vue +++ b/src/screens/InteractionsScreen.vue @@ -16,7 +16,7 @@ @object-drop="onObjectInteractionDrop" />
- + () - const objectsContainerScrollLock = useScrollLock(objectsContainerElement) const useFloatingObjectIds = reactive(new Set()) const combineFloatingObjectIds = reactive(new Set()) @@ -84,7 +82,9 @@ function onObjectDragEnd() { dragCounter.value-- - if (dragCounter.value <= 0) objectsContainerScrollLock.value = false + if (dragCounter.value <= 0) { + // lock scrolling? + } } function onObjectUseDrop(objectId: string) { diff --git a/src/server/game.ts b/src/server/game.ts index c3ba59f..bcdd539 100644 --- a/src/server/game.ts +++ b/src/server/game.ts @@ -11,16 +11,26 @@ interface Events { export class Game extends EventEmitter { private currentRoomId: string = script.roomsById.values().next()!.value!.id private interactionQueue: Map = new Map() + private visibleObjectIds = new Set() constructor() { super() + this.switchRoom(this.currentRoomId) } getInitialStateEvents(): GameEvent[] { const events: GameEvent[] = [] events.push({ type: "room-changed", roomId: this.currentRoomId }) + this.interactionQueue.forEach(item => events.push({ type: "interaction-queued", item })) + script.roomsById.get(this.currentRoomId)!.initialObjects.forEach(o => { + if (!this.visibleObjectIds.has(o.id)) events.push({ type: "object-visibility-changed", id: o.id, isVisible: false }) + }) + + script.roomsById.get(this.currentRoomId)!.hiddenObjects.forEach(o => { + if (this.visibleObjectIds.has(o.id)) events.push({ type: "object-visibility-changed", id: o.id, isVisible: true }) + }) return events } @@ -56,6 +66,8 @@ export class Game extends EventEmitter { switchRoom(roomId: string) { this.currentRoomId = roomId this.interactionQueue.clear() + this.visibleObjectIds.clear() + script.roomsById.get(this.currentRoomId)!.initialObjects.forEach(o => this.visibleObjectIds.add(o.id)) this.emit("game-event", { type: "room-changed", roomId }) } @@ -66,7 +78,7 @@ export class Game extends EventEmitter { this.emit("game-event", { type: "interaction-votes-changed", id, votes: 0 }) switch (item.interaction.type) { case "use": - this.emit("game-event", { type: "object-visibility-changed", id: item.interaction.objectId, isVisible: false }) + this.setObjectVisibility(item.interaction.objectId, false) break case "combine": @@ -74,11 +86,11 @@ export class Game extends EventEmitter { if (matchingCombination !== undefined) { matchingCombination.inputs.forEach(input => { - if (input.isConsumed) this.emit("game-event", { type: "object-visibility-changed", id: input.objectId, isVisible: false }) + if (input.isConsumed) this.setObjectVisibility(input.objectId, false) }) matchingCombination.outputIds.forEach(outputId => { - this.emit("game-event", { type: "object-visibility-changed", id: outputId, isVisible: true }) + this.setObjectVisibility(outputId, true) }) } @@ -93,6 +105,9 @@ export class Game extends EventEmitter { } setObjectVisibility(id: string, isVisible: boolean) { + if (isVisible) this.visibleObjectIds.add(id) + else this.visibleObjectIds.delete(id) + this.emit("game-event", { type: "object-visibility-changed", id, isVisible }) } } diff --git a/src/server/main.ts b/src/server/main.ts index 04ce823..f5685c2 100644 --- a/src/server/main.ts +++ b/src/server/main.ts @@ -14,7 +14,7 @@ expressApp.use("/trpc", createTrpcMiddleware({ createContext: ({ req, res }) => createContext(res), })) -const { server } = await listen(expressApp, { isProd: !isDev, autoClose: false }) +const { server } = await listen(expressApp, { isProd: !isDev, autoClose: false, port: 3001 }) const wss = new WebSocketServer({ server, path: "/ws" }) const wssTrpcHandler = applyWSSHandler({ diff --git a/vite.config.ts b/vite.config.ts index d175473..59639e7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,10 +10,11 @@ export default defineConfig({ windiPlugin() ], server: { + port: 3000, proxy: { - "/trpc": "http://localhost:3000", + "/trpc": "http://localhost:3001", "/ws": { - target: "http://localhost:3000", + target: "http://localhost:3001", ws: true } }