Skip to content

Commit

Permalink
import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 committed Jun 11, 2024
1 parent a2d7d85 commit a719974
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/lib/game/actions/plantTreeAction.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
44 changes: 1 addition & 43 deletions src/lib/game/game.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand All @@ -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"]) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/game/objects/area.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/lib/game/objects/buildings/building.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/lib/game/objects/flag.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/game/objects/lake.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/lib/game/objects/rabbit.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/game/objects/stone.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/game/objects/units/courier.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/game/objects/units/farmer.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/game/objects/units/trader.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/game/objects/units/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/game/objects/wagon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/game/objects/wolf.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/lib/game/services/routeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 12 additions & 12 deletions src/lib/server/db/db.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down
5 changes: 3 additions & 2 deletions src/routes/p/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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, "/")
}
}) satisfies PageServerLoad
4 changes: 2 additions & 2 deletions src/routes/p/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -15,4 +15,4 @@ export const load: PageServerLoad = async ({ params }) => {
return {
profile
}
};
}) satisfies PageServerLoad

0 comments on commit a719974

Please sign in to comment.