* docs: add editor-app README with setup instructions * docs: add separate EN/CN editor setup guides * fix(editor): fix build errors and refactor behavior-tree architecture - Fix fairygui-editor tsconfig extends path and add missing tsconfig.build.json - Refactor behavior-tree-editor to not depend on asset-system in runtime - Create local BehaviorTreeRuntimeModule for pure runtime logic - Move asset loader registration to editor module install() - Add BehaviorTreeLoader for asset system integration - Fix rapier2d WASM loader to not pass arguments to init() - Add WASM base64 loader config to rapier2d tsup.config - Update README documentation and simplify setup steps
73 lines
1.3 KiB
TypeScript
73 lines
1.3 KiB
TypeScript
import {RawVector, RawRotation} from "./raw";
|
|
|
|
export interface Vector {
|
|
x: number;
|
|
y: number;
|
|
}
|
|
|
|
/**
|
|
* A 2D vector.
|
|
*/
|
|
export class Vector2 implements Vector {
|
|
x: number;
|
|
y: number;
|
|
|
|
constructor(x: number, y: number) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
}
|
|
|
|
export class VectorOps {
|
|
public static new(x: number, y: number): Vector {
|
|
return new Vector2(x, y);
|
|
}
|
|
|
|
public static zeros(): Vector {
|
|
return VectorOps.new(0.0, 0.0);
|
|
}
|
|
|
|
// FIXME: type ram: RawVector?
|
|
public static fromRaw(raw: RawVector): Vector {
|
|
if (!raw) return null;
|
|
|
|
let res = VectorOps.new(raw.x, raw.y);
|
|
raw.free();
|
|
return res;
|
|
}
|
|
|
|
public static intoRaw(v: Vector): RawVector {
|
|
return new RawVector(v.x, v.y);
|
|
}
|
|
|
|
public static copy(out: Vector, input: Vector) {
|
|
out.x = input.x;
|
|
out.y = input.y;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* A rotation angle in radians.
|
|
*/
|
|
export type Rotation = number;
|
|
|
|
export class RotationOps {
|
|
public static identity(): number {
|
|
return 0.0;
|
|
}
|
|
|
|
public static fromRaw(raw: RawRotation): Rotation {
|
|
if (!raw) return null;
|
|
|
|
let res = raw.angle;
|
|
raw.free();
|
|
return res;
|
|
}
|
|
|
|
public static intoRaw(angle: Rotation): RawRotation {
|
|
return RawRotation.fromAngle(angle);
|
|
}
|
|
}
|
|
|
|
|