Skip to content

Commit

Permalink
Refactoring (part 4)
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Feb 12, 2024
1 parent 8bcd8b4 commit a1e4fa4
Show file tree
Hide file tree
Showing 43 changed files with 426 additions and 8,311 deletions.
8,280 changes: 232 additions & 8,048 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,29 @@
},
"devDependencies": {
"@types/heap": "0.2.33",
"@types/jest": "29.5.7",
"@types/node": "20.8.10",
"@types/react": "18.2.25",
"@types/react-dom": "18.2.10",
"@types/jest": "29.5.12",
"@types/node": "20.11.17",
"@types/react": "18.2.55",
"@types/react-dom": "18.2.19",
"@types/styled-components": "5.1.29",
"@types/uuid": "9.0.6",
"@vitejs/plugin-react": "4.1.1",
"@vitejs/plugin-react": "4.2.1",
"alias-reuse": "2.0.0",
"eslint": "8.51.0",
"eslint-config-neki": "1.3.0",
"jest": "29.7.0",
"jest-canvas-mock": "2.5.2",
"jest-environment-jsdom": "29.7.0",
"phaser3spectorjs": "0.0.8",
"ts-jest": "29.1.1",
"typescript": "5.2.2",
"vite": "4.5.0",
"vite-plugin-checker": "0.6.2",
"vite-plugin-static-copy": "0.17.0",
"vite-plugin-zip-pack": "1.0.6"
"ts-jest": "29.1.2",
"typescript": "5.3.3",
"vite": "5.1.1",
"vite-plugin-checker": "0.6.4",
"vite-plugin-static-copy": "0.17.1"
},
"dependencies": {
"events": "3.3.0",
"gen-biome": "2.4.0",
"gen-biome": "2.4.1",
"heap": "0.2.7",
"idb": "7.1.1",
"phaser": "3.60.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import React, { useState } from 'react';

import { GameScene } from '../../../../../types';
import { Amount } from '~scene/system/interface/amount';
import { PlayerEvents } from '~scene/world/entities/player/types';
import { PlayerEvent } from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';

export const Experience: React.FC = () => {
const world = useScene<IWorld>(GameScene.WORLD);

const [amount, setAmount] = useState(world.player.experience);

useEvent(world.player, PlayerEvents.UPDATE_EXPERIENCE, (experience: number) => {
useEvent(world.player, PlayerEvent.UPDATE_EXPERIENCE, (experience: number) => {
setAmount(experience);
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Tutorial } from '~lib/tutorial';
import { TutorialStep } from '~lib/tutorial/types';
import { Amount } from '~scene/system/interface/amount';
import { Hint } from '~scene/system/interface/hint';
import { PlayerEvents } from '~scene/world/entities/player/types';
import { PlayerEvent } from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';

import { Wrapper } from './styles';
Expand All @@ -25,7 +25,7 @@ export const Resources: React.FC = () => {
[],
);

useEvent(world.player, PlayerEvents.UPDATE_RESOURCES, (resources: number) => {
useEvent(world.player, PlayerEvent.UPDATE_RESOURCES, (resources: number) => {
setAmount(resources);
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/screen/interface/player-hud/score/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import React, { useState } from 'react';

import { GameScene } from '../../../../../types';
import { Amount } from '~scene/system/interface/amount';
import { PlayerEvents } from '~scene/world/entities/player/types';
import { PlayerEvent } from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';

export const Score: React.FC = () => {
const world = useScene<IWorld>(GameScene.WORLD);

const [amount, setAmount] = useState(world.player.score);

useEvent(world.player, PlayerEvents.UPDATE_SCORE, (score: number) => {
useEvent(world.player, PlayerEvent.UPDATE_SCORE, (score: number) => {
setAmount(score);
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/screen/interface/skills/modal/item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { phrase } from '~lib/lang';
import { Cost } from '~scene/system/interface/cost';
import { PLAYER_MAX_SKILL_LEVEL } from '~scene/world/entities/player/const';
import {
PlayerSkill, PlayerSkillData, PlayerEvents, PlayerSkillIcon,
PlayerSkill, PlayerSkillData, PlayerEvent, PlayerSkillIcon,
} from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';

Expand Down Expand Up @@ -41,7 +41,7 @@ export const Item: React.FC<Props> = ({ type }) => {
world.player.upgrade(type);
}, [type]);

useEvent(world.player, PlayerEvents.UPGRADE_SKILL, () => {
useEvent(world.player, PlayerEvent.UPGRADE_SKILL, () => {
setData(getData());
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/screen/interface/superskills/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEvent, useScene } from 'phaser-react-ui';
import React, { useMemo, useState } from 'react';

import { GameScene } from '../../../../types';
import { PlayerSuperskill, PlayerEvents } from '~scene/world/entities/player/types';
import { PlayerSuperskill, PlayerEvent } from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';

import { Item } from './item';
Expand All @@ -19,7 +19,7 @@ export const Superskills: React.FC = () => {
Object.keys(world.player.unlockedSuperskills).length > 0
));

useEvent(world.player, PlayerEvents.UNLOCK_SUPERSKILL, () => {
useEvent(world.player, PlayerEvent.UNLOCK_SUPERSKILL, () => {
setAllow(true);
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/screen/interface/superskills/item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { IGame } from '../../../../../types';
import { GameScene, GameEvent } from '../../../../../types';
import { phrase } from '~lib/lang';
import { Cost } from '~scene/system/interface/cost';
import { PlayerSuperskill, PlayerEvents, PlayerSuperskillIcon } from '~scene/world/entities/player/types';
import { PlayerSuperskill, PlayerEvent, PlayerSuperskillIcon } from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';

import {
Expand Down Expand Up @@ -35,7 +35,7 @@ export const Item: React.FC<Props> = ({ type }) => {
}
}, [type, isAllow]);

useEvent(world.player, PlayerEvents.UNLOCK_SUPERSKILL, (superskill: PlayerSuperskill) => {
useEvent(world.player, PlayerEvent.UNLOCK_SUPERSKILL, (superskill: PlayerSuperskill) => {
if (superskill === type) {
setAllow(true);
}
Expand Down
8 changes: 4 additions & 4 deletions src/game/scenes/screen/interface/unlocks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React, { useEffect, useState } from 'react';
import type { IGame } from '../../../../types';
import { GameScene } from '../../../../types';
import { BuildingVariant } from '~scene/world/entities/building/types';
import { AssistantVariant, AssistantEvents } from '~scene/world/entities/npc/assistant/types';
import { PlayerSuperskill, PlayerEvents } from '~scene/world/entities/player/types';
import { AssistantVariant, AssistantEvent } from '~scene/world/entities/npc/assistant/types';
import { PlayerSuperskill, PlayerEvent } from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';
import { WaveEvent } from '~scene/world/wave/types';

Expand Down Expand Up @@ -46,14 +46,14 @@ export const Unlocks: React.FC = () => {
setFeatures((current) => list.concat(current));
}, []);

useEvent(world.player, PlayerEvents.UNLOCK_SUPERSKILL, (superskill: PlayerSuperskill) => {
useEvent(world.player, PlayerEvent.UNLOCK_SUPERSKILL, (superskill: PlayerSuperskill) => {
setFeatures((current) => current.concat([{
type: 'SUPERSKILL',
item: superskill,
}]));
}, []);

useEvent(world.assistant, AssistantEvents.UNLOCK_VARIANT, (variant: AssistantVariant) => {
useEvent(world.assistant, AssistantEvent.UNLOCK_VARIANT, (variant: AssistantVariant) => {
setFeatures((current) => current.concat([{
type: 'ASSISTANT',
item: variant,
Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/system/interface/cost/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
} from 'react';

import { GameScene } from '../../../../types';
import { PlayerEvents } from '~scene/world/entities/player/types';
import { PlayerEvent } from '~scene/world/entities/player/types';
import type { IWorld } from '~scene/world/types';

import * as styles from './styles';
Expand All @@ -30,7 +30,7 @@ export const Cost: React.FC<Props> = ({ type, value, check = true }) => {
(!check || typeof value !== 'number' || haveAmount >= value)
), [check, value, haveAmount]);

useEvent(world.player, PlayerEvents[`UPDATE_${type}`], (amount: number) => {
useEvent(world.player, PlayerEvent[`UPDATE_${type}`], (amount: number) => {
setHaveAmount(amount);
}, []);

Expand Down
6 changes: 3 additions & 3 deletions src/game/scenes/world/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Tutorial } from '~lib/tutorial';
import { TutorialStep } from '~lib/tutorial/types';
import { Utils } from '~lib/utils';

import { BuilderEvents, IBuilder } from './types';
import { BuilderEvent, IBuilder } from './types';
import { WORLD_DEPTH_GRAPHIC } from '../const';
import { BUILDING_TILE } from '../entities/building/const';
import { BUILDINGS } from '../entities/building/factory/const';
Expand Down Expand Up @@ -226,7 +226,7 @@ export class Builder extends Phaser.Events.EventEmitter implements IBuilder {

this.createBuildInstance();

this.emit(BuilderEvents.BUILD_START);
this.emit(BuilderEvent.BUILD_START);
}

public close() {
Expand All @@ -239,7 +239,7 @@ export class Builder extends Phaser.Events.EventEmitter implements IBuilder {
this.isBuild = false;
this.supposedPosition = null;

this.emit(BuilderEvents.BUILD_STOP);
this.emit(BuilderEvent.BUILD_STOP);
}

private clearBuildingVariant() {
Expand Down
2 changes: 1 addition & 1 deletion src/game/scenes/world/builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface IBuilder extends Phaser.Events.EventEmitter {
getBuildingsByVariant<T extends IBuilding>(variant: BuildingVariant): T[]
}

export enum BuilderEvents {
export enum BuilderEvent {
BUILD_START = 'build_start',
BUILD_STOP = 'build_stop',
}
8 changes: 4 additions & 4 deletions src/game/scenes/world/entities/building/factory/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { BuildingAmmunition } from '~scene/world/entities/building/variants/ammu
import { BuildingBooster } from '~scene/world/entities/building/variants/booster';
import { BuildingGenerator } from '~scene/world/entities/building/variants/generator';
import { BuildingRadar } from '~scene/world/entities/building/variants/radar';
import { BuildingTowerElectro } from '~scene/world/entities/building/variants/tower/variants/electro';
import { BuildingTowerFire } from '~scene/world/entities/building/variants/tower/variants/fire';
import { BuildingTowerFrozen } from '~scene/world/entities/building/variants/tower/variants/frozen';
import { BuildingTowerLazer } from '~scene/world/entities/building/variants/tower/variants/lazer';
import { BuildingTowerElectro } from '~scene/world/entities/building/variants/tower/electro';
import { BuildingTowerFire } from '~scene/world/entities/building/variants/tower/fire';
import { BuildingTowerFrozen } from '~scene/world/entities/building/variants/tower/frozen';
import { BuildingTowerLazer } from '~scene/world/entities/building/variants/tower/lazer';
import { BuildingWall } from '~scene/world/entities/building/variants/wall';

import type { IBuildingFactory } from './types';
Expand Down
Loading

0 comments on commit a1e4fa4

Please sign in to comment.