commit 06
This commit is contained in:
parent
58e60e4da4
commit
3c22d4656e
8 changed files with 32 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
.idea/
|
.idea/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
dist/
|
||||||
*.env
|
*.env
|
|
@ -3,7 +3,7 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"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",
|
"start:server": "NODE_ENV=production tsx ./src/server/main.ts",
|
||||||
"build:ui": "vite build",
|
"build:ui": "vite build",
|
||||||
"dev:ui": "vite --host",
|
"dev:ui": "vite --host",
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
<div class="bg-gray-900 h-[100dvh] overflow-hidden text-white">
|
<div class="bg-gray-900 h-[100dvh] overflow-hidden text-white">
|
||||||
<div :class="$style.noise"/>
|
<div :class="$style.noise"/>
|
||||||
<div :class="$style.vignette"/>
|
<div :class="$style.vignette"/>
|
||||||
<div v-if="isLoading" class="flex flex-col justify-center items-center text-lg inset-0 absolute">
|
|
||||||
<span class="text-center">Verbindung wird hergestellt…</span>
|
|
||||||
</div>
|
|
||||||
<div class="h-full relative flex flex-col">
|
<div class="h-full relative flex flex-col">
|
||||||
<nav class="mx-auto p-4 flex gap-4 overflow-x-auto max-w-full">
|
<nav class="mx-auto p-4 flex gap-4 overflow-x-auto max-w-full">
|
||||||
<div class="flex-shrink-0 flex items-center rounded-lg bg-dark-400 overflow-hidden">
|
<div class="flex-shrink-0 flex items-center rounded-lg bg-dark-400 overflow-hidden">
|
||||||
|
@ -28,6 +25,9 @@
|
||||||
</transition>
|
</transition>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex flex-col justify-center items-center text-lg inset-0 absolute bg-dark-900 transition" :class="!isLoading && 'opacity-0 pointer-events-none'">
|
||||||
|
<span class="text-center">Verbindung wird hergestellt…</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ export const useGame = defineStore("gameState", () => {
|
||||||
trpcClient.director.setObjectVisibility.mutate({ id, isVisible })
|
trpcClient.director.setObjectVisibility.mutate({ id, isVisible })
|
||||||
},
|
},
|
||||||
handleGameEvent(event: GameEvent) {
|
handleGameEvent(event: GameEvent) {
|
||||||
|
console.log(event)
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case "room-changed":
|
case "room-changed":
|
||||||
currentInteraction.value = null
|
currentInteraction.value = null
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
@object-drop="onObjectInteractionDrop"
|
@object-drop="onObjectInteractionDrop"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<transition-group tag="div" name="list" ref="objectsContainerElement" class="grid gap-3 grid-cols-2 flex-grow auto-rows-min p-4 pt-0 relative">
|
<transition-group tag="div" name="list" class="grid gap-3 grid-cols-2 flex-grow auto-rows-min p-4 pt-0 relative">
|
||||||
<ObjectCard
|
<ObjectCard
|
||||||
v-for="object in game.visibleObjectsById.values()"
|
v-for="object in game.visibleObjectsById.values()"
|
||||||
:key="object.id"
|
:key="object.id"
|
||||||
|
@ -44,8 +44,6 @@
|
||||||
const game = useGame()
|
const game = useGame()
|
||||||
|
|
||||||
const dragCounter = ref(0)
|
const dragCounter = ref(0)
|
||||||
const objectsContainerElement = ref<HTMLElement>()
|
|
||||||
const objectsContainerScrollLock = useScrollLock(objectsContainerElement)
|
|
||||||
|
|
||||||
const useFloatingObjectIds = reactive(new Set())
|
const useFloatingObjectIds = reactive(new Set())
|
||||||
const combineFloatingObjectIds = reactive(new Set())
|
const combineFloatingObjectIds = reactive(new Set())
|
||||||
|
@ -84,7 +82,9 @@
|
||||||
|
|
||||||
function onObjectDragEnd() {
|
function onObjectDragEnd() {
|
||||||
dragCounter.value--
|
dragCounter.value--
|
||||||
if (dragCounter.value <= 0) objectsContainerScrollLock.value = false
|
if (dragCounter.value <= 0) {
|
||||||
|
// lock scrolling?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onObjectUseDrop(objectId: string) {
|
function onObjectUseDrop(objectId: string) {
|
||||||
|
|
|
@ -11,16 +11,26 @@ interface Events {
|
||||||
export class Game extends EventEmitter<Events> {
|
export class Game extends EventEmitter<Events> {
|
||||||
private currentRoomId: string = script.roomsById.values().next()!.value!.id
|
private currentRoomId: string = script.roomsById.values().next()!.value!.id
|
||||||
private interactionQueue: Map<string, InteractionQueueItem> = new Map()
|
private interactionQueue: Map<string, InteractionQueueItem> = new Map()
|
||||||
|
private visibleObjectIds = new Set<string>()
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
|
this.switchRoom(this.currentRoomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
getInitialStateEvents(): GameEvent[] {
|
getInitialStateEvents(): GameEvent[] {
|
||||||
const events: GameEvent[] = []
|
const events: GameEvent[] = []
|
||||||
|
|
||||||
events.push({ type: "room-changed", roomId: this.currentRoomId })
|
events.push({ type: "room-changed", roomId: this.currentRoomId })
|
||||||
|
|
||||||
this.interactionQueue.forEach(item => events.push({ type: "interaction-queued", item }))
|
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
|
return events
|
||||||
}
|
}
|
||||||
|
@ -56,6 +66,8 @@ export class Game extends EventEmitter<Events> {
|
||||||
switchRoom(roomId: string) {
|
switchRoom(roomId: string) {
|
||||||
this.currentRoomId = roomId
|
this.currentRoomId = roomId
|
||||||
this.interactionQueue.clear()
|
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 })
|
this.emit("game-event", { type: "room-changed", roomId })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +78,7 @@ export class Game extends EventEmitter<Events> {
|
||||||
this.emit("game-event", { type: "interaction-votes-changed", id, votes: 0 })
|
this.emit("game-event", { type: "interaction-votes-changed", id, votes: 0 })
|
||||||
switch (item.interaction.type) {
|
switch (item.interaction.type) {
|
||||||
case "use":
|
case "use":
|
||||||
this.emit("game-event", { type: "object-visibility-changed", id: item.interaction.objectId, isVisible: false })
|
this.setObjectVisibility(item.interaction.objectId, false)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "combine":
|
case "combine":
|
||||||
|
@ -74,11 +86,11 @@ export class Game extends EventEmitter<Events> {
|
||||||
|
|
||||||
if (matchingCombination !== undefined) {
|
if (matchingCombination !== undefined) {
|
||||||
matchingCombination.inputs.forEach(input => {
|
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 => {
|
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<Events> {
|
||||||
}
|
}
|
||||||
|
|
||||||
setObjectVisibility(id: string, isVisible: boolean) {
|
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 })
|
this.emit("game-event", { type: "object-visibility-changed", id, isVisible })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ expressApp.use("/trpc", createTrpcMiddleware({
|
||||||
createContext: ({ req, res }) => createContext(res),
|
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 wss = new WebSocketServer({ server, path: "/ws" })
|
||||||
const wssTrpcHandler = applyWSSHandler({
|
const wssTrpcHandler = applyWSSHandler({
|
||||||
|
|
|
@ -10,10 +10,11 @@ export default defineConfig({
|
||||||
windiPlugin()
|
windiPlugin()
|
||||||
],
|
],
|
||||||
server: {
|
server: {
|
||||||
|
port: 3000,
|
||||||
proxy: {
|
proxy: {
|
||||||
"/trpc": "http://localhost:3000",
|
"/trpc": "http://localhost:3001",
|
||||||
"/ws": {
|
"/ws": {
|
||||||
target: "http://localhost:3000",
|
target: "http://localhost:3001",
|
||||||
ws: true
|
ws: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue