Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdelab committed Jan 22, 2025
1 parent ca8ce55 commit ac860cc
Showing 18 changed files with 88 additions and 793 deletions.
2 changes: 1 addition & 1 deletion client/apps/game/src/hooks/store/_three-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StructureInfo } from "@/types";
import { StructureInfo } from "@/three/types";
import { BuildingType, HexPosition, ID, Position } from "@bibliothecadao/eternum";

export interface ThreeStore {
2 changes: 1 addition & 1 deletion client/apps/game/src/three/game-renderer.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import HexceptionScene from "@/three/scenes/hexception";
import HUDScene from "@/three/scenes/hud-scene";
import WorldmapScene from "@/three/scenes/worldmap";
import { SystemManager } from "@/three/systems/system-manager";
import { SceneName } from "@/types";
import { GRAPHICS_SETTING, GraphicsSettings, IS_FLAT_MODE } from "@/ui/config";
import { SetupResult } from "@bibliothecadao/eternum";
import throttle from "lodash/throttle";
@@ -25,6 +24,7 @@ import { MapControls } from "three/examples/jsm/controls/MapControls";
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment";
import Stats from "three/examples/jsm/libs/stats.module";
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js";
import { SceneName } from "./types";

export default class GameRenderer {
private labelRenderer!: CSS2DRenderer;
3 changes: 1 addition & 2 deletions client/apps/game/src/three/managers/army-manager.ts
Original file line number Diff line number Diff line change
@@ -5,12 +5,11 @@ import { isAddressEqualToAccount } from "@/three/helpers/utils";
import { ArmyModel } from "@/three/managers/army-model";
import { Biome } from "@/three/managers/biome";
import { LabelManager } from "@/three/managers/label-manager";
import { ArmyData, MovingArmyData, MovingLabelData, RenderChunkSize } from "@/types";
import { Position } from "@/types/position";
import { ArmySystemUpdate } from "@/types/systems";
import { BiomeType, ContractAddress, FELT_CENTER, ID, orders } from "@bibliothecadao/eternum";
import * as THREE from "three";
import { CSS2DObject } from "three/examples/jsm/renderers/CSS2DRenderer";
import { ArmyData, ArmySystemUpdate, MovingArmyData, MovingLabelData, RenderChunkSize } from "../types";
import { calculateOffset, getHexForWorldPosition, getWorldPositionForHex } from "../utils";

const myColor = new THREE.Color(0, 1.5, 0);
2 changes: 1 addition & 1 deletion client/apps/game/src/three/managers/battle-manager.ts
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@ import { GUIManager } from "@/three/helpers/gui-manager";
import { BattleModel } from "@/three/managers/battle-model";
import { LabelManager } from "@/three/managers/label-manager";
import { Position } from "@/types/position";
import { BattleSystemUpdate } from "@/types/systems";
import { ID } from "@bibliothecadao/eternum";
import * as THREE from "three";
import { BattleSystemUpdate } from "../types";
import { getWorldPositionForHex } from "../utils";

const LABEL_PATH = "textures/battle_label.png";
2 changes: 1 addition & 1 deletion client/apps/game/src/three/managers/input-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SceneManager } from "@/three/scene-manager";
import { SceneName } from "@/types";
import * as THREE from "three";
import { SceneName } from "../types";

type ListenerTypes = "click" | "mousemove" | "contextmenu" | "dblclick" | "mousedown";

3 changes: 1 addition & 2 deletions client/apps/game/src/three/managers/structure-manager.ts
Original file line number Diff line number Diff line change
@@ -3,11 +3,10 @@ import { gltfLoader, isAddressEqualToAccount } from "@/three/helpers/utils";
import InstancedModel from "@/three/managers/instanced-model";
import { LabelManager } from "@/three/managers/label-manager";
import { StructureLabelPaths, StructureModelPaths } from "@/three/scenes/constants";
import { RenderChunkSize, StructureInfo } from "@/types";
import { StructureSystemUpdate } from "@/types/systems";
import { FELT_CENTER } from "@/ui/config";
import { ID, StructureType } from "@bibliothecadao/eternum";
import * as THREE from "three";
import { RenderChunkSize, StructureInfo, StructureSystemUpdate } from "../types";
import { getWorldPositionForHex } from "../utils";

const neutralColor = new THREE.Color(0xffffff);
2 changes: 1 addition & 1 deletion client/apps/game/src/three/scene-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransitionManager } from "@/three/managers/transition-manager";
import { HexagonScene } from "@/three/scenes/hexagon-scene";
import { SceneName } from "@/types";
import { SceneName } from "./types";

export class SceneManager {
private currentScene: SceneName | undefined = undefined;
4 changes: 2 additions & 2 deletions client/apps/game/src/three/scenes/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as THREE from "three";
import { BiomeType } from "@/three/managers/biome";
import { HyperstructureTypesNames, StructureProgress } from "@/types";
import { IS_FLAT_MODE } from "@/ui/config";
import {
BuildingType,
@@ -10,6 +8,8 @@ import {
ResourcesIds,
StructureType,
} from "@bibliothecadao/eternum";
import * as THREE from "three";
import { HyperstructureTypesNames, StructureProgress } from "../types";

export const HEX_SIZE = 1;

3 changes: 2 additions & 1 deletion client/apps/game/src/three/scenes/hexagon-scene.ts
Original file line number Diff line number Diff line change
@@ -10,14 +10,15 @@ import { InteractiveHexManager } from "@/three/managers/interactive-hex-manager"
import { type SceneManager } from "@/three/scene-manager";
import { HEX_SIZE, biomeModelPaths } from "@/three/scenes/constants";
import { SystemManager } from "@/three/systems/system-manager";
import { LeftView, RightView, type SceneName } from "@/types";
import { LeftView, RightView } from "@/types";
import { GRAPHICS_SETTING, GraphicsSettings, IS_FLAT_MODE } from "@/ui/config";
import { type HexPosition, type SetupResult } from "@bibliothecadao/eternum";
import gsap from "gsap";
import throttle from "lodash/throttle";
import * as THREE from "three";
import { type MapControls } from "three/examples/jsm/controls/MapControls";
import { env } from "../../../env";
import { SceneName } from "../types";
import { getWorldPositionForHex } from "../utils";
export abstract class HexagonScene {
protected scene!: THREE.Scene;
4 changes: 2 additions & 2 deletions client/apps/game/src/three/scenes/hexception.tsx
Original file line number Diff line number Diff line change
@@ -8,9 +8,8 @@ import { SMALL_DETAILS_NAME } from "@/three/managers/instanced-model";
import { SceneManager } from "@/three/scene-manager";
import { HexagonScene } from "@/three/scenes/hexagon-scene";
import { playBuildingSound } from "@/three/sound/utils";
import { LeftView, SceneName, StructureProgress } from "@/types";
import { LeftView } from "@/types";
import { Position } from "@/types/position";
import { BuildingSystemUpdate, RealmSystemUpdate } from "@/types/systems";
import { IS_FLAT_MODE } from "@/ui/config";
import { ResourceIcon } from "@/ui/elements/resource-icon";
import {
@@ -33,6 +32,7 @@ import clsx from "clsx";
import * as THREE from "three";
import { CSS2DObject } from "three-stdlib";
import { MapControls } from "three/examples/jsm/controls/MapControls";
import { BuildingSystemUpdate, RealmSystemUpdate, SceneName, StructureProgress } from "../types";
import { getHexForWorldPosition, getWorldPositionForHex } from "../utils";
import {
BUILDINGS_CATEGORIES_TYPES,
7 changes: 2 additions & 5 deletions client/apps/game/src/three/scenes/worldmap.ts
Original file line number Diff line number Diff line change
@@ -13,9 +13,8 @@ import { SceneManager } from "@/three/scene-manager";
import { HEX_SIZE, PREVIEW_BUILD_COLOR_INVALID } from "@/three/scenes/constants";
import { HexagonScene } from "@/three/scenes/hexagon-scene";
import { playSound } from "@/three/sound/utils";
import { LeftView, SceneName } from "@/types";
import { LeftView } from "@/types";
import { Position } from "@/types/position";
import { ArmySystemUpdate, TileSystemUpdate } from "@/types/systems";
import { FELT_CENTER, IS_FLAT_MODE, IS_MOBILE } from "@/ui/config";
import { UNDEFINED_STRUCTURE_ENTITY_ID } from "@/ui/constants";
import {
@@ -30,11 +29,11 @@ import {
getNeighborOffsets,
} from "@bibliothecadao/eternum";
import { getEntities } from "@dojoengine/state";
import * as torii from "@dojoengine/torii-client";
import throttle from "lodash/throttle";
import * as THREE from "three";
import { Raycaster } from "three";
import { MapControls } from "three/examples/jsm/controls/MapControls";
import { ArmySystemUpdate, SceneName, TileSystemUpdate } from "../types";
import { getWorldPositionForHex } from "../utils";

export default class WorldmapScene extends HexagonScene {
@@ -50,8 +49,6 @@ export default class WorldmapScene extends HexagonScene {

private currentChunk: string = "null";

private subscription: torii.Subscription | null = null;

private armyManager: ArmyManager;
private structureManager: StructureManager;
private battleManager: BattleManager;
18 changes: 9 additions & 9 deletions client/apps/game/src/three/systems/system-manager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { StructureProgress } from "@/types";
import { Position } from "@/types/position";
import {
ArmySystemUpdate,
BattleSystemUpdate,
BuildingSystemUpdate,
RealmSystemUpdate,
StructureSystemUpdate,
TileSystemUpdate,
} from "@/types/systems";
import { divideByPrecision } from "@/ui/utils/utils";
import {
ClientComponents,
@@ -32,6 +23,15 @@ import {
import { getEntityIdFromKeys } from "@dojoengine/utils";
import { shortString } from "starknet";
import { PROGRESS_FINAL_THRESHOLD, PROGRESS_HALF_THRESHOLD } from "../scenes/constants";
import {
ArmySystemUpdate,
BattleSystemUpdate,
BuildingSystemUpdate,
RealmSystemUpdate,
StructureProgress,
StructureSystemUpdate,
TileSystemUpdate,
} from "../types";

// The SystemManager class is responsible for updating the Three.js models when there are changes in the game state.
// It listens for updates from torii and translates them into a format that can be consumed by the Three.js model managers.
60 changes: 60 additions & 0 deletions client/apps/game/src/three/types/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Position } from "@/types/position";
import { ID, StructureType } from "@bibliothecadao/eternum";
import * as THREE from "three";

export enum SceneName {
WorldMap = "map",
Hexception = "hex",
}

export enum HyperstructureTypesNames {
STAGE_1 = "hyperstructure_stage0",
STAGE_2 = "hyperstructure_stage1",
STAGE_3 = "hyperstructure_stage2",
}

export enum StructureProgress {
STAGE_1 = 0,
STAGE_2 = 1,
STAGE_3 = 2,
}

export interface StructureInfo {
entityId: ID;
hexCoords: { col: number; row: number };
stage: number;
level: number;
isMine: boolean;
owner: { address: bigint };
structureType: StructureType;
hasWonder: boolean;
}

export interface ArmyData {
entityId: ID;
matrixIndex: number;
hexCoords: Position;
isMine: boolean;
owner: { address: bigint; ownerName: string; guildName: string };
order: string;
color: string;
}

export interface MovingArmyData {
startPos: THREE.Vector3;
endPos: THREE.Vector3;
progress: number;
matrixIndex: number;
currentPathIndex: number;
}

export interface MovingLabelData {
startPos: THREE.Vector3;
endPos: THREE.Vector3;
progress: number;
}

export interface RenderChunkSize {
width: number;
height: number;
}
2 changes: 2 additions & 0 deletions client/apps/game/src/three/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./common";
export * from "./systems";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StructureProgress } from "@/types";
import { Position } from "@/types/position";
import { HexPosition, ID, StructureType } from "@bibliothecadao/eternum";
import { StructureProgress } from "./common";

export type ArmySystemUpdate = {
entityId: ID;
61 changes: 1 addition & 60 deletions client/apps/game/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
import { Position } from "@/types/position";
import { ID, StructureType } from "@bibliothecadao/eternum";
import * as THREE from "three";

export enum SceneName {
WorldMap = "map",
Hexception = "hex",
}

export enum HyperstructureTypesNames {
STAGE_1 = "hyperstructure_stage0",
STAGE_2 = "hyperstructure_stage1",
STAGE_3 = "hyperstructure_stage2",
}

export enum StructureProgress {
STAGE_1 = 0,
STAGE_2 = 1,
STAGE_3 = 2,
}
import { ID } from "@bibliothecadao/eternum";

export enum RightView {
None,
@@ -34,49 +15,9 @@ export enum LeftView {
ResourceTable,
}

export interface StructureInfo {
entityId: ID;
hexCoords: { col: number; row: number };
stage: number;
level: number;
isMine: boolean;
owner: { address: bigint };
structureType: StructureType;
hasWonder: boolean;
}

export type BattleViewInfo = {
battleEntityId: ID | undefined;
engage?: boolean;
ownArmyEntityId: ID | undefined;
targetArmy: ID | undefined;
};

export interface ArmyData {
entityId: ID;
matrixIndex: number;
hexCoords: Position;
isMine: boolean;
owner: { address: bigint; ownerName: string; guildName: string };
order: string;
color: string;
}

export interface MovingArmyData {
startPos: THREE.Vector3;
endPos: THREE.Vector3;
progress: number;
matrixIndex: number;
currentPathIndex: number;
}

export interface MovingLabelData {
startPos: THREE.Vector3;
endPos: THREE.Vector3;
progress: number;
}

export interface RenderChunkSize {
width: number;
height: number;
}
2 changes: 0 additions & 2 deletions client/apps/game/src/ui/constants.ts
Original file line number Diff line number Diff line change
@@ -4,5 +4,3 @@ export const UNDEFINED_STRUCTURE_ENTITY_ID = 0;

// todo: get this from the contract
export const PRIZE_POOL_GUILDS = 300000;
const PRIZE_POOL_CONTENT_CREATORS = 200000;
const PRIZE_POOL_ACHIEVEMENTS = 200000;
Loading

0 comments on commit ac860cc

Please sign in to comment.