Skip to content

Commit

Permalink
refactor(*): minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Oct 9, 2024
1 parent 80a613f commit 85c22a1
Show file tree
Hide file tree
Showing 115 changed files with 890 additions and 1,095 deletions.
77 changes: 39 additions & 38 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "import"],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import'],
extends: [
"eslint:recommended",
"plugin:import/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
'eslint:recommended',
'plugin:import/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
// Basic
quotes: ["error", "single"],
"no-multiple-empty-lines": ["error", { max: 1, maxBOF: 0, maxEOF: 1 }],
"no-multi-spaces": "error",
"object-curly-spacing": ["error", "always"],
"array-bracket-spacing": ["error", "never"],
"computed-property-spacing": ["error", "never"],
"comma-dangle": ["error", "always-multiline"],
"eol-last": ["error", "always"],
"no-trailing-spaces": "error",
"brace-style": ["error", "1tbs", { allowSingleLine: true }],
indent: ["error", 2, { SwitchCase: 1 }],
"keyword-spacing": ["error", { before: true, after: true }],
"padded-blocks": ["error", "never"],
"comma-spacing": ["error", { before: false, after: true }],
"space-in-parens": ["error", "never"],
'quotes': ['error', 'single'],
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 1 }],
'no-multi-spaces': 'error',
'object-curly-spacing': ['error', 'always'],
'array-bracket-spacing': ['error', 'never'],
'computed-property-spacing': ['error', 'never'],
'comma-dangle': ['error', 'always-multiline'],
'eol-last': ['error', 'always'],
'no-trailing-spaces': 'error',
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
'indent': ['error', 2, { SwitchCase: 1 }],
'keyword-spacing': ['error', { before: true, after: true }],
'padded-blocks': ['error', 'never'],
'comma-spacing': ['error', { before: false, after: true }],
'space-in-parens': ['error', 'never'],
// TypeScript
"@typescript-eslint/semi": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
'@typescript-eslint/semi': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
// Import
"import/no-cycle": "error",
"import/no-unresolved": "off",
"import/order": [
"warn",
'import/no-named-as-default-member': 'off',
'import/no-cycle': 'error',
'import/no-unresolved': 'off',
'import/order': [
'warn',
{
"newlines-between": "always",
'newlines-between': 'always',
groups: [
["builtin", "external"],
["parent", "sibling"],
"index",
"object",
"type",
"unknown",
['builtin', 'external'],
['parent', 'sibling'],
'index',
'object',
'type',
'unknown',
],
alphabetize: {
order: "asc",
order: 'asc',
},
pathGroups: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/const/difficulty.ts → src/game/difficulty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO: Split and move into every feature
// TODO: Split by features
export const DIFFICULTY = {
/**
* Player
Expand Down
28 changes: 9 additions & 19 deletions src/game/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import Phaser from 'phaser';

import { CONTAINER_ID, DEBUG_MODS, AUDIO_VOLUME } from './const';
import { GameDifficulty, GameState, GameSettings, GameScene, GameEvent,
} from './types';
import { GameDifficulty, GameState, GameSettings, GameScene, GameEvent } from './types';

import type {
IGame, GameStat, GameSavePayload } from './types';
import type { IGame, GameStat, GameSavePayload } from './types';
import type { StorageSave } from '~lib/storage/types';
import type { IScreen } from '~scene/screen/types';
import type { IWorld } from '~scene/world/types';
Expand All @@ -24,24 +22,18 @@ import { World } from '~scene/world';
export class Game extends Phaser.Game implements IGame {
public difficulty: GameDifficulty = GameDifficulty.NORMAL;

private isSaved: boolean = false;
private saved: boolean = false;

private _state: GameState = GameState.IDLE;

public get state() { return this._state; }

private set state(v) { this._state = v; }

private _screen: IScreen;

public get screen() { return this._screen; }

private set screen(v) { this._screen = v; }

private _world: IWorld;

public get world() { return this._world; }

private set world(v) { this._world = v; }

private _settings: Record<GameSettings, boolean> = {
Expand All @@ -50,9 +42,7 @@ export class Game extends Phaser.Game implements IGame {
[GameSettings.EFFECTS]: true,
[GameSettings.SHOW_DAMAGE]: true,
};

public get settings() { return this._settings; }

private set settings(v) { this._settings = v; }

public usedSave: Nullable<StorageSave> = null;
Expand Down Expand Up @@ -110,7 +100,7 @@ export class Game extends Phaser.Game implements IGame {
window.addEventListener('beforeunload', (event: Event) => {
const needConfirm = (
this.state === GameState.STARTED
|| (this.state === GameState.PAUSED && !this.isSaved)
|| (this.state === GameState.PAUSED && !this.saved)
);

if (needConfirm) {
Expand Down Expand Up @@ -155,7 +145,7 @@ export class Game extends Phaser.Game implements IGame {
this.world.scene.resume();
this.screen.scene.resume();

this.isSaved = false;
this.saved = false;
}

public continueGame(save: StorageSave) {
Expand Down Expand Up @@ -284,9 +274,9 @@ export class Game extends Phaser.Game implements IGame {

public getDifficultyMultiplier() {
switch (this.difficulty) {
case GameDifficulty.EASY: return 0.8;
case GameDifficulty.HARD: return 1.4;
default: return 1.0;
case GameDifficulty.EASY: return 0.8;
case GameDifficulty.HARD: return 1.4;
default: return 1.0;
}
}

Expand Down Expand Up @@ -369,7 +359,7 @@ export class Game extends Phaser.Game implements IGame {
const save = await Storage.AddSave(this, name);

if (save) {
this.isSaved = true;
this.saved = true;
this.usedSave = save;
}

Expand Down
3 changes: 1 addition & 2 deletions src/game/scenes/gameover/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Interface } from 'phaser-react-ui';

import { GameoverUI } from './interface';
import { Scene } from '..';
import { GameScene } from '../../types';

import { GameoverUI } from './interface';

export class Gameover extends Scene {
constructor() {
super(GameScene.GAMEOVER);
Expand Down
6 changes: 2 additions & 4 deletions src/game/scenes/gameover/interface/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import React, { useEffect, useRef } from 'react';

import { Result } from './result';

import type { GameStat, IGame } from '../../../types';
import type { GameStat, IGame } from '~game/types';

import { phrase } from '~lib/lang';
import { Tutorial } from '~lib/tutorial';
import { Overlay } from '~scene/system/interface/overlay';

import {
Wrapper, Label, Button, Head, IconRestart,
} from './styles';
import { Wrapper, Label, Button, Head, IconRestart } from './styles';

type Props = {
stat: GameStat
Expand Down
6 changes: 2 additions & 4 deletions src/game/scenes/gameover/interface/result/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { useMemo } from 'react';

import type { GameStat } from '../../../../types';
import type { GameStat } from '~game/types';
import type { LangPhrase } from '~lib/lang/types';

import { phrase } from '~lib/lang';

import {
Wrapper, Item, Value, Label, Record,
} from './styles';
import { Wrapper, Item, Value, Label, Record } from './styles';

type Props = {
stat: GameStat
Expand Down
6 changes: 3 additions & 3 deletions src/game/scenes/menu/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Interface } from 'phaser-react-ui';

import { Scene } from '..';
import { GameScene, GameState } from '../../types';

import { MenuUI } from './interface';
import { Scene } from '..';

import type { MenuPage } from './types';

import { GameScene, GameState } from '~game/types';

export class Menu extends Scene {
constructor() {
super(GameScene.MENU);
Expand Down
16 changes: 16 additions & 0 deletions src/game/scenes/menu/interface/content/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AboutGame } from './about-game';
import { Controls } from './controls';
import { LoadGame } from './load-game';
import { NewGame } from './new-game';
import { SaveGame } from './save-game';
import { Settings } from './settings';
import { MenuPage } from '../../types';

export const PAGES: Record<MenuPage, React.FC> = {
[MenuPage.NEW_GAME]: NewGame,
[MenuPage.SAVE_GAME]: SaveGame,
[MenuPage.LOAD_GAME]: LoadGame,
[MenuPage.SETTINGS]: Settings,
[MenuPage.ABOUT_GAME]: AboutGame,
[MenuPage.CONTROLS]: Controls,
};
4 changes: 1 addition & 3 deletions src/game/scenes/menu/interface/content/controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import React from 'react';
import { CONTROLS } from '~lib/controls/const';
import { phrase } from '~lib/lang';

import {
Wrapper, Control, Keys, Key, Description,
} from './styles';
import { Wrapper, Control, Keys, Key, Description } from './styles';

export const Controls: React.FC = () => (
<Wrapper>
Expand Down
18 changes: 2 additions & 16 deletions src/game/scenes/menu/interface/content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
import React from 'react';

import { AboutGame } from './about-game';
import { Controls } from './controls';
import { LoadGame } from './load-game';
import { NewGame } from './new-game';
import { SaveGame } from './save-game';
import { Settings } from './settings';
import { PAGES } from './const';

import { MenuPage } from '~scene/menu/types';
import type { MenuPage } from '~scene/menu/types';

import { Wrapper } from './styles';

type Props = {
page?: MenuPage
};

const PAGES: Record<MenuPage, React.FC> = {
[MenuPage.NEW_GAME]: NewGame,
[MenuPage.SAVE_GAME]: SaveGame,
[MenuPage.LOAD_GAME]: LoadGame,
[MenuPage.SETTINGS]: Settings,
[MenuPage.ABOUT_GAME]: AboutGame,
[MenuPage.CONTROLS]: Controls,
};

export const Content: React.FC<Props> = ({ page }) => {
const PageComponent = page && PAGES[page];

Expand Down
2 changes: 1 addition & 1 deletion src/game/scenes/menu/interface/content/load-game/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useGame } from 'phaser-react-ui';
import React, { useState } from 'react';

import type { IGame } from '../../../../../types';
import type { IGame } from '~game/types';
import type { LangPhrase } from '~lib/lang/types';

import { phrase } from '~lib/lang';
Expand Down
3 changes: 1 addition & 2 deletions src/game/scenes/menu/interface/content/new-game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import Phaser from 'phaser';
import { useGame } from 'phaser-react-ui';
import React, { useMemo, useState } from 'react';

import { GameDifficulty } from '../../../../../types';

import { Param } from './param';
import { Record } from './record';
import { GameDifficulty } from '../../../../../types';

import type { IGame } from '../../../../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React from 'react';

import { phrase } from '~lib/lang';

import {
Wrapper, Amount, Icon, Label, Value,
} from './styles';
import { Wrapper, Amount, Icon, Label, Value } from './styles';

type Props = {
value: number
Expand Down
9 changes: 3 additions & 6 deletions src/game/scenes/menu/interface/content/save-game/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { useGame } from 'phaser-react-ui';
import React, {
useRef, useEffect, useState,
} from 'react';
import React, { useRef, useEffect, useState } from 'react';

import { MAX_GAME_SAVES } from '../../../../../const';

import type { IGame } from '../../../../../types';
import type { ChangeEvent } from 'react';
import type { IGame } from '~game/types';
import type { LangPhrase } from '~lib/lang/types';
import type { StorageSave } from '~lib/storage/types';

import { MAX_GAME_SAVES } from '~game/const';
import { phrase } from '~lib/lang';
import { Storage } from '~lib/storage';
import { Button } from '~scene/system/interface/button';
Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/menu/interface/content/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import { GameSettings } from '../../../../../types';

import { Param } from './param';

import { GameSettings } from '~game/types';

import { Wrapper } from './styles';

export const Settings: React.FC = () => (
Expand Down
11 changes: 11 additions & 0 deletions src/game/scenes/menu/interface/content/settings/param/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { LangPhrase } from '~lib/lang/types';

import { InterfaceTextColor } from '~lib/interface/types';

export const PARAM_VALUES: {
value: LangPhrase
color?: InterfaceTextColor
}[] = [
{ value: 'ON' },
{ value: 'OFF', color: InterfaceTextColor.ERROR },
];
Loading

0 comments on commit 85c22a1

Please sign in to comment.