From a7199741ae8c804f95d94c8324fb25bc8e955121 Mon Sep 17 00:00:00 2001 From: Nick Kosarev Date: Tue, 11 Jun 2024 12:16:48 +0200 Subject: [PATCH] import fixes --- src/lib/game/actions/plantTreeAction.ts | 2 +- src/lib/game/game.ts | 44 +--------------------- src/lib/game/objects/area.ts | 4 +- src/lib/game/objects/buildings/building.ts | 4 +- src/lib/game/objects/flag.ts | 4 +- src/lib/game/objects/lake.ts | 2 +- src/lib/game/objects/rabbit.ts | 2 +- src/lib/game/objects/stone.ts | 2 +- src/lib/game/objects/units/courier.ts | 6 +-- src/lib/game/objects/units/farmer.ts | 6 +-- src/lib/game/objects/units/trader.ts | 6 +-- src/lib/game/objects/units/unit.ts | 8 ++-- src/lib/game/objects/wagon.ts | 4 +- src/lib/game/objects/wolf.ts | 2 +- src/lib/game/services/routeService.ts | 8 +++- src/lib/server/db/db.repository.ts | 24 ++++++------ src/routes/p/+page.server.ts | 5 ++- src/routes/p/[slug]/+page.server.ts | 4 +- 18 files changed, 51 insertions(+), 86 deletions(-) diff --git a/src/lib/game/actions/plantTreeAction.ts b/src/lib/game/actions/plantTreeAction.ts index b00e6585..1578f8ac 100644 --- a/src/lib/game/actions/plantTreeAction.ts +++ b/src/lib/game/actions/plantTreeAction.ts @@ -1,6 +1,6 @@ import { Village } from "../chunks" import type { Player } from "../objects/units" -import type { GameScene } from "../scenes" +import type { GameScene } from "../scenes/gameScene" import { PlantNewTreeScript } from "../scripts/plantNewTreeScript" import { Action } from "./action" import { ANSWER } from "$lib/game/services/actionService"; diff --git a/src/lib/game/game.ts b/src/lib/game/game.ts index ddb107d4..7b1b785b 100644 --- a/src/lib/game/game.ts +++ b/src/lib/game/game.ts @@ -1,15 +1,13 @@ import { Application, Container } from "pixi.js" import type { IGameObject, - IGameObjectMechanic, IGameObjectPlayer, - IGameObjectRaider, IGameObjectTrader, WebSocketMessage, GameSceneType, } from "$lib/game/types" import { type GameObject, type Wagon } from "./objects" -import { Mechanic, Player, Raider, Trader } from "./objects/units" +import { Player, Trader } from "./objects/units" import type { GameScene } from "./scenes/gameScene" import { MovingScene } from "./scenes/movingScene" import { AssetsManager, AudioManager } from "./utils" @@ -203,30 +201,6 @@ export class Game extends Container { } } - initMechanic(object: IGameObjectMechanic) { - const unit = new Mechanic({ game: this, object }) - this.addChild(unit) - } - - updateMechanic(object: IGameObjectMechanic) { - const unit = this.findObject(object.id) - if (unit instanceof Mechanic) { - unit.update(object) - } - } - - initRaider(object: IGameObjectRaider) { - const raider = new Raider({ game: this, object }) - this.addChild(raider) - } - - updateRaider(object: IGameObjectRaider) { - const raider = this.findObject(object.id) - if (raider instanceof Raider) { - raider.update(object) - } - } - public checkIfThisFlagIsTarget(id: string) { for (const obj of this.children) { if (obj.target?.id === id) { @@ -276,14 +250,6 @@ export class Game extends Container { this.initTrader(object as IGameObjectTrader) return } - if (object.entity === "MECHANIC") { - this.initMechanic(object as IGameObjectMechanic) - return - } - if (object.entity === "RAIDER") { - this.initRaider(object as IGameObjectRaider) - return - } return } @@ -295,14 +261,6 @@ export class Game extends Container { this.updateTrader(object as IGameObjectTrader) return } - if (object.entity === "MECHANIC") { - this.updateMechanic(object as IGameObjectMechanic) - return - } - if (object.entity === "RAIDER") { - this.updateRaider(object as IGameObjectRaider) - return - } } handleMessageEvent(event: WebSocketMessage["event"]) { diff --git a/src/lib/game/objects/area.ts b/src/lib/game/objects/area.ts index e7740d4d..947c3dae 100644 --- a/src/lib/game/objects/area.ts +++ b/src/lib/game/objects/area.ts @@ -1,6 +1,6 @@ import type { IGameObjectArea } from "$lib/game/types" -import type { GameScene } from "../scenes/gameScene.ts" -import { GameObject } from "./gameObject.ts" +import type { GameScene } from "../scenes/gameScene" +import { GameObject } from "./gameObject" interface IAreaOptions { scene: GameScene diff --git a/src/lib/game/objects/buildings/building.ts b/src/lib/game/objects/buildings/building.ts index 8c598669..bb537cc9 100644 --- a/src/lib/game/objects/buildings/building.ts +++ b/src/lib/game/objects/buildings/building.ts @@ -1,8 +1,8 @@ import { createId } from "@paralleldrive/cuid2" import type { IGameObjectBuilding, ItemType, } from "$lib/game/types" import { Inventory } from "../../common" -import type { GameScene } from "../../scenes/gameScene.ts" -import { GameObject } from "../gameObject.ts" +import type { GameScene } from "../../scenes/gameScene" +import { GameObject } from "../gameObject" interface IBuildingOptions { scene: GameScene diff --git a/src/lib/game/objects/flag.ts b/src/lib/game/objects/flag.ts index d5ae99ab..4f5c539f 100644 --- a/src/lib/game/objects/flag.ts +++ b/src/lib/game/objects/flag.ts @@ -1,7 +1,7 @@ import { Sprite } from "pixi.js" import type { IGameObjectFlag } from "$lib/game/types" -import type { GameScene } from "../scenes/gameScene.ts" -import { GameObject } from "./gameObject.ts" +import type { GameScene } from "../scenes/gameScene" +import { GameObject } from "./gameObject" interface IFlagOptions { scene: GameScene diff --git a/src/lib/game/objects/lake.ts b/src/lib/game/objects/lake.ts index 5bc9a3c2..0e7a11bb 100644 --- a/src/lib/game/objects/lake.ts +++ b/src/lib/game/objects/lake.ts @@ -1,6 +1,6 @@ import type { IGameObjectLake } from "$lib/game/types" import { AssetsManager } from "../utils" -import { GameObject } from "./gameObject.ts" +import { GameObject } from "./gameObject" import { GameScene } from "../scenes/gameScene"; import { Water } from "./water"; diff --git a/src/lib/game/objects/rabbit.ts b/src/lib/game/objects/rabbit.ts index 692ba835..dc9c2617 100644 --- a/src/lib/game/objects/rabbit.ts +++ b/src/lib/game/objects/rabbit.ts @@ -1,7 +1,7 @@ import { Sprite } from "pixi.js" import type { IGameObjectRabbit } from "$lib/game/types" import type { Game } from "../game" -import { GameObject } from "./gameObject.ts" +import { GameObject } from "./gameObject" interface IRabbitOptions { game: Game diff --git a/src/lib/game/objects/stone.ts b/src/lib/game/objects/stone.ts index e9d41cf3..d0becc8f 100644 --- a/src/lib/game/objects/stone.ts +++ b/src/lib/game/objects/stone.ts @@ -1,7 +1,7 @@ import { Sprite } from "pixi.js" import { type IGameObjectStone } from "$lib/game/types" import type { GameScene } from "../scenes/gameScene" -import { GameObject } from "./gameObject.ts" +import { GameObject } from "./gameObject" import { getRandomInRange } from "$lib/random"; interface IStoneOptions { diff --git a/src/lib/game/objects/units/courier.ts b/src/lib/game/objects/units/courier.ts index eabc8a6e..e3e0119b 100644 --- a/src/lib/game/objects/units/courier.ts +++ b/src/lib/game/objects/units/courier.ts @@ -1,7 +1,7 @@ import type { IGameObjectCourier } from "$lib/game/types" -import { generateUnitUserName } from "../../common/generators/unitName.ts" -import { generateUnitTop } from "../../common/generators/unitTop.ts" -import type { GameScene } from "../../scenes/gameScene.ts" +import { generateUnitUserName } from "../../common/generators/unitName" +import { generateUnitTop } from "../../common/generators/unitTop" +import type { GameScene } from "../../scenes/gameScene" import { Unit } from "./unit" interface ICourierOptions { diff --git a/src/lib/game/objects/units/farmer.ts b/src/lib/game/objects/units/farmer.ts index decf35f0..afe2aebd 100644 --- a/src/lib/game/objects/units/farmer.ts +++ b/src/lib/game/objects/units/farmer.ts @@ -1,7 +1,7 @@ import type { IGameObjectFarmer } from "$lib/game/types" -import { generateUnitUserName } from "../../common/generators/unitName.ts" -import { generateUnitTop } from "../../common/generators/unitTop.ts" -import type { GameScene } from "../../scenes/gameScene.ts" +import { generateUnitUserName } from "../../common/generators/unitName" +import { generateUnitTop } from "../../common/generators/unitTop" +import type { GameScene } from "../../scenes/gameScene" import { Unit } from "./unit" interface IFarmerOptions { diff --git a/src/lib/game/objects/units/trader.ts b/src/lib/game/objects/units/trader.ts index a54e20d4..9a44737b 100644 --- a/src/lib/game/objects/units/trader.ts +++ b/src/lib/game/objects/units/trader.ts @@ -1,7 +1,7 @@ import type { IGameObjectTrader } from "$lib/game/types" -import { generateUnitUserName } from "../../common/generators/unitName.ts" -import { generateUnitTop } from "../../common/generators/unitTop.ts" -import type { GameScene } from "../../scenes/gameScene.ts" +import { generateUnitUserName } from "../../common/generators/unitName" +import { generateUnitTop } from "../../common/generators/unitTop" +import type { GameScene } from "../../scenes/gameScene" import { Unit } from "./unit" interface ITraderOptions { diff --git a/src/lib/game/objects/units/unit.ts b/src/lib/game/objects/units/unit.ts index 11ecee3e..4e86805e 100644 --- a/src/lib/game/objects/units/unit.ts +++ b/src/lib/game/objects/units/unit.ts @@ -8,12 +8,12 @@ import { UnitHairContainer } from "../../components/unitHairContainer" import { UnitHeadContainer } from "../../components/unitHeadContainer" import { UnitInterface } from "../../components/unitInterface" import { UnitTopContainer } from "../../components/unitTopContainer" -import type { GameScene } from "../../scenes/gameScene.ts" +import type { GameScene } from "../../scenes/gameScene" import { AssetsManager } from "../../utils" import { Flag } from "../flag" -import { GameObject } from "../gameObject.ts" -import { Stone } from "../stone.ts" -import { Tree } from "../tree.ts" +import { GameObject } from "../gameObject" +import { Stone } from "../stone" +import { Tree } from "../tree" import { getRandomInRange } from "$lib/random"; interface IUnitOptions { diff --git a/src/lib/game/objects/wagon.ts b/src/lib/game/objects/wagon.ts index aa680dae..5b9437b8 100644 --- a/src/lib/game/objects/wagon.ts +++ b/src/lib/game/objects/wagon.ts @@ -10,8 +10,8 @@ import { import { WagonEngineContainer } from "../components/wagonEngineContainer" import { WagonFuelBoxContainer } from "../components/wagonFuelBoxContainer" import { WagonWheelContainer } from "../components/wagonWheelContainer" -import type { GameScene } from "../scenes/gameScene.ts" -import { GameObject } from "./gameObject.ts" +import type { GameScene } from "../scenes/gameScene" +import { GameObject } from "./gameObject" import { Mechanic } from "./units" interface IWagonOptions { diff --git a/src/lib/game/objects/wolf.ts b/src/lib/game/objects/wolf.ts index eee21657..b8f71fef 100644 --- a/src/lib/game/objects/wolf.ts +++ b/src/lib/game/objects/wolf.ts @@ -1,7 +1,7 @@ import { Sprite } from "pixi.js" import type { IGameObjectWolf } from "$lib/game/types" import type { Game } from "../game" -import { GameObject } from "./gameObject.ts" +import { GameObject } from "./gameObject" interface IWolfOptions { game: Game diff --git a/src/lib/game/services/routeService.ts b/src/lib/game/services/routeService.ts index 07d169f1..a81ded4a 100644 --- a/src/lib/game/services/routeService.ts +++ b/src/lib/game/services/routeService.ts @@ -186,7 +186,13 @@ export class RouteService { height: number theme: IGameChunkTheme }) { - const lake = new LakeChunk({ width, height, center, theme }) + const lake = new LakeChunk({ + scene: this.scene, + width, + height, + center, + theme + }) this.scene.chunks.push(lake) return lake } diff --git a/src/lib/server/db/db.repository.ts b/src/lib/server/db/db.repository.ts index 0c8ff96e..eeed007f 100644 --- a/src/lib/server/db/db.repository.ts +++ b/src/lib/server/db/db.repository.ts @@ -136,42 +136,42 @@ export class DBRepository { } } - findPlayerByTwitchId(twitchId: string) { + findPlayerByProfileId(profileId: string) { return this.db.player.findFirst({ - where: { twitchId }, + where: { profileId }, }) } createPlayer({ - twitchId, - userName, + profileId, + name, inventoryId, id, }: { - twitchId: string - userName: string + profileId: string + name: string inventoryId: string id: string }) { return db.player.create({ data: { id, - twitchId, - userName, + profileId, + name, inventoryId, }, }) } - async findOrCreatePlayer(twitchId: string, userName: string) { - const player = await this.findPlayerByTwitchId(twitchId) + async findOrCreatePlayer(profileId: string, name: string) { + const player = await this.findPlayerByProfileId(profileId) if (!player) { const id = createId() const inventory = await this.createInventory(id) return this.createPlayer({ id, - twitchId, - userName, + profileId, + name, inventoryId: inventory.id, }) } diff --git a/src/routes/p/+page.server.ts b/src/routes/p/+page.server.ts index b1d0fe7a..577e0c3f 100644 --- a/src/routes/p/+page.server.ts +++ b/src/routes/p/+page.server.ts @@ -1,5 +1,6 @@ import { redirect } from "@sveltejs/kit"; +import type { PageServerLoad } from './$types'; -export const load: PageServerLoad = async () => { +export const load = (async () => { redirect(301, "/") -} \ No newline at end of file +}) satisfies PageServerLoad \ No newline at end of file diff --git a/src/routes/p/[slug]/+page.server.ts b/src/routes/p/[slug]/+page.server.ts index 2d238aa8..f9a5091f 100644 --- a/src/routes/p/[slug]/+page.server.ts +++ b/src/routes/p/[slug]/+page.server.ts @@ -2,7 +2,7 @@ import { error } from '@sveltejs/kit'; import type { PageServerLoad } from './$types'; import { db } from "$lib/server/db/db.client"; -export const load: PageServerLoad = async ({ params }) => { +export const load = (async ({ params }) => { const userName = params.slug const profile = await db.profile.findFirst({ @@ -15,4 +15,4 @@ export const load: PageServerLoad = async ({ params }) => { return { profile } -}; \ No newline at end of file +}) satisfies PageServerLoad \ No newline at end of file