Skip to content

Commit

Permalink
chore(Systems): Move system core from game/ to core/
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruptein authored Dec 26, 2024
1 parent 0e34345 commit 7127683
Show file tree
Hide file tree
Showing 132 changed files with 368 additions and 279 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tech changes will usually be stripped from release notes for the public
- [server] Assets:
- Assets are no longer stored in a flat folder structure, but instead use a subpath based structure
- An asset with hash `35eaef2e9a116aa152f7f161f1281411cb1e1375` is now stored as `assets/35/ea/35eaef2e9a116aa152f7f161f1281411cb1e1375`
- [tech] Systems: Move system-core from game/ to core/ so that it can also be used by e.g. assets

### Removed

Expand Down
2 changes: 1 addition & 1 deletion client/src/apiTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AssetId } from "./assetManager/models";
import type { GlobalId } from "./game/id";
import type { GlobalId } from "./core/id";
import type { LayerName } from "./game/models/floor";
import type { Role } from "./game/models/role";
import type { AuraId } from "./game/systems/auras/models";
Expand Down
2 changes: 1 addition & 1 deletion client/src/assetManager/models.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { NumberId } from "../game/id";
import type { NumberId } from "../core/id";

export type AssetId = NumberId<"assetId">;
2 changes: 1 addition & 1 deletion client/src/assetManager/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed } from "vue";

import type { ApiAsset } from "../apiTypes";
import { buildState } from "../game/systems/state";
import { buildState } from "../core/systems/state";

import type { AssetId } from "./models";

Expand Down
4 changes: 4 additions & 0 deletions client/src/core/id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type NumberId<T extends string> = number & { __brand: T };
export type StringId<T extends string> = string & { __brand: T };
export type GlobalId = StringId<"globalId">;
export type LocalId = NumberId<"localId">;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion client/src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tinycolor from "tinycolor2";

import type { GlobalId } from "../game/id";
import type { GlobalId } from "../core/id";

// Reference: https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
export function uuidv4(): GlobalId {
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/api/emits/initiative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
InitiativeOrderChange,
InitiativeValueSet,
} from "../../../apiTypes";
import type { GlobalId } from "../../id";
import type { GlobalId } from "../../../core/id";
import type { InitiativeSort } from "../../models/initiative";
import { wrapSocket } from "../helpers";
import { socket } from "../socket";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import "./events/user";

import type { ApiFloor, ApiLocationCore, PlayerPosition } from "../../apiTypes";
import { toGP } from "../../core/geometry";
import type { GlobalId } from "../../core/id";
import { SyncMode } from "../../core/models/types";
import type { AssetList } from "../../core/models/types";
import { debugLayers } from "../../localStorageHelpers";
Expand All @@ -41,7 +42,6 @@ import { convertAssetListToMap } from "../assets/utils";
import { clearGame } from "../clear";
import { addServerFloor } from "../floor/server";
import { getShapeFromGlobal } from "../id";
import type { GlobalId } from "../id";
import { setCenterPosition } from "../position";
import { deleteShapes } from "../shapes/utils";
import { floorSystem } from "../systems/floors";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/api/events/initiative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
InitiativeEffectTurns,
InitiativeOptionSet,
} from "../../../apiTypes";
import type { GlobalId } from "../../id";
import type { GlobalId } from "../../../core/id";
import type { InitiativeSort } from "../../models/initiative";
import { initiativeStore } from "../../ui/initiative/state";
import { socket } from "../socket";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/api/events/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {
LocationRename,
LocationSettingsSet,
} from "../../../apiTypes";
import type { GlobalId } from "../../../core/id";
import { coreStore } from "../../../store/core";
import { locationStore } from "../../../store/location";
import type { GlobalId } from "../../id";
import type { Location } from "../../models/settings";
import { gameSystem } from "../../systems/game";
import { playerSystem } from "../../systems/players";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/api/events/shape/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type {
ShapePositionUpdate,
ShapeRectSizeUpdate,
} from "../../../../apiTypes";
import type { GlobalId } from "../../../../core/id";
import { SyncMode } from "../../../../core/models/types";
import { activeShapeStore } from "../../../../store/activeShape";
import { getLocalId, getShapeFromGlobal } from "../../../id";
import type { GlobalId } from "../../../id";
import type { ICircle } from "../../../interfaces/shapes/circle";
import type { IRect } from "../../../interfaces/shapes/rect";
import { deleteShapes } from "../../../shapes/utils";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/api/events/shape/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type {
ShapeSetOptionalStringValue,
ShapeSetStringValue,
} from "../../../../apiTypes";
import type { GlobalId, LocalId } from "../../../../core/id";
import { UI_SYNC } from "../../../../core/models/types";
import type { Sync } from "../../../../core/models/types";
import { getLocalId, getShape } from "../../../id";
import type { GlobalId, LocalId } from "../../../id";
import type { IAsset } from "../../../interfaces/shapes/asset";
import { floorSystem } from "../../../systems/floors";
import { propertiesSystem } from "../../../systems/properties";
Expand Down
4 changes: 2 additions & 2 deletions client/src/game/clear.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { clearSystems } from "../core/systems";
import type { SystemClearReason } from "../core/systems/models";
import { locationStore } from "../store/location";

import { clearIds } from "./id";
import { compositeState } from "./layers/state";
import { stopDrawLoop } from "./rendering/core";
import { clearSystems } from "./systems";
import type { SystemClearReason } from "./systems/models";
import { initiativeStore } from "./ui/initiative/state";
import { visionState } from "./vision/state";

Expand Down
3 changes: 2 additions & 1 deletion client/src/game/colour.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tinycolor from "tinycolor2";

import type { LocalId } from "./id";
import type { LocalId } from "../core/id";

import { gameState } from "./systems/game/state";
import { locationSettingsState } from "./systems/settings/location/state";
import { playerSettingsState } from "./systems/settings/players/state";
Expand Down
8 changes: 2 additions & 6 deletions client/src/game/id.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import type { GlobalId, LocalId } from "../core/id";
import { dropFromSystems } from "../core/systems";
import { uuidv4 } from "../core/utils";

import type { IShape } from "./interfaces/shape";
import { dropFromSystems } from "./systems";

export type NumberId<T extends string> = number & { __brand: T };
export type StringId<T extends string> = string & { __brand: T };
export type GlobalId = StringId<"globalId">;
export type LocalId = NumberId<"localId">;

// Array of GlobalId indexed by localId
let uuids: GlobalId[] = [];
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/interfaces/layer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ApiShape } from "../../apiTypes";
import type { LocalId } from "../../core/id";
import type { InvalidationMode, SyncMode } from "../../core/models/types";
import type { LocalId } from "../id";
import type { FloorId, LayerName } from "../models/floor";
import type { BoundingRect } from "../shapes/variants/simple/boundingRect";

Expand Down
2 changes: 1 addition & 1 deletion client/src/game/interfaces/shape.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ApiShape } from "../../apiTypes";
import type { GlobalPoint, Vector } from "../../core/geometry";
import type { GridType } from "../../core/grid";
import type { LocalId } from "../id";
import type { LocalId } from "../../core/id";
import type { Floor, FloorId, LayerName } from "../models/floor";
import type { ServerShapeOptions, ShapeOptions } from "../models/shapes";
import type { DepShape, SHAPE_TYPE } from "../shapes/types";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/interfaces/shapes/toggleComposite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LocalId } from "../../../core/id";
import type { Sync } from "../../../core/models/types";
import type { LocalId } from "../../id";
import type { IShape } from "../shape";

export interface IToggleComposite extends IShape {
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/layers/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LocalId } from "../../core/id";
import { sendToggleCompositeAddVariant } from "../api/emits/shape/toggleComposite";
import { getGlobalId, getShape } from "../id";
import type { LocalId } from "../id";
import type { IShape } from "../interfaces/shape";
import type { IToggleComposite } from "../interfaces/shapes/toggleComposite";

Expand Down
2 changes: 1 addition & 1 deletion client/src/game/layers/variants/fowLighting.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { g2l, g2lz, g2lr, toRadians } from "../../../core/conversions";
import type { LocalId } from "../../../core/id";
import type { SyncMode, InvalidationMode } from "../../../core/models/types";
import { FOG_COLOUR } from "../../colour";
import { getShape } from "../../id";
import type { LocalId } from "../../id";
import type { IShape } from "../../interfaces/shape";
import { LayerName } from "../../models/floor";
import { accessState } from "../../systems/access/state";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/layers/variants/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { toRaw } from "vue";
import type { ApiShape } from "../../../apiTypes";
import { g2l, l2g, l2gz } from "../../../core/conversions";
import { Ray, cloneP, toLP } from "../../../core/geometry";
import type { LocalId } from "../../../core/id";
import { filter } from "../../../core/iter";
import { InvalidationMode, SyncMode, UI_SYNC } from "../../../core/models/types";
import { callbackProvider } from "../../../core/utils";
import { debugLayers } from "../../../localStorageHelpers";
import { activeShapeStore } from "../../../store/activeShape";
import { sendRemoveShapes, sendShapeAdd, sendShapeOrder } from "../../api/emits/shape/core";
import { dropId, getGlobalId, getShape } from "../../id";
import type { LocalId } from "../../id";
import type { ILayer } from "../../interfaces/layer";
import type { IShape } from "../../interfaces/shape";
import { LayerName } from "../../models/floor";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/models/floor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NumberId } from "../id";
import type { NumberId } from "../../core/id";

export type FloorId = NumberId<"floorId">;
export type FloorIndex = NumberId<"floorIndex">;
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/models/initiative.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GlobalId, LocalId } from "../id";
import type { GlobalId, LocalId } from "../../core/id";

interface CommonInitiativeData {
initiative?: number;
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/models/shapes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Vector } from "../../core/geometry";
import type { LocalId } from "../id";
import type { LocalId } from "../../core/id";
import type { DoorOptions } from "../systems/logic/door/models";
import type { TeleportOptions } from "../systems/logic/tp/models";

Expand Down
2 changes: 1 addition & 1 deletion client/src/game/operations/model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ApiShape } from "../../apiTypes";
import type { GlobalPoint } from "../../core/geometry";
import type { LocalId } from "../id";
import type { LocalId } from "../../core/id";
import type { LayerName } from "../models/floor";

export type Operation =
Expand Down
3 changes: 2 additions & 1 deletion client/src/game/operations/movement.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { addP, toArrayP } from "../../core/geometry";
import type { Vector } from "../../core/geometry";
import type { LocalId } from "../../core/id";
import { sendShapePositionUpdate } from "../api/emits/shape/core";
import { getShape, type LocalId } from "../id";
import { getShape } from "../id";
import type { IShape } from "../interfaces/shape";
import { accessSystem } from "../systems/access";
import { clientSystem } from "../systems/client";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/operations/undo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ApiShape } from "../../apiTypes";
import { toGP, Vector } from "../../core/geometry";
import type { GlobalPoint } from "../../core/geometry";
import type { LocalId } from "../../core/id";
import { SyncMode } from "../../core/models/types";
import { getLocalId, getShape } from "../id";
import type { LocalId } from "../id";
import type { LayerName } from "../models/floor";
import { ToolName } from "../models/tools";
import type { ISelectTool } from "../models/tools";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
snapPointToGrid,
snapShapeToGrid,
} from "../../core/grid";
import type { GlobalId, LocalId } from "../../core/id";
import { rotateAroundPoint } from "../../core/math";
import { mostReadable } from "../../core/utils";
import { generateLocalId, dropId } from "../id";
import type { GlobalId, LocalId } from "../id";
import type { ILayer } from "../interfaces/layer";
import type { IShape } from "../interfaces/shape";
import { LayerName } from "../models/floor";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type {
ApiTracker,
} from "../../apiTypes";
import { subtractP, Vector } from "../../core/geometry";
import type { GlobalId } from "../../core/id";
import { SyncMode, InvalidationMode } from "../../core/models/types";
import { uuidv4 } from "../../core/utils";
import { sendRemoveShapes } from "../api/emits/shape/core";
import { getGlobalId, getLocalId } from "../id";
import type { GlobalId } from "../id";
import type { IShape } from "../interfaces/shape";
import type { LayerName } from "../models/floor";
import { addOperation } from "../operations/undo";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { g2l, g2lz } from "../../../core/conversions";
import { toGP } from "../../../core/geometry";
import type { GlobalPoint } from "../../../core/geometry";
import { baseAdjust } from "../../../core/http";
import type { GlobalId, LocalId } from "../../../core/id";
import { map } from "../../../core/iter";
import { InvalidationMode, SyncMode } from "../../../core/models/types";
import { sendAssetRectImageChange } from "../../api/emits/shape/asset";
import { FOG_COLOUR } from "../../colour";
import { getGlobalId } from "../../id";
import type { GlobalId, LocalId } from "../../id";
import type { IAsset } from "../../interfaces/shapes/asset";
import { LayerName } from "../../models/floor";
import type { ServerShapeOptions } from "../../models/shapes";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/baseRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { ApiBaseRectShape, ApiShape } from "../../../apiTypes";
import { g2lx, g2ly } from "../../../core/conversions";
import { addP, cloneP, toGP, Vector } from "../../../core/geometry";
import type { GlobalPoint } from "../../../core/geometry";
import type { GlobalId, LocalId } from "../../../core/id";
import { rotateAroundPoint } from "../../../core/math";
import type { GlobalId, LocalId } from "../../id";
import type { IShape } from "../../interfaces/shape";
import type { ServerShapeOptions } from "../../models/shapes";
import type { ShapeProperties } from "../../systems/properties/state";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { ApiCircleShape } from "../../../apiTypes";
import { g2lz } from "../../../core/conversions";
import { addP, subtractP, toArrayP, toGP, Vector } from "../../../core/geometry";
import type { GlobalPoint } from "../../../core/geometry";
import type { GlobalId, LocalId } from "../../../core/id";
import { getColour } from "../../colour";
import type { GlobalId, LocalId } from "../../id";
import type { IShape } from "../../interfaces/shape";
import type { ServerShapeOptions } from "../../models/shapes";
import { getProperties } from "../../systems/properties/state";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/circularToken.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ApiCircularTokenShape } from "../../../apiTypes";
import { g2l, g2lz } from "../../../core/conversions";
import type { GlobalPoint } from "../../../core/geometry";
import type { GlobalId, LocalId } from "../../../core/id";
import { SyncMode } from "../../../core/models/types";
import { calcFontScale, mostReadable } from "../../../core/utils";
import { sendCircularTokenUpdate } from "../../api/emits/shape/circularToken";
import { getColour } from "../../colour";
import { getGlobalId } from "../../id";
import type { GlobalId, LocalId } from "../../id";
import type { IShape } from "../../interfaces/shape";
import type { ServerShapeOptions } from "../../models/shapes";
import { getProperties } from "../../systems/properties/state";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/fontAwesomeIcon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type IconLookup, findIconDefinition, icon, type IconDefinition } from "@fortawesome/fontawesome-svg-core";

import type { GlobalPoint } from "../../../core/geometry";
import type { GlobalId, LocalId } from "../../id";
import type { GlobalId, LocalId } from "../../../core/id";
import type { IAsset } from "../../interfaces/shapes/asset";
import type { SHAPE_TYPE } from "../types";

Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/hex.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type GlobalPoint } from "../../../core/geometry";
import type { GridType } from "../../../core/grid";
import type { GlobalId, LocalId } from "../../id";
import type { GlobalId, LocalId } from "../../../core/id";
import { createHex } from "../../rendering/grid";

import { Polygon } from "./polygon";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { ApiLineShape } from "../../../apiTypes";
import { g2l, g2lx, g2ly, g2lz } from "../../../core/conversions";
import { addP, subtractP, toArrayP, toGP } from "../../../core/geometry";
import type { GlobalPoint } from "../../../core/geometry";
import type { GlobalId, LocalId } from "../../../core/id";
import { rotateAroundPoint } from "../../../core/math";
import { getColour } from "../../colour";
import type { GlobalId, LocalId } from "../../id";
import type { IShape } from "../../interfaces/shape";
import { getProperties } from "../../systems/properties/state";
import type { ShapeProperties } from "../../systems/properties/state";
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/shapes/variants/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type { ApiPolygonShape } from "../../../apiTypes";
import { g2l, g2lz, toDegrees } from "../../../core/conversions";
import { Vector, addP, getAngleBetween, getDistanceToSegment, subtractP, toArrayP, toGP } from "../../../core/geometry";
import type { GlobalPoint } from "../../../core/geometry";
import type { GlobalId, LocalId } from "../../../core/id";
import { equalPoints, filterEqualPoints, getPointsCenter, rotateAroundPoint } from "../../../core/math";
import { InvalidationMode, SyncMode } from "../../../core/models/types";
import { uuidv4 } from "../../../core/utils";
import { sendShapePositionUpdate } from "../../api/emits/shape/core";
import { getColour } from "../../colour";
import { getGlobalId } from "../../id";
import type { GlobalId, LocalId } from "../../id";
import type { IShape } from "../../interfaces/shape";
import type { ServerShapeOptions } from "../../models/shapes";
import type { AuraId } from "../../systems/auras/models";
Expand Down
3 changes: 1 addition & 2 deletions client/src/game/shapes/variants/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { ApiTextShape } from "../../../apiTypes";
import { g2lz, l2gz } from "../../../core/conversions";
import { addP, toGP, Vector } from "../../../core/geometry";
import type { GlobalPoint } from "../../../core/geometry";
import type { GlobalId, LocalId } from "../../../core/id";
import { rotateAroundPoint } from "../../../core/math";
import { SyncMode } from "../../../core/models/types";
import { sendTextUpdate } from "../../api/emits/shape/text";
import { getGlobalId } from "../../id";
import type { GlobalId, LocalId } from "../../id";
import type { IText } from "../../interfaces/shapes/text";
import { getProperties } from "../../systems/properties/state";
import type { ShapeProperties } from "../../systems/properties/state";
Expand Down Expand Up @@ -113,7 +113,6 @@ export class Text extends Shape implements IText {
return this.getBoundingBox().visibleInCanvas(max);
}


resize(resizePoint: number, point: GlobalPoint): number {
point = rotateAroundPoint(point, this.center, -this.angle);

Expand Down
Loading

0 comments on commit 7127683

Please sign in to comment.