organized docs and split up interface file

This commit is contained in:
Joe Weaver 2021-01-26 10:08:38 -05:00
parent 9e0ebae63c
commit 34b9a2d71d
27 changed files with 144 additions and 122 deletions

View File

@ -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"; import Map from "../DataTypes/Map";
/** /**

View File

@ -1,4 +1,4 @@
import { AI } from "../DataTypes/Interfaces/Descriptors"; import AI from "../DataTypes/Interfaces/AI";
import StateMachine from "../DataTypes/State/StateMachine"; import StateMachine from "../DataTypes/State/StateMachine";
import GameNode from "../Nodes/GameNode"; import GameNode from "../Nodes/GameNode";

View File

@ -1,6 +1,6 @@
import Graph, { MAX_V } from "./Graph"; import Graph, { MAX_V } from "./Graph";
import Vec2 from "../Vec2"; 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. * An extension of Graph that has nodes with positions in 2D space.

View File

@ -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<string, any>): void;
}

View File

@ -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<T extends AI>(ai: string | (new () => T), options: Record<string, any>): void;
/**
* Sets the AI to start/stop for this Actor.
* @param active The new active status of the AI.
*/
setAIActive(active: boolean): void;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,47 +1,12 @@
import Map from "../Map";
import AABB from "../Shapes/AABB";
import Shape from "../Shapes/Shape"; import Shape from "../Shapes/Shape";
import AABB from "../Shapes/AABB";
import Vec2 from "../Vec2"; import Vec2 from "../Vec2";
import NavigationPath from "../../Pathfinding/NavigationPath"; import Map from "../Map";
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;
}
/** /**
* Describes an object that can opt into physics. * 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. */ /** A flag for whether or not this object has initialized game physics. */
hasPhysics: boolean; 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 * If used before "move()", it will tell you the velocity of the node after its last movement
*/ */
getLastVelocity(): Vec2; 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<string, any>) => 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<T extends AI>(ai: string | (new () => T), options: Record<string, any>): 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;
} }

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,7 @@
/**
* Represents an object with a unique id
*/
export default interface Unique {
/** The unique id of this object. */
id: number;
}

View File

@ -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;
}

View File

@ -1,7 +1,7 @@
import Vec2 from "./Vec2"; import Vec2 from "./Vec2";
import Collection from "./Collection"; import Collection from "./Collection";
import AABB from "./AABB" import AABB from "./Shapes/AABB"
import { Positioned } from "./Interfaces/Descriptors"; import Positioned from "./Interfaces/Positioned";
// TODO - Make max depth // TODO - Make max depth
@ -63,7 +63,7 @@ export default class QuadTree<T extends Positioned> implements Collection {
*/ */
insert(item: T){ insert(item: T){
// If the item is inside of the bounds of this quadtree // 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){ if(this.divided){
// Defer to the children // Defer to the children
this.deferInsert(item); this.deferInsert(item);

View File

@ -1,9 +1,9 @@
import Vec2 from "./Vec2"; import Vec2 from "./Vec2";
import Collection from "./Collection"; import Collection from "./Collection";
import AABB from "./Shapes/AABB" import AABB from "./Shapes/AABB";
import { Region, Unique } from "./Interfaces/Descriptors"; import Region from "./Interfaces/Region";
import Unique from "./Interfaces/Unique";
import Map from "./Map"; import Map from "./Map";
import Stats from "../Debug/Stats";
/** /**
* A quadtree data structure implemented to work with regions rather than points. * A quadtree data structure implemented to work with regions rather than points.

View File

@ -1,6 +1,6 @@
import Emitter from "../../Events/Emitter"; import Emitter from "../../Events/Emitter";
import GameEvent from "../../Events/GameEvent"; import GameEvent from "../../Events/GameEvent";
import { Updateable } from "../Interfaces/Descriptors"; import Updateable from "../Interfaces/Updateable";
import StateMachine from "./StateMachine"; import StateMachine from "./StateMachine";
/** /**

View File

@ -4,7 +4,7 @@ import Map from "../Map";
import GameEvent from "../../Events/GameEvent"; import GameEvent from "../../Events/GameEvent";
import Receiver from "../../Events/Receiver"; import Receiver from "../../Events/Receiver";
import Emitter from "../../Events/Emitter"; 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 * An implementation of a Push Down Automata State machine. States can also be hierarchical

View File

@ -1,6 +1,6 @@
import GameNode from "./GameNode"; import GameNode from "./GameNode";
import Vec2 from "../DataTypes/Vec2"; import Vec2 from "../DataTypes/Vec2";
import { Region } from "../DataTypes/Interfaces/Descriptors"; import Region from "../DataTypes/Interfaces/Region";
import AABB from "../DataTypes/Shapes/AABB"; import AABB from "../DataTypes/Shapes/AABB";
import Debug from "../Debug/Debug"; import Debug from "../Debug/Debug";
import Color from "../Utils/Color"; import Color from "../Utils/Color";

View File

@ -4,7 +4,14 @@ import Receiver from "../Events/Receiver";
import Emitter from "../Events/Emitter"; import Emitter from "../Events/Emitter";
import Scene from "../Scene/Scene"; import Scene from "../Scene/Scene";
import Layer from "../Scene/Layer"; 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 Shape from "../DataTypes/Shapes/Shape";
import Map from "../DataTypes/Map"; import Map from "../DataTypes/Map";
import AABB from "../DataTypes/Shapes/AABB"; import AABB from "../DataTypes/Shapes/AABB";

View File

@ -1,4 +1,4 @@
import { Navigable } from "../DataTypes/Interfaces/Descriptors" import Navigable from "../DataTypes/Interfaces/Navigable";
import Map from "../DataTypes/Map"; import Map from "../DataTypes/Map";
import Vec2 from "../DataTypes/Vec2"; import Vec2 from "../DataTypes/Vec2";
import NavigationPath from "./NavigationPath"; import NavigationPath from "./NavigationPath";

View File

@ -1,5 +1,5 @@
import PositionGraph from "../DataTypes/Graphs/PositionGraph"; import PositionGraph from "../DataTypes/Graphs/PositionGraph";
import { Navigable } from "../DataTypes/Interfaces/Descriptors"; import Navigable from "../DataTypes/Interfaces/Navigable";
import Stack from "../DataTypes/Stack"; import Stack from "../DataTypes/Stack";
import Vec2 from "../DataTypes/Vec2"; import Vec2 from "../DataTypes/Vec2";
import GraphUtils from "../Utils/GraphUtils"; import GraphUtils from "../Utils/GraphUtils";

View File

@ -1,4 +1,4 @@
import { Physical } from "../DataTypes/Interfaces/Descriptors"; import Physical from "../DataTypes/Interfaces/Physical";
import Vec2 from "../DataTypes/Vec2"; import Vec2 from "../DataTypes/Vec2";
import GameNode from "../Nodes/GameNode"; import GameNode from "../Nodes/GameNode";
import Tilemap from "../Nodes/Tilemap"; import Tilemap from "../Nodes/Tilemap";

View File

@ -1,4 +1,4 @@
import { Physical } from "../../DataTypes/Interfaces/Descriptors"; import Physical from "../../DataTypes/Interfaces/Physical";
import GameNode from "../../Nodes/GameNode"; import GameNode from "../../Nodes/GameNode";
// @ignorePage // @ignorePage

View File

@ -1,5 +1,4 @@
import { Physical } from "../../DataTypes/Interfaces/Descriptors"; import Physical from "../../DataTypes/Interfaces/Physical";
import PhysicsUtils from "../../Utils/PhysicsUtils";
import SortingUtils from "../../Utils/SortingUtils"; import SortingUtils from "../../Utils/SortingUtils";
import BroadPhase from "./BroadPhase"; import BroadPhase from "./BroadPhase";

View File

@ -1,4 +1,4 @@
import { Physical } from "../DataTypes/Interfaces/Descriptors"; import Physical from "../DataTypes/Interfaces/Physical";
import Vec2 from "../DataTypes/Vec2"; import Vec2 from "../DataTypes/Vec2";
// @ignorePage // @ignorePage

View File

@ -1,6 +1,5 @@
import GameNode from "../Nodes/GameNode"; import GameNode from "../Nodes/GameNode";
import Vec2 from "../DataTypes/Vec2"; import Updateable from "../DataTypes/Interfaces/Updateable";
import { Updateable } from "../DataTypes/Interfaces/Descriptors";
import Tilemap from "../Nodes/Tilemap"; import Tilemap from "../Nodes/Tilemap";
import Receiver from "../Events/Receiver"; import Receiver from "../Events/Receiver";
import Emitter from "../Events/Emitter"; import Emitter from "../Events/Emitter";

View File

@ -1,5 +1,5 @@
import GameNode from "../Nodes/GameNode"; import GameNode from "../Nodes/GameNode";
import { Physical } from "../DataTypes/Interfaces/Descriptors"; import Physical from "../DataTypes/Interfaces/Physical";
import Tilemap from "../Nodes/Tilemap"; import Tilemap from "../Nodes/Tilemap";
import PhysicsManager from "./PhysicsManager"; import PhysicsManager from "./PhysicsManager";
import Vec2 from "../DataTypes/Vec2"; import Vec2 from "../DataTypes/Vec2";

View File

@ -12,7 +12,7 @@ import GameLoop from "../Loop/GameLoop";
import SceneManager from "./SceneManager"; import SceneManager from "./SceneManager";
import Receiver from "../Events/Receiver"; import Receiver from "../Events/Receiver";
import Emitter from "../Events/Emitter"; import Emitter from "../Events/Emitter";
import { Updateable } from "../DataTypes/Interfaces/Descriptors"; import Updateable from "../DataTypes/Interfaces/Updateable";
import NavigationManager from "../Pathfinding/NavigationManager"; import NavigationManager from "../Pathfinding/NavigationManager";
import AIManager from "../AI/AIManager"; import AIManager from "../AI/AIManager";
import Map from "../DataTypes/Map"; import Map from "../DataTypes/Map";