From 106abd851ab452c54f7861af5d2cd90770fe4ccc Mon Sep 17 00:00:00 2001 From: orion Date: Mon, 11 May 2026 19:06:06 +0200 Subject: [PATCH] WIP: No idea what exactly i did over those past 2 days --- .../{shimeji => shimagic}/physics2d/physis.ts | 0 .../physics2d/primitives/aabb.ts | 2 +- .../physics2d/primitives/box2d.ts | 8 +- .../physics2d/primitives/circle.ts | 4 +- .../physics2d/primitives/collider2d.ts | 0 .../physics2d/primitives/ray2d.ts | 0 .../physics2d/primitives/raycast_result.ts | 0 .../rigidbody/intersection_detector2d.ts | 52 +++- .../physics2d/rigidbody/rigidbody2d.ts | 0 .../{shimeji => shimagic}/renderer/line2d.ts | 0 .../renderer/renderer.ts | 0 .../renderer/shaders/fragment_shader.frag | 0 .../renderer/shaders/vertex_shader.vert | 0 .../renderer/web_g_engine.ts | 0 src/lib/shimagic/shimagic.ts | 70 +++++ src/lib/stores/bash/commandRegistry.ts | 2 + src/lib/stores/bash/fs.ts | 73 +++-- src/lib/stores/shimeji.ts | 4 +- src/lib/stores/terminal/init.svelte.ts | 16 +- src/lib/stores/terminal/terminal.ts | 34 +-- src/lib/termos/filesystem/virtualfs.d.ts | 1 + src/lib/termos/shell/bash.d.ts | 7 + src/lib/termos/shell/command.d.ts | 27 ++ src/lib/termos/shell/process.d.ts | 63 ++++ src/lib/termos/termos.d.ts | 280 ++++++++++++++++++ src/lib/vector.ts | 5 + src/modules/Shimeji.svelte | 16 +- 27 files changed, 605 insertions(+), 59 deletions(-) rename src/lib/{shimeji => shimagic}/physics2d/physis.ts (100%) rename src/lib/{shimeji => shimagic}/physics2d/primitives/aabb.ts (91%) rename src/lib/{shimeji => shimagic}/physics2d/primitives/box2d.ts (86%) rename src/lib/{shimeji => shimagic}/physics2d/primitives/circle.ts (69%) rename src/lib/{shimeji => shimagic}/physics2d/primitives/collider2d.ts (100%) rename src/lib/{shimeji => shimagic}/physics2d/primitives/ray2d.ts (100%) rename src/lib/{shimeji => shimagic}/physics2d/primitives/raycast_result.ts (100%) rename src/lib/{shimeji => shimagic}/physics2d/rigidbody/intersection_detector2d.ts (77%) rename src/lib/{shimeji => shimagic}/physics2d/rigidbody/rigidbody2d.ts (100%) rename src/lib/{shimeji => shimagic}/renderer/line2d.ts (100%) rename src/lib/{shimeji => shimagic}/renderer/renderer.ts (100%) rename src/lib/{shimeji => shimagic}/renderer/shaders/fragment_shader.frag (100%) rename src/lib/{shimeji => shimagic}/renderer/shaders/vertex_shader.vert (100%) rename src/lib/{shimeji => shimagic}/renderer/web_g_engine.ts (100%) create mode 100644 src/lib/shimagic/shimagic.ts create mode 100644 src/lib/termos/filesystem/virtualfs.d.ts create mode 100644 src/lib/termos/shell/bash.d.ts create mode 100644 src/lib/termos/shell/command.d.ts create mode 100644 src/lib/termos/shell/process.d.ts create mode 100644 src/lib/termos/termos.d.ts diff --git a/src/lib/shimeji/physics2d/physis.ts b/src/lib/shimagic/physics2d/physis.ts similarity index 100% rename from src/lib/shimeji/physics2d/physis.ts rename to src/lib/shimagic/physics2d/physis.ts diff --git a/src/lib/shimeji/physics2d/primitives/aabb.ts b/src/lib/shimagic/physics2d/primitives/aabb.ts similarity index 91% rename from src/lib/shimeji/physics2d/primitives/aabb.ts rename to src/lib/shimagic/physics2d/primitives/aabb.ts index 2c66611..fc2ef25 100644 --- a/src/lib/shimeji/physics2d/primitives/aabb.ts +++ b/src/lib/shimagic/physics2d/primitives/aabb.ts @@ -4,7 +4,7 @@ import Rigidbody2D from '../rigidbody/rigidbody2d'; export class AABB { private size: Vector2 = new Vector2(); private halfSize: Vector2 = new Vector2(); - private rigidbody: Rigidbody2D | null = null; + private rigidbody: Rigidbody2D = new Rigidbody2D(); constructor(min?: Vector2, max?: Vector2) { if (min !== undefined && max !== undefined) this.size = new Vector2(max).sub(min); diff --git a/src/lib/shimeji/physics2d/primitives/box2d.ts b/src/lib/shimagic/physics2d/primitives/box2d.ts similarity index 86% rename from src/lib/shimeji/physics2d/primitives/box2d.ts rename to src/lib/shimagic/physics2d/primitives/box2d.ts index ae43088..ba45fdd 100644 --- a/src/lib/shimeji/physics2d/primitives/box2d.ts +++ b/src/lib/shimagic/physics2d/primitives/box2d.ts @@ -1,10 +1,10 @@ import Vector2 from '$lib/vector'; -import type Rigidbody2D from '../rigidbody/rigidbody2d'; +import Rigidbody2D from '../rigidbody/rigidbody2d'; export class Box2D { private size: Vector2 = new Vector2(); private halfSize: Vector2 = new Vector2(); - private rigidbody: Rigidbody2D | null = null; + private rigidbody: Rigidbody2D = new Rigidbody2D(); constructor(); constructor(min?: Vector2, max?: Vector2) { @@ -44,6 +44,10 @@ export class Box2D { public get getRigidbody(): Rigidbody2D { return this.rigidbody; } + + public get getHalfSize(): Vector2 { + return this.halfSize; + } } export default Box2D; diff --git a/src/lib/shimeji/physics2d/primitives/circle.ts b/src/lib/shimagic/physics2d/primitives/circle.ts similarity index 69% rename from src/lib/shimeji/physics2d/primitives/circle.ts rename to src/lib/shimagic/physics2d/primitives/circle.ts index 224a2d4..85bd585 100644 --- a/src/lib/shimeji/physics2d/primitives/circle.ts +++ b/src/lib/shimagic/physics2d/primitives/circle.ts @@ -1,9 +1,9 @@ import type Vector2 from '$lib/vector'; -import type Rigidbody2D from '../rigidbody/rigidbody2d'; +import Rigidbody2D from '../rigidbody/rigidbody2d'; class Circle { private radius: number = 1.0; - private rigidbody: Rigidbody2D; + private rigidbody: Rigidbody2D = new Rigidbody2D(); public get Radius(): number { return this.radius; diff --git a/src/lib/shimeji/physics2d/primitives/collider2d.ts b/src/lib/shimagic/physics2d/primitives/collider2d.ts similarity index 100% rename from src/lib/shimeji/physics2d/primitives/collider2d.ts rename to src/lib/shimagic/physics2d/primitives/collider2d.ts diff --git a/src/lib/shimeji/physics2d/primitives/ray2d.ts b/src/lib/shimagic/physics2d/primitives/ray2d.ts similarity index 100% rename from src/lib/shimeji/physics2d/primitives/ray2d.ts rename to src/lib/shimagic/physics2d/primitives/ray2d.ts diff --git a/src/lib/shimeji/physics2d/primitives/raycast_result.ts b/src/lib/shimagic/physics2d/primitives/raycast_result.ts similarity index 100% rename from src/lib/shimeji/physics2d/primitives/raycast_result.ts rename to src/lib/shimagic/physics2d/primitives/raycast_result.ts diff --git a/src/lib/shimeji/physics2d/rigidbody/intersection_detector2d.ts b/src/lib/shimagic/physics2d/rigidbody/intersection_detector2d.ts similarity index 77% rename from src/lib/shimeji/physics2d/rigidbody/intersection_detector2d.ts rename to src/lib/shimagic/physics2d/rigidbody/intersection_detector2d.ts index ccc7c52..0c781d3 100644 --- a/src/lib/shimeji/physics2d/rigidbody/intersection_detector2d.ts +++ b/src/lib/shimagic/physics2d/rigidbody/intersection_detector2d.ts @@ -1,4 +1,4 @@ -import Line2D from '$lib/shimeji/renderer/line2d'; +import Line2D from '$lib/shimagic/renderer/line2d'; import Vector2 from '$lib/vector'; import VMath from '$lib/vmath'; import AABB from '../primitives/aabb'; @@ -177,7 +177,57 @@ class IntersectionDetector2D { return true; } else { //TODO: Box2D implementation + + RaycastResult.reset(result); + + const halfSize: Vector2 = primitive.getHalfSize; + + const xAxis: Vector2 = new Vector2(1, 0); + const yAxis: Vector2 = new Vector2(0, 1); + VMath.rotate(xAxis, primitive.getRigidbody.Rotation, Vector2.zero); + VMath.rotate(yAxis, primitive.getRigidbody.Rotation, Vector2.zero); + + const p: Vector2 = new Vector2(primitive.getRigidbody.Position).sub(ray.Origin); + const f: Vector2 = new Vector2(xAxis.dot(ray.Direction), yAxis.dot(ray.Direction)); + const e: Vector2 = new Vector2(xAxis.dot(p), yAxis.dot(p)); + + const tArr: number[] = [0, 0, 0, 0]; + if (VMath.compare(f.x, 0)) { + if (-e.x - halfSize.x > 0 || -e.x + halfSize.x < 0) { + return false; + } + } + f.x = 0.00001; + tArr[0 * 2 + 0] = e.x + halfSize.x / f.x; + tArr[0 * 2 + 1] = e.x - halfSize.x / f.x; + + if (VMath.compare(f.y, 0)) { + if (-e.y - halfSize.y > 0 || -e.y + halfSize.y < 0) { + return false; + } + } + f.y = 0.00001; + tArr[1 * 2 + 0] = e.y + halfSize.y / f.y; + tArr[1 * 2 + 1] = e.x - halfSize.x / f.x; + + const tmin: number = Math.max(Math.min(tArr[0], tArr[1]), Math.min(tArr[2], tArr[3])); + const tmax: number = Math.min(Math.max(tArr[0], tArr[1]), Math.max(tArr[2], tArr[3])); + + const t = tmin < 0 ? tmax : tmin; + const hit: boolean = t > 0; //&& t * t < ray.Distance; + if (!hit) return false; + + if (result != null) { + const point: Vector2 = new Vector2(ray.Origin).add(new Vector2(ray.Direction).mul(t)); + const normal: Vector2 = new Vector2(ray.Origin).sub(point); + normal.normalize(); + + result.init(point, normal, t, true); + } + return true; } + + public static circleAndLine() } } diff --git a/src/lib/shimeji/physics2d/rigidbody/rigidbody2d.ts b/src/lib/shimagic/physics2d/rigidbody/rigidbody2d.ts similarity index 100% rename from src/lib/shimeji/physics2d/rigidbody/rigidbody2d.ts rename to src/lib/shimagic/physics2d/rigidbody/rigidbody2d.ts diff --git a/src/lib/shimeji/renderer/line2d.ts b/src/lib/shimagic/renderer/line2d.ts similarity index 100% rename from src/lib/shimeji/renderer/line2d.ts rename to src/lib/shimagic/renderer/line2d.ts diff --git a/src/lib/shimeji/renderer/renderer.ts b/src/lib/shimagic/renderer/renderer.ts similarity index 100% rename from src/lib/shimeji/renderer/renderer.ts rename to src/lib/shimagic/renderer/renderer.ts diff --git a/src/lib/shimeji/renderer/shaders/fragment_shader.frag b/src/lib/shimagic/renderer/shaders/fragment_shader.frag similarity index 100% rename from src/lib/shimeji/renderer/shaders/fragment_shader.frag rename to src/lib/shimagic/renderer/shaders/fragment_shader.frag diff --git a/src/lib/shimeji/renderer/shaders/vertex_shader.vert b/src/lib/shimagic/renderer/shaders/vertex_shader.vert similarity index 100% rename from src/lib/shimeji/renderer/shaders/vertex_shader.vert rename to src/lib/shimagic/renderer/shaders/vertex_shader.vert diff --git a/src/lib/shimeji/renderer/web_g_engine.ts b/src/lib/shimagic/renderer/web_g_engine.ts similarity index 100% rename from src/lib/shimeji/renderer/web_g_engine.ts rename to src/lib/shimagic/renderer/web_g_engine.ts diff --git a/src/lib/shimagic/shimagic.ts b/src/lib/shimagic/shimagic.ts new file mode 100644 index 0000000..c2cc07f --- /dev/null +++ b/src/lib/shimagic/shimagic.ts @@ -0,0 +1,70 @@ +import { WebG } from './renderer/web_g_engine'; + +export namespace Shimagic { + export class Shimeji { + private WebGEngine: WebG.Engine; + //private PhysisEngine: Physis.Engine; + private size!: number; + + private AnimID: number | null = null; + private pDeltaT: number = 0; + + constructor(webgengine: WebG.Engine /* physis: Physis.Engine */) { + this.WebGEngine = webgengine; + } + + /** + * Factory method: Initializes all sub-systems like WebG & Physis aswell as initializes the Shimeji and starts its animation + * @async + * @public + * @param {ShimejiConfig} config - Shimeji configuration + * @returns {Promise} that resolves when the Shimeji is done initializing + */ + public static async Initialize(config: ShimejiConfig): Promise { + const webg = await WebG.Engine.Initialize(config.webG); + //const physis = await Physis.Engine.Initialize(config.physis); + + const shimeji = new Shimeji(webg); + shimeji.size = config.size; + + const AFrame = (delta: number) => { + shimeji.pDeltaT = delta; + shimeji.AnimID = requestAnimationFrame(shimeji._anim); + }; + + shimeji.AnimID = requestAnimationFrame(AFrame); + + return shimeji; + } + + private _anim(delta: number) { + let dt = (delta - this.pDeltaT) / 1000; + dt = Math.min(dt, 0.05 /* * this.Physis.TIMESCALE */); + this.pDeltaT = delta; + + this.UpdatePhysics(dt); + this.UpdateFrame(dt); + + this.AnimID = requestAnimationFrame(this._anim); + } + + /** + * A function called automatically every "frame" where the code for calculating the next physics frame of the Shimeji is placed + * @param delta - Automatically passed in deltaT value; + */ + private UpdatePhysics(delta: number): void {} + + /** + * A function called automatically every "frame" where the code for drawing the next frame of the Shimeji is placed + * @param delta - Automatically passed in deltaT value; + */ + private UpdateFrame(delta: number): void {} + } + + interface ShimejiConfig { + sprite: string; //temp soultion to + size: number; + webG: WebG.EngineConfig; + //physis: Physis.EngineConfig; + } +} diff --git a/src/lib/stores/bash/commandRegistry.ts b/src/lib/stores/bash/commandRegistry.ts index 87dc8f8..5970155 100644 --- a/src/lib/stores/bash/commandRegistry.ts +++ b/src/lib/stores/bash/commandRegistry.ts @@ -25,6 +25,8 @@ export type CommandResultData = { args?: CommandArgs; }; +TermOS.Shell.Command. + export const COMMANDS = { cd, ls, diff --git a/src/lib/stores/bash/fs.ts b/src/lib/stores/bash/fs.ts index ed45c57..4b227f1 100755 --- a/src/lib/stores/bash/fs.ts +++ b/src/lib/stores/bash/fs.ts @@ -1,6 +1,5 @@ -import type { Bash } from "./bash"; -import type { User } from "./etc/userData"; -import type { Permission, TimeStamps } from "./metadata"; +import type { User } from './etc/userData'; +import type { Permission, TimeStamps } from './metadata'; export enum Type { Directory = 16384, @@ -8,7 +7,7 @@ export enum Type { SymbolicLink = 40960 } -export type NodePerms = { +export type NodePermission = { user: Permission; group: Permission; other: Permission; @@ -65,8 +64,7 @@ export class VirtualFS { if (!currentNode) throw new Error('could not find the node in the fs table - inodetopathstring'); - if (!currentNode.parent || - currentNode.inode === this.rootINode) { + if (!currentNode.parent || currentNode.inode === this.rootINode) { return '/'; } @@ -157,26 +155,63 @@ export class VirtualFS { return node; } - public recursiveTraversalPre(node: TreeNode, callback: (param: TreeNode) => void, childIndex?: number[], depthIndex?: number): void { - if(!depthIndex) depthIndex = 0; - if(!childIndex) childIndex = [0]; + public recursiveTraversalPre( + node: TreeNode, + callback: (param: TreeNode) => void, + childIndex?: number[], + depthIndex?: number + ): void { + if (!depthIndex) depthIndex = 0; + if (!childIndex) childIndex = [0]; - if(node.type != Type.File && node.children[childIndex[depthIndex]]) { + if (node.type != Type.File && node.children[childIndex[depthIndex]]) { node = this.getNodeByINode(node.children[childIndex[depthIndex]]); - depthIndex++; - if(!childIndex[depthIndex]) childIndex[depthIndex] = 0; - + depthIndex++; + if (!childIndex[depthIndex]) childIndex[depthIndex] = 0; + callback(node); - } - else { + } else { node = this.getNodeByINode(node.parent); - childIndex[depthIndex] = 0; - depthIndex--; - childIndex[depthIndex]++; + childIndex[depthIndex] = 0; + depthIndex--; + childIndex[depthIndex]++; } - if(depthIndex < 0) return; + if (depthIndex < 0) return; this.recursiveTraversalPre(node, callback, childIndex, depthIndex); } + + private _createNode(name: string, type: Type, path: number, user: number): void { + let children: null | number[]; + + const node: TreeNode = { + inode: this.FsTable.size + 1, + name: name, + type: type, + size: 4096, //TODO: Calculate the size from the content + children: [], + content: '', + link: -1, + permission: { + user: { + r: true, + w: true, + x: false + }, + group: { + r: true, + w: false, + x: false + }, + other: { + r: true, + w: false, + x: false + } + }, + owner: user, + group: + } + } } diff --git a/src/lib/stores/shimeji.ts b/src/lib/stores/shimeji.ts index 3cbbac6..d4e26eb 100644 --- a/src/lib/stores/shimeji.ts +++ b/src/lib/stores/shimeji.ts @@ -1,5 +1,5 @@ //import Renderer from '$lib/shimeji/renderer/renderer'; -import { WebG } from '$lib/shimeji/renderer/web_g_engine'; +import { WebG } from '$lib/shimagic/renderer/web_g_engine'; import Vector2 from '../vector'; export class Shimejii { @@ -211,7 +211,7 @@ export class Shimejii { moveTo(pos: number) {} } -namespace Shimagic { +export namespace Shimagic { export class Shimeji { private WebGEngine: WebG.Engine; //private PhysisEngine: Physis.Engine; diff --git a/src/lib/stores/terminal/init.svelte.ts b/src/lib/stores/terminal/init.svelte.ts index cfb4437..444bbdf 100755 --- a/src/lib/stores/terminal/init.svelte.ts +++ b/src/lib/stores/terminal/init.svelte.ts @@ -1,4 +1,4 @@ -import type { User } from '../bash/etc/userData'; +import { TermOS } from '$lib/termos/termos'; import type { TreeNode } from '../bash/fs'; //import { type ILocale } from './localeRegistry'; import { Terminal, type PageCallbacks, type TermInitArgs } from './terminal'; @@ -102,17 +102,19 @@ async function fetchFileSystem(path: string): Promise { async function fetchLocale(id: string): Promise { const response = await fetch(`/src/lib/assets/locales/terminal/${id}.json`); - if(!response.ok) throw new Error('Failed to fetch the chosen locale'); + if (!response.ok) throw new Error('Failed to fetch the chosen locale'); const data = await response.json(); return data; } +TermOS.Shell.Bash; + export async function initTerminal( - user: {username: string, password: string}, - callbackInit: PageCallbacks, - localeId: string - ): Promise { + user: { username: string; password: string }, + callbackInit: PageCallbacks, + localeId: string +): Promise { try { const sig = await fetchFsSignature('/src/lib/assets/fs/signature'); const fsJson = await fetchFsJson(sig); @@ -123,7 +125,7 @@ export async function initTerminal( }; */ const args: TermInitArgs = { - //locale, + //locale, bash: { fs, user diff --git a/src/lib/stores/terminal/terminal.ts b/src/lib/stores/terminal/terminal.ts index c966b90..286e4be 100755 --- a/src/lib/stores/terminal/terminal.ts +++ b/src/lib/stores/terminal/terminal.ts @@ -1,8 +1,7 @@ -import type { BooleanLiteral } from 'typescript'; -import { Bash, Signal, type BashInitArgs, type Result } from '../bash/bash'; +import { Bash, type BashInitArgs, type Result } from '../bash/bash'; import type { CommandArgs } from '../bash/commandRegistry'; import type { User } from '../bash/etc/userData'; -import { VirtualFS, type TreeNode } from '../bash/fs'; +import { VirtualFS } from '../bash/fs'; import { KeybindInhibitor } from '../bash/keybindInhibitor'; import { ExitCode } from '../bash/metadata'; import type { Process } from '../bash/process'; @@ -47,22 +46,21 @@ export class Terminal { this._bash = new Bash(args.bash); const keybinds: Map any> = new Map([ - [TERMINAL_KEYBINDS.sigint,this._processKill] + [TERMINAL_KEYBINDS.sigint, this._processKill] ]); this._keybindInhibitor = new KeybindInhibitor(keybinds); - - //this.locale = args.locale; + //this.locale = args.locale; } private _processKill(): ExitCode { const get: Process | ExitCode = this._bash.getProcess(); - if(get == ExitCode.ERROR) return ExitCode.ERROR; + if (get == ExitCode.ERROR) return ExitCode.ERROR; const process: Process = get; const result = process.sigKill(() => { - console.log("process kill successful"); + console.log('process kill successful'); }); //this.isProcessActive = false; @@ -131,7 +129,7 @@ export class Terminal { this._bash.updateHistory(input); const parsed: ParsedInput = this._parseInput(input); //console.log(parsed, 'executeCommand output'); - + return this._bash.executeCommand(parsed.command, parsed.args); } @@ -144,19 +142,17 @@ export class Terminal { } getPrimaryKeybindInhibitor(): KeybindInhibitor { - const processKeybinds: KeybindInhibitor | null = - this._bash.getProcessKeybindInhibitor(); - if(processKeybinds) { + const processKeybinds: KeybindInhibitor | null = this._bash.getProcessKeybindInhibitor(); + if (processKeybinds) { return processKeybinds; - } - else { + } else { return this._keybindInhibitor; } } getProcessKeyInhibitor(): KeybindInhibitor | ExitCode.ERROR { const out = this._bash.getProcessKeybindInhibitor(); - if(out) return out; + if (out) return out; else return ExitCode.ERROR; } @@ -170,14 +166,18 @@ export class Terminal { getTerminalWidth(): number { const width = this._callbacks.getWidth?.(); - if(!width) { throw new Error('somehow width is undefined still after all the checks'); } + if (!width) { + throw new Error('somehow width is undefined still after all the checks'); + } return width; } getFontSize(): number { const size = this._callbacks.getFontSize?.(); - if(!size) { throw new Error('somehow font size is undefined still after all the checks'); } + if (!size) { + throw new Error('somehow font size is undefined still after all the checks'); + } return size; } diff --git a/src/lib/termos/filesystem/virtualfs.d.ts b/src/lib/termos/filesystem/virtualfs.d.ts new file mode 100644 index 0000000..9b2afc7 --- /dev/null +++ b/src/lib/termos/filesystem/virtualfs.d.ts @@ -0,0 +1 @@ +declare namespace FileSystem {} diff --git a/src/lib/termos/shell/bash.d.ts b/src/lib/termos/shell/bash.d.ts new file mode 100644 index 0000000..45d9763 --- /dev/null +++ b/src/lib/termos/shell/bash.d.ts @@ -0,0 +1,7 @@ +namespace TermOS { + export namespace Shell { + export class Bash { + private readonly _fs: TermOS. + } + } +} diff --git a/src/lib/termos/shell/command.d.ts b/src/lib/termos/shell/command.d.ts new file mode 100644 index 0000000..42cdae2 --- /dev/null +++ b/src/lib/termos/shell/command.d.ts @@ -0,0 +1,27 @@ +namespace TermOS { + export namespace Shell { + export abstract class Command { + public abstract readonly _flags: CommandFlag[]; + public abstract readonly _root: boolean; + public abstract readonly _keybinds?: Map any>; + public abstract readonly _help: string; //TODO: Dont know where to pull the help text from yet + public abstract result: CommandResult = { bin: this.constructor.name }; + + public abstract Main(this: Bash, flags: CommandFlag[], args: string[]) {} + } + + export type CommandFlag = { + flag: string; + values?: string[]; + }; + + export type CommandResult = { + bin: string; + flags?: CommandFlag[]; + args?: string[]; + path: number; + exitcode: ExitCode; + data?: any; + }; + } +} diff --git a/src/lib/termos/shell/process.d.ts b/src/lib/termos/shell/process.d.ts new file mode 100644 index 0000000..35565f5 --- /dev/null +++ b/src/lib/termos/shell/process.d.ts @@ -0,0 +1,63 @@ +import type { CommandArgs } from "$lib/stores/bash/commandRegistry"; +import type { KeybindInhibitor } from "$lib/stores/bash/keybindInhibitor"; +import type { ExitCode } from "$lib/stores/bash/metadata"; + +namespace TermOS { + export namespace Shell { + export class Process { + private _bash: Bash; + private _uid: number; + private _name: string; + private _timestamp: Date; + private _keybindInhibitor?: KeybindInhibitor; + private _abortController: AbortController; + + constructor( + bash: Bash, + uid: number, + name: string, + command: Command, + args: CommandArgs + ) { + this._bash = bash; + this._uid = uid; + this._name = name; + this._timestamp = new Date(); + this._abortController = new AbortController(); + + if(command._keybinds) { + this._keybindInhibitor = new KeybindInhibitor(command.keybinds) + } + + this._Exec(command, bash, args); + } + + public getKeybindInhibitor(): KeybindInhibitor | null { + if(this._keybindInhibitor) return this._keybindInhibitor; + + return null; + } + + public sigKill(callback: () => void): ExitCode { + this._abortController.abort(); + callback(); + + return ExitCode.INT; + } + + public get Uid(): number { + + } + + public get Timestamp(): Date { + return this._timestamp; + } + + public get Name(): string { + return this._name + } + + public async get Result(): Promise + } + } +} diff --git a/src/lib/termos/termos.d.ts b/src/lib/termos/termos.d.ts new file mode 100644 index 0000000..9f9a277 --- /dev/null +++ b/src/lib/termos/termos.d.ts @@ -0,0 +1,280 @@ +declare namespace TermOS { + export async function Initialize() {} + + export declare namespace Shell { + async function _init() {} + + export type User = { + username: string; + password: string; + readonly uid: number; + readonly gid: number; + home: string; + accessible: boolean; + history: string; + cwd?: number; + pwd?: number; + }; + + export type Group = { + groupname: string; + gid: number; + members: number[]; + }; + + export enum ExitCode { + OK = 0, + ERR = 1, + INT = 2 + } + } + + export declare namespace Terminal { + async function _init() {} + + export class KeybindInhibitor { + private readonly _keybinds: Map any>; + + constructor(keybinds: Map any>) { + this._keybinds = keybinds; + } + + private parseModifierStates(event: KeyboardEvent): Modifier[] | undefined { + const mods: Modifier[] = []; + + if (event.altKey) mods.push('Alt'); + if (event.ctrlKey) mods.push('Ctrl'); + if (event.shiftKey) mods.push('Ctrl'); + + if (mods.length == 0) return undefined; + + return mods; + } + + processKeystroke(event: KeyboardEvent) { + const keybind: KeyBind = [ + { + key: event.key, + mods: this.parseModifierStates(event) + } + ]; + + const out = this._keybinds.get(keybind); + if (out) out(); + } + } + + type Modifier = 'Ctrl' | 'Alt' | 'Shift'; + + type KeyStroke = { + key: string; + mods?: Modifier[]; + }; + + export type KeyBind = [KeyStroke] | [KeyStroke, KeyStroke]; + } + + export declare namespace FileSystem {} +} + +/* +namespace TermOS { + export async function Initialize() {} + + + export namespace Shell { + export class Bash { + private readonly _fs: FileSystem; + private _passwd: + } + + abstract class Command { + public abstract readonly FLAGS: CommandFlag[]; + public abstract readonly ROOT: boolean; + public abstract readonly KEYBINDS: KeybindIn + + public abstract async Main(this: Bash): Promise + } + + export class Process { + + private _bash: Bash; + private _result: Result; + private _uid: number; + private _name: string; + private _initTimestamp: Date; + private _keybindInhibitor?: KeybindInhibitor; + private _abortController: AbortController; + + constructor( + _bashInstance: Bash, + uid: number, + name: string, + command: Command, + args: CommandArgs + ) { + this._bash = _bashInstance; + this._result = { exitCode: ExitCode.ERROR, path: this._bash.getCwd() } + this._uid = uid; + this._name = name; + this._initTimestamp = new Date(); + this._abortController = new AbortController(); + + if(command.keybinds) { + this._keybindInhibitor = new KeybindInhibitor(command.keybinds); + } + + this._Run(command, _bashInstance, args); + } + + public getKeybindInhibitor(): KeybindInhibitor | null { + if(this._keybindInhibitor) { + return this._keybindInhibitor; + } + else { + return null; + } + } + + public sigKill(callback: () => void): ExitCode { + this._abortController.abort(); + callback(); + + return ExitCode.SUCCESS //Only temp, need to add ExitCode.INT + } + + public getUid(): number { + return this._uid; + } + + public getInitTime(): Date { + return this._initTimestamp; + } + + public getName(): string { + return this._name; + } + + public async getResult(): Promise { + return this._result; + } + + private async _Run(command: ICommand, bashInstance: Bash, args: CommandArgs) { + this._result = command.method.call( + bashInstance, args); + } + + } + + type CommandFlag = { + flag: string; + values?: string[]; + } + + enum ExitCode { + SUCCESS = 0, + ERROR = 1 + } + + type CommandResult = { + exit_code: ExitCode; + path: number; + data?: any; + } + + type User = { + username: string; + password: string; + readonly uid: number; + readonly gid: number; + home: string; + accessible: boolean; + bash_history: string[]; + cwd?: number; + pwd?: number; + } + + const COMMANDS + const PASSWD + const GROUP + } + class She { + private readonly _fs: FileSystem = new FileSystem(); + + constructor() {} + + private static async _init() {} + } + + export namespace Terminal { + export class KeybindInhibitor { + private readonly _KEYBINDS: + } + } + + class Terminal { + constructor() {} + + private static async _init() {} + } + + class FileSystem { + private _table: Map; + + constructor(fs: Map, user: User) {} + + private static async _init() {} + + public type TreeNod { + inode: number; + } + } + + type TreeNode = { + inode: number; + parent: number; + name: string; + type: Type; + size: number; //Size in Bytes + children: number[]; + content: string; // GUID of the cache file that contains the file contents. + link: number; // Links + permission: NodePermission; + owner: number; + group: number; + timestamps: TimeStamps; + interactible: boolean; + func: any; + } + + enum Type { + Directory = 16384, + File = 32768, + + } + + type NodePermission = { + user: Permission; + group: Permission; + other: Permission; + } + + type TimeStamps = { + modified: Date; + changed: Date; + accessed: Date; + } + + // TODO: Finish this + enum ExitCode { + SUCCESS = 0, + ERROR = 1 + } + + type Permission = { + r: boolean; + w: boolean; + x: boolean; + } +} +*/ diff --git a/src/lib/vector.ts b/src/lib/vector.ts index 391d372..89e666d 100644 --- a/src/lib/vector.ts +++ b/src/lib/vector.ts @@ -2,6 +2,11 @@ class Vector2 { public x: number; public y: number; + /** + * + * @param x + * @param y + */ constructor(x?: number, y?: number); constructor(v?: Vector2); constructor(x: Vector2 | number = 0, y: number = 0) { diff --git a/src/modules/Shimeji.svelte b/src/modules/Shimeji.svelte index 4992ae2..1ec5cb7 100644 --- a/src/modules/Shimeji.svelte +++ b/src/modules/Shimeji.svelte @@ -1,14 +1,14 @@