From cc5e1d57ff3c821aa5255132a63f9c4aaf955680 Mon Sep 17 00:00:00 2001 From: Fadi Shawki Date: Thu, 11 Jan 2024 15:36:54 +0100 Subject: [PATCH] 2024/01/11 - Debug playground setup --- .../explorer/OrbitMinesExplorer.tsx | 2 +- src/@orbitmines/explorer/Ray.ts | 41 ++++++++++++++++--- .../explorer/debug/DebugCanvas.tsx | 39 ++++++++---------- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/@orbitmines/explorer/OrbitMinesExplorer.tsx b/src/@orbitmines/explorer/OrbitMinesExplorer.tsx index 4b55748..2105fd5 100644 --- a/src/@orbitmines/explorer/OrbitMinesExplorer.tsx +++ b/src/@orbitmines/explorer/OrbitMinesExplorer.tsx @@ -100,7 +100,7 @@ export const Line = ({ start, mid, end, scale, color = line.color }: any) => lineWidth={line.width * scale} /> -const circle = { radius: 3, color: "orange", segments: 30, } +export const circle = { radius: 3, color: "orange", segments: 30, } export const Vertex = ({ position, color = circle.color }: any) => diff --git a/src/@orbitmines/explorer/Ray.ts b/src/@orbitmines/explorer/Ray.ts index 5c21fe5..a70e010 100644 --- a/src/@orbitmines/explorer/Ray.ts +++ b/src/@orbitmines/explorer/Ray.ts @@ -1,5 +1,6 @@ import _ from "lodash"; import {NotImplementedError, PreventsImplementationBug} from "./errors/errors"; +import {InterfaceOptions} from "./OrbitMinesExplorer"; // SHOULDNT CLASSIFY THESE? @@ -480,25 +481,55 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ?? //TODO USED FOR DEBUG NOW - move = (func: (self: Ray) => Ray, traversed: Ray[]): Ray => { + move = (func: (self: Ray) => Ray, memory: boolean, Interface: Ray): Ray => { const target_ray = func(this.self); const target = target_ray.as_reference().o({ ...this._dirty_store, position: target_ray.any.position ?? this.self.any.position - ?? [0, 0, 0] + ?? Ray.POSITION_OF_DOOM }); console.log('move', `${this.self.label.split(' ')[0]} -> ${target.self.label.split(' ')[0]}`); - if (!target_ray.any.traversed) { - traversed.push(target); - target_ray.any.traversed = true; + if (memory) { + if (!target_ray.any.traversed) { + Interface.any.rays.push(target); + target_ray.any.traversed = true; + } + } else { + Interface.any.rays = [target]; } return target; } + static POSITION_OF_DOOM = [0, 300, 0] + + // TODO: Abstract away as compilation + get render_options(): Required { + return ({ + position: + this.self.any.position + ?? (this.is_none() ? Ray.POSITION_OF_DOOM : [0, 0, 0]), + rotation: + this.self.any.rotation + ?? [0, 0, 0], + scale: + this.self.any.scale + ?? (this.is_none() ? 1.5 : 1.5), + color: + this.self.any.color + ?? (this.is_none() ? 'red' : { + [RayType.VERTEX]: 'orange', + [RayType.TERMINAL]: '#FF5555', + [RayType.INITIAL]: '#5555FF', + [RayType.REFERENCE]: '#555555', + }[this.type] + ) + }); + } + debug = (c: DebugResult): DebugRay => { if (c[this.label] !== undefined) return c[this.label]!; diff --git a/src/@orbitmines/explorer/debug/DebugCanvas.tsx b/src/@orbitmines/explorer/debug/DebugCanvas.tsx index aecd5be..18b2c9d 100644 --- a/src/@orbitmines/explorer/debug/DebugCanvas.tsx +++ b/src/@orbitmines/explorer/debug/DebugCanvas.tsx @@ -7,7 +7,7 @@ import { _Continuation, _Vertex, add, AutoRay, - AutoVertex, + AutoVertex, circle, InterfaceOptions, Line, SimpleRenderedRay, @@ -31,12 +31,14 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => { } = useThree(); const space_between = 20 * scale; + + const memory = true; const [Interface] = useState(Ray.vertex().o({ selection: Ray - .vertex().o({ position: [0, 0, 0], scale, color: 'orange' }) - .initial.o({ position: [-space_between, 0, 0] }).terminal - .terminal.o({ position: [space_between, 0, 0 ]}).initial + .vertex().o({ position: [0, 0, 0], scale, color: '#FF55FF' }) + .initial.o({ position: [-space_between, 0, 0], scale }).terminal + .terminal.o({ position: [space_between, 0, 0 ], scale }).initial .as_reference().o({ position: [0, 0, 0], scale, @@ -49,17 +51,17 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => { hotkeys: [ { combo: "a", global: true, label: "", onKeyDown: () => { - Interface.any.selection = Interface.any.selection.move((self: Ray) => self.initial, Interface.any.rays); + Interface.any.selection = Interface.any.selection.move((self: Ray) => self.initial, memory, Interface); } }, { combo: "d", global: true, label: "", onKeyDown: () => { - Interface.any.selection = Interface.any.selection.move((self: Ray) => self.terminal, Interface.any.rays); + Interface.any.selection = Interface.any.selection.move((self: Ray) => self.terminal, memory, Interface); } }, { combo: "w", global: true, label: "", onKeyDown: () => { - Interface.any.selection = Interface.any.selection.move((self: Ray) => self.self, Interface.any.rays); + Interface.any.selection = Interface.any.selection.move((self: Ray) => self.self, memory, Interface); } }, { @@ -83,32 +85,23 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => { hotkeyConfig.set(...hotkeys); - const render: { [TKey in keyof InterfaceOptions]: (ray: Ray) => InterfaceOptions[TKey] } = { - position: (ray: Ray) => ray.self.any.position ?? (ray.is_none() ? [0, 400, 0] : [0, 0, 0]), - rotation: (ray: Ray) => ray.self.any.rotation ?? [0, 0, 0], - scale: (ray: Ray): number => ray.self.any.scale ?? (ray.is_none() ? 1.5 : 1.5), - color: (ray: Ray): string => ray.self.any.color ?? (ray.is_none() ? 'red' : 'orange'), - } - - const options = (ray: Ray): Required => _.mapValues(render, (func: any) => func(ray)) as Required; - const Render = ({ ray }: { ray: Ray }) => { - const initial: Required = options(ray.self.initial.as_reference()); - const vertex: Required = options(ray); - const terminal: Required = options(ray.self.terminal.as_reference()); + const initial: Required = ray.self.initial.as_reference().render_options; + const vertex: Required = ray.render_options; + const terminal: Required = ray.self.terminal.as_reference().render_options; switch (ray.type) { case RayType.REFERENCE: - return + return case RayType.INITIAL: { return <> - + <_Continuation {...vertex} /> } case RayType.TERMINAL: { return <> - + <_Continuation {...vertex} /> } @@ -121,7 +114,7 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => { return <> {Interface.any.stats ? : <>} - + {/*{Interface.any.rays.map((ray: Ray) => )}*/} {Interface.any.rays.map((ray: Ray) => )}