Skip to content

Commit

Permalink
circling fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 committed Jun 16, 2024
1 parent e8ec158 commit cca09cf
Show file tree
Hide file tree
Showing 74 changed files with 697 additions and 784 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: App – Build and Push Docker Image
name: Build and Push Docker Image

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: App – Deploy Docker Image on server
name: Deploy Docker Image on Prod

on:
workflow_dispatch:
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/test.yml → .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Test
name: Run Tests and Lint

on:
push:
branches:
- main
push

permissions:
contents: write
Expand All @@ -18,8 +16,11 @@ jobs:

- run: bun install

- name: Lint
run: |
bun run lint
bun run lint:deps
bun run check
- name: ESLint
run: bun run lint

- name: Find circular dependencies
run: bun run lint:deps

- name: Check Svelte files
run: bun run check
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig tsconfig.json --watch",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:deps": "madge -c --extensions ts ./"
"lint:deps": "madge -c --extensions ts ./src"
},
"dependencies": {
"@paralleldrive/cuid2": "2.2.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import type { Player } from '../objects/units'
import type { IGameAction, IGameActionResponse } from '$lib/game/types'
import type { IGameAction } from '$lib/game/types'

interface IActionOptions {
command: IGameAction['command']
commandDescription: IGameAction['commandDescription']
}

export class Action implements IGameAction {
export class BaseAction implements IGameAction {
public command: string
public commandDescription: string

public live!: (
player: Player,
params: string[],
) => Promise<IGameActionResponse>

constructor({ command, commandDescription }: IActionOptions) {
this.command = command
this.commandDescription = commandDescription
Expand Down
14 changes: 6 additions & 8 deletions src/lib/game/actions/donateWoodToVillageAction.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { Village } from '../chunks'
import type { Warehouse } from '../objects/buildings/warehouse'
import type { Player } from '../objects/units'
import type { GameScene } from '../scenes/gameScene'
import { Action } from './action'
import { ANSWER } from '$lib/game/services/actionService'
import { BaseAction } from './baseAction'
import { ANSWER } from '$lib/game/scenes/services/actionService'
import type { GameScene } from '$lib/game/types'

interface IDonateWoodToVillageActionOptions {
scene: GameScene
}

export class DonateWoodToVillageAction extends Action {
private scene: GameScene
export class DonateWoodToVillageAction extends BaseAction {
scene: GameScene

constructor({ scene }: IDonateWoodToVillageActionOptions) {
super({ command: 'donate', commandDescription: '!donate [quantity]' })

this.scene = scene
this.live = this.initLive
}

async initLive(player: Player, params: string[]) {
async live(player, params) {
const amount = this.scene.actionService.getAmountFromChatCommand(params[0])
if (!amount) {
return ANSWER.WRONG_AMOUNT_ERROR
Expand Down
14 changes: 6 additions & 8 deletions src/lib/game/actions/plantTreeAction.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { Village } from '../chunks'
import type { Player } from '../objects/units'
import type { GameScene } from '../scenes/gameScene'
import { PlantNewTreeScript } from '../scripts/plantNewTreeScript'
import { Action } from './action'
import { ANSWER } from '$lib/game/services/actionService'
import { BaseAction } from './baseAction'
import { ANSWER } from '$lib/game/scenes/services/actionService'
import type { GameScene } from '$lib/game/types'

interface IPlantTreeActionOptions {
scene: GameScene
}

export class PlantTreeAction extends Action {
private scene: GameScene
export class PlantTreeAction extends BaseAction {
scene: GameScene

constructor({ scene }: IPlantTreeActionOptions) {
super({ command: 'plant', commandDescription: '!plant' })

this.scene = scene
this.live = this.initLive
}

async initLive(player: Player) {
async live(player) {
if (player.script && !player.script.isInterruptible) {
return ANSWER.BUSY_ERROR
}
Expand Down
22 changes: 10 additions & 12 deletions src/lib/game/actions/voteAction.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import type { Poll } from '../common'
import type { Player } from '../objects/units'
import { Action } from './action'
import { ANSWER } from '$lib/game/services/actionService'
import { BaseAction } from './baseAction'
import { ANSWER } from '$lib/game/scenes/services/actionService'

interface IVoteActionOptions {
poll: Poll
}

export class VoteAction extends Action {
private poll: Poll
private readonly id: string
export class VoteAction extends BaseAction {
#poll: Poll
readonly #id: string

constructor({ poll }: IVoteActionOptions) {
super({ command: 'go', commandDescription: '!go' })

this.id = poll.generatePollId()
this.#id = poll.generatePollId()

this.command = `go ${this.id}`
this.commandDescription = `!go ${this.id}`
this.command = `go ${this.#id}`
this.commandDescription = `!go ${this.#id}`

this.poll = poll
this.live = this.initLive
this.#poll = poll
}

async initLive(player: Player) {
async live(player) {
const isSuccess = this.poll.vote(player)
if (!isSuccess) {
return ANSWER.ALREADY_VOTED_ERROR
Expand Down
68 changes: 11 additions & 57 deletions src/lib/game/game.ts → src/lib/game/baseGame.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { Application, Container } from 'pixi.js'
import type { GameObject, Wagon } from './objects'
import { Player, Trader } from './objects/units'
import type { GameScene } from './scenes/gameScene'
import { MovingScene } from './scenes/movingScene'
import { AssetsManager, AudioManager } from './utils'
import { BackgroundGenerator } from './utils/generators/background'
import type {
GameSceneType,
IGameObject,
IGameObjectPlayer,
IGameObjectTrader,
WebSocketMessage,
Game,
GameObject,
GameScene,
GameSceneType, WebSocketMessage,
} from '$lib/game/types'
import type { Wagon } from '$lib/game/objects/wagon'
import { AudioManager } from '$lib/game/utils/audioManager'
import { BackgroundGenerator } from '$lib/game/utils/generators/background'
import { AssetsManager } from '$lib/game/utils/assetsManager'

export class Game extends Container {
export class BaseGame extends Container implements Game {
public children: GameObject[] = []
public app!: Application
public audio!: AudioManager
Expand Down Expand Up @@ -176,30 +173,6 @@ export class Game extends Container {
}
}

initPlayer(object: IGameObjectPlayer) {
const player = new Player({ game: this, object })
this.addChild(player)
}

updatePlayer(object: IGameObjectPlayer) {
const player = this.findObject(object.id)
if (player instanceof Player) {
player.update(object)
}
}

initTrader(object: IGameObjectTrader) {
const unit = new Trader({ game: this, object })
this.addChild(unit)
}

updateTrader(object: IGameObjectTrader) {
const unit = this.findObject(object.id)
if (unit instanceof Trader) {
unit.update(object)
}
}

public checkIfThisFlagIsTarget(id: string) {
for (const obj of this.children) {
if (obj.target?.id === id) {
Expand Down Expand Up @@ -234,31 +207,12 @@ export class Game extends Container {
}
}

handleMessageObject(object: Partial<IGameObject>) {
handleMessageObject(object: Partial<GameObject>) {
if (!object.id) {
return
}

const obj = this.findObject(object.id)
if (!obj) {
if (object.entity === 'PLAYER') {
this.initPlayer(object as IGameObjectPlayer)
return
}
if (object.entity === 'TRADER') {
this.initTrader(object as IGameObjectTrader)
return
}
return
}

if (object.entity === 'PLAYER') {
this.updatePlayer(object as IGameObjectPlayer)
return
}
if (object.entity === 'TRADER') {
this.updateTrader(object as IGameObjectTrader)
}
this.findObject(object.id)
}

handleMessageEvent(event: WebSocketMessage['event']) {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/game/chunks/forest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Stone, Tree } from '../objects'
import type { GameScene } from '../scenes/gameScene.ts'
import { GameChunk } from './gameChunk'
import { getRandomInRange } from '$lib/random'
import type { IGameChunkTheme, IGameForestChunk } from '$lib/game/types'
import type { GameScene, IGameChunkTheme, IGameForestChunk } from '$lib/game/types'

interface IForestOptions {
center: IGameForestChunk['center']
Expand Down
14 changes: 9 additions & 5 deletions src/lib/game/chunks/gameChunk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { createId } from '@paralleldrive/cuid2'
import { Area, type GameObject, Tree } from '../objects'
import type { GameScene } from '../scenes/gameScene.ts'
import { Area, Tree } from '../objects'
import { getRandomInRange } from '$lib/random'
import type { IGameChunk, IGameChunkTheme } from '$lib/game/types'
import type {
GameObject,
GameScene,
IGameChunk,
IGameChunkTheme,
} from '$lib/game/types'

interface IGameChunkOptions {
center: IGameChunk['center']
Expand Down Expand Up @@ -40,12 +44,12 @@ export class GameChunk implements IGameChunk {

this.scene = scene

this.initArea({ width, height, theme })
this.#initArea({ width, height, theme })
}

public live() {}

private initArea({
#initArea({
width,
height,
theme,
Expand Down
4 changes: 0 additions & 4 deletions src/lib/game/chunks/index.ts

This file was deleted.

7 changes: 5 additions & 2 deletions src/lib/game/chunks/lake.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Lake, Stone, Tree } from '../objects'
import type { GameScene } from '../scenes/gameScene.ts'
import { GameChunk } from './gameChunk'
import { getRandomInRange } from '$lib/random'
import type { IGameChunkTheme, IGameLakeChunk } from '$lib/game/types'
import type {
GameScene,
IGameChunkTheme,
IGameLakeChunk,
} from '$lib/game/types'

interface ILakeOptions {
scene: GameScene
Expand Down
11 changes: 5 additions & 6 deletions src/lib/game/chunks/village.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Store } from '../objects/buildings/store'
import { WagonStop } from '../objects/buildings/wagonStop'
import { Warehouse } from '../objects/buildings/warehouse'
import { Courier, Farmer } from '../objects/units'
import type { GameScene } from '../scenes/gameScene'
import { BuildScript } from '../scripts/buildScript'
import { ChopTreeScript } from '../scripts/chopTreeScript'
import { MoveToTargetScript } from '../scripts/moveToTargetScript'
Expand All @@ -14,9 +13,9 @@ import { PlantNewTreeScript } from '../scripts/plantNewTreeScript'
import { GameChunk } from './gameChunk'
import { getRandomInRange } from '$lib/random'
import type {
IGameChunkTheme,
IGameObjectFlag,
IGameVillageChunk,
GameObjectFlag,
GameScene,
IGameChunkTheme, IGameVillageChunk,
} from '$lib/game/types'

interface IVillageOptions {
Expand Down Expand Up @@ -179,7 +178,7 @@ export class Village extends GameChunk implements IGameVillageChunk {
}
}

initFlag(type: IGameObjectFlag['type']) {
initFlag(type: GameObjectFlag['type']) {
const randomPoint = this.getRandomPoint()
this.objects.push(
new Flag({
Expand All @@ -191,7 +190,7 @@ export class Village extends GameChunk implements IGameVillageChunk {
)
}

initFlags(type: IGameObjectFlag['type'], count: number) {
initFlags(type: GameObjectFlag['type'], count: number) {
for (let i = 0; i < count; i++) {
this.initFlag(type)
}
Expand Down
6 changes: 0 additions & 6 deletions src/lib/game/common/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/lib/game/common/poll.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createId } from '@paralleldrive/cuid2'
import { VoteAction } from '../actions/voteAction'
import type { GameScene } from '../scenes/gameScene'
import { getRandomInRange } from '$lib/random'
import type { IGameObjectPlayer, IGamePoll } from '$lib/game/types'
import type { GameScene, IGameObjectPlayer, IGamePoll } from '$lib/game/types'

interface IPollOptions {
scene: GameScene
Expand Down
Loading

0 comments on commit cca09cf

Please sign in to comment.