diff --git a/src/AI/AIManager.ts b/src/AI/AIManager.ts index ef45538..990e178 100644 --- a/src/AI/AIManager.ts +++ b/src/AI/AIManager.ts @@ -1,4 +1,6 @@ -import { Actor, AI, Updateable } from "../DataTypes/Interfaces/Descriptors"; +import Actor from "../DataTypes/Interfaces/Actor"; +import Updateable from "../DataTypes/Interfaces/Updateable"; +import AI from "../DataTypes/Interfaces/AI"; import Map from "../DataTypes/Map"; /** diff --git a/src/AI/StateMachineAI.ts b/src/AI/StateMachineAI.ts index eafd448..7322544 100644 --- a/src/AI/StateMachineAI.ts +++ b/src/AI/StateMachineAI.ts @@ -1,4 +1,4 @@ -import { AI } from "../DataTypes/Interfaces/Descriptors"; +import AI from "../DataTypes/Interfaces/AI"; import StateMachine from "../DataTypes/State/StateMachine"; import GameNode from "../Nodes/GameNode"; diff --git a/src/DataTypes/Graphs/PositionGraph.ts b/src/DataTypes/Graphs/PositionGraph.ts index c6fb453..cca9d77 100644 --- a/src/DataTypes/Graphs/PositionGraph.ts +++ b/src/DataTypes/Graphs/PositionGraph.ts @@ -1,6 +1,6 @@ import Graph, { MAX_V } from "./Graph"; import Vec2 from "../Vec2"; -import { DebugRenderable } from "../Interfaces/Descriptors"; +import DebugRenderable from "../Interfaces/DebugRenderable"; /** * An extension of Graph that has nodes with positions in 2D space. diff --git a/src/DataTypes/Interfaces/AI.ts b/src/DataTypes/Interfaces/AI.ts new file mode 100644 index 0000000..3e544fc --- /dev/null +++ b/src/DataTypes/Interfaces/AI.ts @@ -0,0 +1,10 @@ +import GameNode from "../../Nodes/GameNode"; +import Updateable from "./Updateable"; + +/** + * Defines a controller for a bot or a human. Must be able to update + */ +export default interface AI extends Updateable { + /** Initializes the AI with the actor and any additional config */ + initializeAI(owner: GameNode, options: Record): void; +} \ No newline at end of file diff --git a/src/DataTypes/Interfaces/Actor.ts b/src/DataTypes/Interfaces/Actor.ts new file mode 100644 index 0000000..ea7947d --- /dev/null +++ b/src/DataTypes/Interfaces/Actor.ts @@ -0,0 +1,35 @@ +import NavigationPath from "../../Pathfinding/NavigationPath"; +import AI from "./AI"; + +/** + * A game object that has an AI and can perform its own actions every update cycle + */ +export default interface Actor { + /** The AI of the actor */ + ai: AI; + + /** The activity status of the actor */ + aiActive: boolean; + + /** The id of the actor according to the @reference[AIManager] */ + actorId: number; + + /** The path that navigation will follow */ + path: NavigationPath; + + /** A flag representing whether or not the actor is currently pathfinding */ + pathfinding: boolean; + + /** + * Adds an AI to this Actor. + * @param ai The name of the AI, or the actual AI, to add to the Actor. + * @param options The options to give to the AI for initialization. + */ + addAI(ai: string | (new () => T), options: Record): void; + + /** + * Sets the AI to start/stop for this Actor. + * @param active The new active status of the AI. + */ + setAIActive(active: boolean): void; +} \ No newline at end of file diff --git a/src/DataTypes/Interfaces/DebugRenderable.ts b/src/DataTypes/Interfaces/DebugRenderable.ts new file mode 100644 index 0000000..b440c7c --- /dev/null +++ b/src/DataTypes/Interfaces/DebugRenderable.ts @@ -0,0 +1,7 @@ +/** + * Represents a game object that can be rendered in Debug mode + */ +export default interface DebugRenderable { + /** Renders the debugging information for this object. */ + debugRender(): void; +} \ No newline at end of file diff --git a/src/DataTypes/Interfaces/Navigable.ts b/src/DataTypes/Interfaces/Navigable.ts new file mode 100644 index 0000000..8f80c0f --- /dev/null +++ b/src/DataTypes/Interfaces/Navigable.ts @@ -0,0 +1,12 @@ +import Vec2 from "../Vec2"; +import NavigationPath from "../../Pathfinding/NavigationPath"; + +/** Represents an entity that can be navigated on. */ +export default interface Navigable { + /** + * Gets a new navigation path based on this Navigable object. + * @param fromPosition The position to start navigation from. + * @param toPosition The position to navigate to. + */ + getNavigationPath(fromPosition: Vec2, toPosition: Vec2): NavigationPath; +} \ No newline at end of file diff --git a/src/DataTypes/Interfaces/Descriptors.ts b/src/DataTypes/Interfaces/Physical.ts similarity index 55% rename from src/DataTypes/Interfaces/Descriptors.ts rename to src/DataTypes/Interfaces/Physical.ts index dc08c60..ba1e94a 100644 --- a/src/DataTypes/Interfaces/Descriptors.ts +++ b/src/DataTypes/Interfaces/Physical.ts @@ -1,47 +1,12 @@ -import Map from "../Map"; -import AABB from "../Shapes/AABB"; import Shape from "../Shapes/Shape"; +import AABB from "../Shapes/AABB"; import Vec2 from "../Vec2"; -import NavigationPath from "../../Pathfinding/NavigationPath"; -import GameNode from "../../Nodes/GameNode"; - -// @ignorePage - -export interface Unique { - /** The unique id of this object. */ - id: number; -} - -export interface Positioned { - /** The center of this object. */ - position: Vec2; - - /** The center of this object relative to the viewport. */ - readonly relativePosition: Vec2; -} - -export interface Region { - /** The size of this object. */ - size: Vec2; - - /** The scale of this object. */ - scale: Vec2; - - /** The size of the object taking into account the zoom and scale */ - readonly sizeWithZoom: Vec2; - - /** The bounding box of this object. */ - boundary: AABB; -} - -export function isRegion(arg: any): boolean { - return arg && arg.size && arg.scale && arg.boundary; -} +import Map from "../Map"; /** * Describes an object that can opt into physics. */ -export interface Physical { +export default interface Physical { /** A flag for whether or not this object has initialized game physics. */ hasPhysics: boolean; @@ -136,64 +101,4 @@ export interface Physical { * If used before "move()", it will tell you the velocity of the node after its last movement */ getLastVelocity(): Vec2; -} - -/** - * Defines a controller for a bot or a human. Must be able to update - */ -export interface AI extends Updateable { - /** Initializes the AI with the actor and any additional config */ - initializeAI: (owner: GameNode, options: Record) => void; -} - -export interface Actor { - /** The AI of the actor */ - ai: AI; - - /** The activity status of the actor */ - aiActive: boolean; - - /** The id of the actor according to the AIManager */ - actorId: number; - - /** The path that navigation will follow */ - path: NavigationPath; - - /** A flag representing whether or not the actor is currently pathfinding */ - pathfinding: boolean; - - /** - * Adds an AI to this Actor. - * @param ai The name of the AI, or the actual AI, to add to the Actor. - * @param options The options to give to the AI for initialization. - */ - addAI(ai: string | (new () => T), options: Record): void; - - /** - * Sets the AI to start/stop for this Actor. - * @param active The new active status of the AI. - */ - setAIActive(active: boolean): void; -} - -export interface Navigable { - /** - * Gets a new navigation path based on this Navigable object. - * @param fromPosition The position to start navigation from. - * @param toPosition The position to navigate to. - */ - getNavigationPath(fromPosition: Vec2, toPosition: Vec2): NavigationPath; -} - -export interface Updateable { - /** - * Updates this object. - * @param deltaT The timestep of the update. - */ - update(deltaT: number): void; -} - -export interface DebugRenderable { - /** Renders the debugging infor for this object. */ - debugRender(): void; } \ No newline at end of file diff --git a/src/DataTypes/Interfaces/Positioned.ts b/src/DataTypes/Interfaces/Positioned.ts new file mode 100644 index 0000000..9da68e8 --- /dev/null +++ b/src/DataTypes/Interfaces/Positioned.ts @@ -0,0 +1,10 @@ +import Vec2 from "../Vec2"; + +/** An object that has a position */ +export default interface Positioned { + /** The center of this object. */ + position: Vec2; + + /** The center of this object relative to the viewport. */ + readonly relativePosition: Vec2; +} \ No newline at end of file diff --git a/src/DataTypes/Interfaces/Region.ts b/src/DataTypes/Interfaces/Region.ts new file mode 100644 index 0000000..019fce3 --- /dev/null +++ b/src/DataTypes/Interfaces/Region.ts @@ -0,0 +1,21 @@ +import Vec2 from "../Vec2"; +import AABB from "../Shapes/AABB"; + +/** An object that is a region, with a size, scale, and boundary. */ +export default interface Region { + /** The size of this object. */ + size: Vec2; + + /** The scale of this object. */ + scale: Vec2; + + /** The size of the object taking into account the zoom and scale */ + readonly sizeWithZoom: Vec2; + + /** The bounding box of this object. */ + boundary: AABB; +} + +export function isRegion(arg: any): boolean { + return arg && arg.size && arg.scale && arg.boundary; +} \ No newline at end of file diff --git a/src/DataTypes/Interfaces/Unique.ts b/src/DataTypes/Interfaces/Unique.ts new file mode 100644 index 0000000..7e04e25 --- /dev/null +++ b/src/DataTypes/Interfaces/Unique.ts @@ -0,0 +1,7 @@ +/** + * Represents an object with a unique id + */ +export default interface Unique { + /** The unique id of this object. */ + id: number; +} \ No newline at end of file diff --git a/src/DataTypes/Interfaces/Updateable.ts b/src/DataTypes/Interfaces/Updateable.ts new file mode 100644 index 0000000..0df2cf6 --- /dev/null +++ b/src/DataTypes/Interfaces/Updateable.ts @@ -0,0 +1,8 @@ +/** Represents a game object that can be updated */ +export default interface Updateable { + /** + * Updates this object. + * @param deltaT The timestep of the update. + */ + update(deltaT: number): void; +} \ No newline at end of file diff --git a/src/DataTypes/QuadTree.ts b/src/DataTypes/QuadTree.ts index a84f4d4..25c77d5 100644 --- a/src/DataTypes/QuadTree.ts +++ b/src/DataTypes/QuadTree.ts @@ -1,7 +1,7 @@ import Vec2 from "./Vec2"; import Collection from "./Collection"; -import AABB from "./AABB" -import { Positioned } from "./Interfaces/Descriptors"; +import AABB from "./Shapes/AABB" +import Positioned from "./Interfaces/Positioned"; // TODO - Make max depth @@ -63,7 +63,7 @@ export default class QuadTree implements Collection { */ insert(item: T){ // If the item is inside of the bounds of this quadtree - if(this.boundary.containsPointSoft(item.getPosition())){ + if(this.boundary.containsPointSoft(item.position)){ if(this.divided){ // Defer to the children this.deferInsert(item); diff --git a/src/DataTypes/RegionQuadTree.ts b/src/DataTypes/RegionQuadTree.ts index 9107356..b8d19fe 100644 --- a/src/DataTypes/RegionQuadTree.ts +++ b/src/DataTypes/RegionQuadTree.ts @@ -1,9 +1,9 @@ import Vec2 from "./Vec2"; import Collection from "./Collection"; -import AABB from "./Shapes/AABB" -import { Region, Unique } from "./Interfaces/Descriptors"; +import AABB from "./Shapes/AABB"; +import Region from "./Interfaces/Region"; +import Unique from "./Interfaces/Unique"; import Map from "./Map"; -import Stats from "../Debug/Stats"; /** * A quadtree data structure implemented to work with regions rather than points. diff --git a/src/DataTypes/State/State.ts b/src/DataTypes/State/State.ts index 57b3f0a..9ed22f9 100644 --- a/src/DataTypes/State/State.ts +++ b/src/DataTypes/State/State.ts @@ -1,6 +1,6 @@ import Emitter from "../../Events/Emitter"; import GameEvent from "../../Events/GameEvent"; -import { Updateable } from "../Interfaces/Descriptors"; +import Updateable from "../Interfaces/Updateable"; import StateMachine from "./StateMachine"; /** diff --git a/src/DataTypes/State/StateMachine.ts b/src/DataTypes/State/StateMachine.ts index b3772b8..bd6fd5d 100644 --- a/src/DataTypes/State/StateMachine.ts +++ b/src/DataTypes/State/StateMachine.ts @@ -4,7 +4,7 @@ import Map from "../Map"; import GameEvent from "../../Events/GameEvent"; import Receiver from "../../Events/Receiver"; import Emitter from "../../Events/Emitter"; -import { Updateable } from "../Interfaces/Descriptors"; +import Updateable from "../Interfaces/Updateable"; /** * An implementation of a Push Down Automata State machine. States can also be hierarchical diff --git a/src/Nodes/CanvasNode.ts b/src/Nodes/CanvasNode.ts index 6aa42eb..b059462 100644 --- a/src/Nodes/CanvasNode.ts +++ b/src/Nodes/CanvasNode.ts @@ -1,6 +1,6 @@ import GameNode from "./GameNode"; import Vec2 from "../DataTypes/Vec2"; -import { Region } from "../DataTypes/Interfaces/Descriptors"; +import Region from "../DataTypes/Interfaces/Region"; import AABB from "../DataTypes/Shapes/AABB"; import Debug from "../Debug/Debug"; import Color from "../Utils/Color"; diff --git a/src/Nodes/GameNode.ts b/src/Nodes/GameNode.ts index 9072ea8..c674ab9 100644 --- a/src/Nodes/GameNode.ts +++ b/src/Nodes/GameNode.ts @@ -4,7 +4,14 @@ import Receiver from "../Events/Receiver"; import Emitter from "../Events/Emitter"; import Scene from "../Scene/Scene"; import Layer from "../Scene/Layer"; -import { Physical, Positioned, isRegion, Unique, Updateable, Actor, AI, DebugRenderable } from "../DataTypes/Interfaces/Descriptors" +import AI from "../DataTypes/Interfaces/AI"; +import Physical from "../DataTypes/Interfaces/Physical"; +import Positioned from "../DataTypes/Interfaces/Positioned"; +import { isRegion } from "../DataTypes/Interfaces/Region"; +import Unique from "../DataTypes/Interfaces/Unique"; +import Updateable from "../DataTypes/Interfaces/Updateable"; +import DebugRenderable from "../DataTypes/Interfaces/DebugRenderable"; +import Actor from "../DataTypes/Interfaces/Actor"; import Shape from "../DataTypes/Shapes/Shape"; import Map from "../DataTypes/Map"; import AABB from "../DataTypes/Shapes/AABB"; diff --git a/src/Pathfinding/NavigationManager.ts b/src/Pathfinding/NavigationManager.ts index 5ebaff5..1daf89d 100644 --- a/src/Pathfinding/NavigationManager.ts +++ b/src/Pathfinding/NavigationManager.ts @@ -1,4 +1,4 @@ -import { Navigable } from "../DataTypes/Interfaces/Descriptors" +import Navigable from "../DataTypes/Interfaces/Navigable"; import Map from "../DataTypes/Map"; import Vec2 from "../DataTypes/Vec2"; import NavigationPath from "./NavigationPath"; diff --git a/src/Pathfinding/Navmesh.ts b/src/Pathfinding/Navmesh.ts index 58aa9ed..4b62765 100644 --- a/src/Pathfinding/Navmesh.ts +++ b/src/Pathfinding/Navmesh.ts @@ -1,5 +1,5 @@ import PositionGraph from "../DataTypes/Graphs/PositionGraph"; -import { Navigable } from "../DataTypes/Interfaces/Descriptors"; +import Navigable from "../DataTypes/Interfaces/Navigable"; import Stack from "../DataTypes/Stack"; import Vec2 from "../DataTypes/Vec2"; import GraphUtils from "../Utils/GraphUtils"; diff --git a/src/Physics/BasicPhysicsManager.ts b/src/Physics/BasicPhysicsManager.ts index 9881dab..8e1fc9c 100644 --- a/src/Physics/BasicPhysicsManager.ts +++ b/src/Physics/BasicPhysicsManager.ts @@ -1,4 +1,4 @@ -import { Physical } from "../DataTypes/Interfaces/Descriptors"; +import Physical from "../DataTypes/Interfaces/Physical"; import Vec2 from "../DataTypes/Vec2"; import GameNode from "../Nodes/GameNode"; import Tilemap from "../Nodes/Tilemap"; diff --git a/src/Physics/BroadPhaseAlgorithms/BroadPhase.ts b/src/Physics/BroadPhaseAlgorithms/BroadPhase.ts index 26baa4b..fbace68 100644 --- a/src/Physics/BroadPhaseAlgorithms/BroadPhase.ts +++ b/src/Physics/BroadPhaseAlgorithms/BroadPhase.ts @@ -1,4 +1,4 @@ -import { Physical } from "../../DataTypes/Interfaces/Descriptors"; +import Physical from "../../DataTypes/Interfaces/Physical"; import GameNode from "../../Nodes/GameNode"; // @ignorePage diff --git a/src/Physics/BroadPhaseAlgorithms/SweepAndPrune.ts b/src/Physics/BroadPhaseAlgorithms/SweepAndPrune.ts index 6d939e5..ac0e898 100644 --- a/src/Physics/BroadPhaseAlgorithms/SweepAndPrune.ts +++ b/src/Physics/BroadPhaseAlgorithms/SweepAndPrune.ts @@ -1,5 +1,4 @@ -import { Physical } from "../../DataTypes/Interfaces/Descriptors"; -import PhysicsUtils from "../../Utils/PhysicsUtils"; +import Physical from "../../DataTypes/Interfaces/Physical"; import SortingUtils from "../../Utils/SortingUtils"; import BroadPhase from "./BroadPhase"; diff --git a/src/Physics/Collisions.ts b/src/Physics/Collisions.ts index 6342312..df3339c 100644 --- a/src/Physics/Collisions.ts +++ b/src/Physics/Collisions.ts @@ -1,4 +1,4 @@ -import { Physical } from "../DataTypes/Interfaces/Descriptors"; +import Physical from "../DataTypes/Interfaces/Physical"; import Vec2 from "../DataTypes/Vec2"; // @ignorePage diff --git a/src/Physics/PhysicsManager.ts b/src/Physics/PhysicsManager.ts index 2583a9d..be85765 100644 --- a/src/Physics/PhysicsManager.ts +++ b/src/Physics/PhysicsManager.ts @@ -1,6 +1,5 @@ import GameNode from "../Nodes/GameNode"; -import Vec2 from "../DataTypes/Vec2"; -import { Updateable } from "../DataTypes/Interfaces/Descriptors"; +import Updateable from "../DataTypes/Interfaces/Updateable"; import Tilemap from "../Nodes/Tilemap"; import Receiver from "../Events/Receiver"; import Emitter from "../Events/Emitter"; diff --git a/src/Physics/TestPhysicsManager.ts b/src/Physics/TestPhysicsManager.ts index 3e0c7e8..dc32486 100644 --- a/src/Physics/TestPhysicsManager.ts +++ b/src/Physics/TestPhysicsManager.ts @@ -1,5 +1,5 @@ import GameNode from "../Nodes/GameNode"; -import { Physical } from "../DataTypes/Interfaces/Descriptors"; +import Physical from "../DataTypes/Interfaces/Physical"; import Tilemap from "../Nodes/Tilemap"; import PhysicsManager from "./PhysicsManager"; import Vec2 from "../DataTypes/Vec2"; diff --git a/src/Scene/Scene.ts b/src/Scene/Scene.ts index 3280b0e..dae194d 100644 --- a/src/Scene/Scene.ts +++ b/src/Scene/Scene.ts @@ -12,7 +12,7 @@ import GameLoop from "../Loop/GameLoop"; import SceneManager from "./SceneManager"; import Receiver from "../Events/Receiver"; import Emitter from "../Events/Emitter"; -import { Updateable } from "../DataTypes/Interfaces/Descriptors"; +import Updateable from "../DataTypes/Interfaces/Updateable"; import NavigationManager from "../Pathfinding/NavigationManager"; import AIManager from "../AI/AIManager"; import Map from "../DataTypes/Map";