WIP: No idea what exactly i did over those past 2 days
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ import Rigidbody2D from '../rigidbody/rigidbody2d';
|
|||||||
export class AABB {
|
export class AABB {
|
||||||
private size: Vector2 = new Vector2();
|
private size: Vector2 = new Vector2();
|
||||||
private halfSize: Vector2 = new Vector2();
|
private halfSize: Vector2 = new Vector2();
|
||||||
private rigidbody: Rigidbody2D | null = null;
|
private rigidbody: Rigidbody2D = new Rigidbody2D();
|
||||||
|
|
||||||
constructor(min?: Vector2, max?: Vector2) {
|
constructor(min?: Vector2, max?: Vector2) {
|
||||||
if (min !== undefined && max !== undefined) this.size = new Vector2(max).sub(min);
|
if (min !== undefined && max !== undefined) this.size = new Vector2(max).sub(min);
|
||||||
+6
-2
@@ -1,10 +1,10 @@
|
|||||||
import Vector2 from '$lib/vector';
|
import Vector2 from '$lib/vector';
|
||||||
import type Rigidbody2D from '../rigidbody/rigidbody2d';
|
import Rigidbody2D from '../rigidbody/rigidbody2d';
|
||||||
|
|
||||||
export class Box2D {
|
export class Box2D {
|
||||||
private size: Vector2 = new Vector2();
|
private size: Vector2 = new Vector2();
|
||||||
private halfSize: Vector2 = new Vector2();
|
private halfSize: Vector2 = new Vector2();
|
||||||
private rigidbody: Rigidbody2D | null = null;
|
private rigidbody: Rigidbody2D = new Rigidbody2D();
|
||||||
|
|
||||||
constructor();
|
constructor();
|
||||||
constructor(min?: Vector2, max?: Vector2) {
|
constructor(min?: Vector2, max?: Vector2) {
|
||||||
@@ -44,6 +44,10 @@ export class Box2D {
|
|||||||
public get getRigidbody(): Rigidbody2D {
|
public get getRigidbody(): Rigidbody2D {
|
||||||
return this.rigidbody;
|
return this.rigidbody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get getHalfSize(): Vector2 {
|
||||||
|
return this.halfSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Box2D;
|
export default Box2D;
|
||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
import type Vector2 from '$lib/vector';
|
import type Vector2 from '$lib/vector';
|
||||||
import type Rigidbody2D from '../rigidbody/rigidbody2d';
|
import Rigidbody2D from '../rigidbody/rigidbody2d';
|
||||||
|
|
||||||
class Circle {
|
class Circle {
|
||||||
private radius: number = 1.0;
|
private radius: number = 1.0;
|
||||||
private rigidbody: Rigidbody2D;
|
private rigidbody: Rigidbody2D = new Rigidbody2D();
|
||||||
|
|
||||||
public get Radius(): number {
|
public get Radius(): number {
|
||||||
return this.radius;
|
return this.radius;
|
||||||
+51
-1
@@ -1,4 +1,4 @@
|
|||||||
import Line2D from '$lib/shimeji/renderer/line2d';
|
import Line2D from '$lib/shimagic/renderer/line2d';
|
||||||
import Vector2 from '$lib/vector';
|
import Vector2 from '$lib/vector';
|
||||||
import VMath from '$lib/vmath';
|
import VMath from '$lib/vmath';
|
||||||
import AABB from '../primitives/aabb';
|
import AABB from '../primitives/aabb';
|
||||||
@@ -177,7 +177,57 @@ class IntersectionDetector2D {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
//TODO: Box2D implementation
|
//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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static circleAndLine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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<Shimeji>} that resolves when the Shimeji is done initializing
|
||||||
|
*/
|
||||||
|
public static async Initialize(config: ShimejiConfig): Promise<Shimeji> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,8 @@ export type CommandResultData = {
|
|||||||
args?: CommandArgs;
|
args?: CommandArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TermOS.Shell.Command.
|
||||||
|
|
||||||
export const COMMANDS = {
|
export const COMMANDS = {
|
||||||
cd,
|
cd,
|
||||||
ls,
|
ls,
|
||||||
|
|||||||
+49
-14
@@ -1,6 +1,5 @@
|
|||||||
import type { Bash } from "./bash";
|
import type { User } from './etc/userData';
|
||||||
import type { User } from "./etc/userData";
|
import type { Permission, TimeStamps } from './metadata';
|
||||||
import type { Permission, TimeStamps } from "./metadata";
|
|
||||||
|
|
||||||
export enum Type {
|
export enum Type {
|
||||||
Directory = 16384,
|
Directory = 16384,
|
||||||
@@ -8,7 +7,7 @@ export enum Type {
|
|||||||
SymbolicLink = 40960
|
SymbolicLink = 40960
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NodePerms = {
|
export type NodePermission = {
|
||||||
user: Permission;
|
user: Permission;
|
||||||
group: Permission;
|
group: Permission;
|
||||||
other: Permission;
|
other: Permission;
|
||||||
@@ -65,8 +64,7 @@ export class VirtualFS {
|
|||||||
if (!currentNode)
|
if (!currentNode)
|
||||||
throw new Error('could not find the node in the fs table - inodetopathstring');
|
throw new Error('could not find the node in the fs table - inodetopathstring');
|
||||||
|
|
||||||
if (!currentNode.parent ||
|
if (!currentNode.parent || currentNode.inode === this.rootINode) {
|
||||||
currentNode.inode === this.rootINode) {
|
|
||||||
return '/';
|
return '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,26 +155,63 @@ export class VirtualFS {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public recursiveTraversalPre(node: TreeNode, callback: (param: TreeNode) => void, childIndex?: number[], depthIndex?: number): void {
|
public recursiveTraversalPre(
|
||||||
if(!depthIndex) depthIndex = 0;
|
node: TreeNode,
|
||||||
if(!childIndex) childIndex = [0];
|
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]]);
|
node = this.getNodeByINode(node.children[childIndex[depthIndex]]);
|
||||||
depthIndex++;
|
depthIndex++;
|
||||||
if(!childIndex[depthIndex]) childIndex[depthIndex] = 0;
|
if (!childIndex[depthIndex]) childIndex[depthIndex] = 0;
|
||||||
|
|
||||||
callback(node);
|
callback(node);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
node = this.getNodeByINode(node.parent);
|
node = this.getNodeByINode(node.parent);
|
||||||
childIndex[depthIndex] = 0;
|
childIndex[depthIndex] = 0;
|
||||||
depthIndex--;
|
depthIndex--;
|
||||||
childIndex[depthIndex]++;
|
childIndex[depthIndex]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(depthIndex < 0) return;
|
if (depthIndex < 0) return;
|
||||||
|
|
||||||
this.recursiveTraversalPre(node, callback, childIndex, depthIndex);
|
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:
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//import Renderer from '$lib/shimeji/renderer/renderer';
|
//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';
|
import Vector2 from '../vector';
|
||||||
|
|
||||||
export class Shimejii {
|
export class Shimejii {
|
||||||
@@ -211,7 +211,7 @@ export class Shimejii {
|
|||||||
moveTo(pos: number) {}
|
moveTo(pos: number) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Shimagic {
|
export namespace Shimagic {
|
||||||
export class Shimeji {
|
export class Shimeji {
|
||||||
private WebGEngine: WebG.Engine;
|
private WebGEngine: WebG.Engine;
|
||||||
//private PhysisEngine: Physis.Engine;
|
//private PhysisEngine: Physis.Engine;
|
||||||
|
|||||||
@@ -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 { TreeNode } from '../bash/fs';
|
||||||
//import { type ILocale } from './localeRegistry';
|
//import { type ILocale } from './localeRegistry';
|
||||||
import { Terminal, type PageCallbacks, type TermInitArgs } from './terminal';
|
import { Terminal, type PageCallbacks, type TermInitArgs } from './terminal';
|
||||||
@@ -102,17 +102,19 @@ async function fetchFileSystem(path: string): Promise<any> {
|
|||||||
|
|
||||||
async function fetchLocale(id: string): Promise<any> {
|
async function fetchLocale(id: string): Promise<any> {
|
||||||
const response = await fetch(`/src/lib/assets/locales/terminal/${id}.json`);
|
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();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TermOS.Shell.Bash;
|
||||||
|
|
||||||
export async function initTerminal(
|
export async function initTerminal(
|
||||||
user: {username: string, password: string},
|
user: { username: string; password: string },
|
||||||
callbackInit: PageCallbacks,
|
callbackInit: PageCallbacks,
|
||||||
localeId: string
|
localeId: string
|
||||||
): Promise<Terminal> {
|
): Promise<Terminal> {
|
||||||
try {
|
try {
|
||||||
const sig = await fetchFsSignature('/src/lib/assets/fs/signature');
|
const sig = await fetchFsSignature('/src/lib/assets/fs/signature');
|
||||||
const fsJson = await fetchFsJson(sig);
|
const fsJson = await fetchFsJson(sig);
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import type { BooleanLiteral } from 'typescript';
|
import { Bash, type BashInitArgs, type Result } from '../bash/bash';
|
||||||
import { Bash, Signal, type BashInitArgs, type Result } from '../bash/bash';
|
|
||||||
import type { CommandArgs } from '../bash/commandRegistry';
|
import type { CommandArgs } from '../bash/commandRegistry';
|
||||||
import type { User } from '../bash/etc/userData';
|
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 { KeybindInhibitor } from '../bash/keybindInhibitor';
|
||||||
import { ExitCode } from '../bash/metadata';
|
import { ExitCode } from '../bash/metadata';
|
||||||
import type { Process } from '../bash/process';
|
import type { Process } from '../bash/process';
|
||||||
@@ -47,22 +46,21 @@ export class Terminal {
|
|||||||
this._bash = new Bash(args.bash);
|
this._bash = new Bash(args.bash);
|
||||||
|
|
||||||
const keybinds: Map<KeyBind, () => any> = new Map([
|
const keybinds: Map<KeyBind, () => any> = new Map([
|
||||||
[TERMINAL_KEYBINDS.sigint,this._processKill]
|
[TERMINAL_KEYBINDS.sigint, this._processKill]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this._keybindInhibitor = new KeybindInhibitor(keybinds);
|
this._keybindInhibitor = new KeybindInhibitor(keybinds);
|
||||||
|
|
||||||
//this.locale = args.locale;
|
//this.locale = args.locale;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _processKill(): ExitCode {
|
private _processKill(): ExitCode {
|
||||||
const get: Process | ExitCode = this._bash.getProcess();
|
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 process: Process = get;
|
||||||
const result = process.sigKill(() => {
|
const result = process.sigKill(() => {
|
||||||
console.log("process kill successful");
|
console.log('process kill successful');
|
||||||
});
|
});
|
||||||
|
|
||||||
//this.isProcessActive = false;
|
//this.isProcessActive = false;
|
||||||
@@ -144,19 +142,17 @@ export class Terminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPrimaryKeybindInhibitor(): KeybindInhibitor {
|
getPrimaryKeybindInhibitor(): KeybindInhibitor {
|
||||||
const processKeybinds: KeybindInhibitor | null =
|
const processKeybinds: KeybindInhibitor | null = this._bash.getProcessKeybindInhibitor();
|
||||||
this._bash.getProcessKeybindInhibitor();
|
if (processKeybinds) {
|
||||||
if(processKeybinds) {
|
|
||||||
return processKeybinds;
|
return processKeybinds;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return this._keybindInhibitor;
|
return this._keybindInhibitor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getProcessKeyInhibitor(): KeybindInhibitor | ExitCode.ERROR {
|
getProcessKeyInhibitor(): KeybindInhibitor | ExitCode.ERROR {
|
||||||
const out = this._bash.getProcessKeybindInhibitor();
|
const out = this._bash.getProcessKeybindInhibitor();
|
||||||
if(out) return out;
|
if (out) return out;
|
||||||
else return ExitCode.ERROR;
|
else return ExitCode.ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,14 +166,18 @@ export class Terminal {
|
|||||||
|
|
||||||
getTerminalWidth(): number {
|
getTerminalWidth(): number {
|
||||||
const width = this._callbacks.getWidth?.();
|
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;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFontSize(): number {
|
getFontSize(): number {
|
||||||
const size = this._callbacks.getFontSize?.();
|
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;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
declare namespace FileSystem {}
|
||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
namespace TermOS {
|
||||||
|
export namespace Shell {
|
||||||
|
export class Bash {
|
||||||
|
private readonly _fs: TermOS.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+27
@@ -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<KeyBind, () => 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+63
@@ -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<CommandResult>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+280
@@ -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<KeyBind, () => any>;
|
||||||
|
|
||||||
|
constructor(keybinds: Map<KeyBind, () => 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<CommandResult>
|
||||||
|
}
|
||||||
|
|
||||||
|
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<Result> {
|
||||||
|
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<number, TreeNode>;
|
||||||
|
|
||||||
|
constructor(fs: Map<number, TreeNode>, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -2,6 +2,11 @@ class Vector2 {
|
|||||||
public x: number;
|
public x: number;
|
||||||
public y: number;
|
public y: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
*/
|
||||||
constructor(x?: number, y?: number);
|
constructor(x?: number, y?: number);
|
||||||
constructor(v?: Vector2);
|
constructor(v?: Vector2);
|
||||||
constructor(x: Vector2 | number = 0, y: number = 0) {
|
constructor(x: Vector2 | number = 0, y: number = 0) {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Renderer from '$lib/shimeji/renderer/renderer';
|
import Renderer from '$lib/shimagic/renderer/rendererr';
|
||||||
import { WebGEngine } from '$lib/shimeji/renderer/web_g_engine';
|
import { WebG } from '$lib/shimagic/renderer/web_g_enginee';
|
||||||
import { Shimeji } from '$lib/stores/shimeji';
|
import { Shimagic } from '$lib/stores/shimeji';
|
||||||
import Vector2 from '$lib/vector';
|
import Vector2 from '$lib/vector';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
const drag: number = 3;
|
const drag: number = 3;
|
||||||
const speed: number = 2;
|
const speed: number = 2;
|
||||||
|
|
||||||
let shimeji: Shimeji;
|
let shimeji: Shimagic.Shimeji;
|
||||||
let renderer: Renderer;
|
let renderer: Renderer;
|
||||||
let sprite: HTMLElement;
|
let sprite: HTMLElement;
|
||||||
let canvas: HTMLCanvasElement;
|
let canvas: HTMLCanvasElement;
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
//const vert = await fetchShader('src/lib/shimeji/renderer/shaders/vertex_shader.vert');
|
//const vert = await fetchShader('src/lib/shimeji/renderer/shaders/vertex_shader.vert');
|
||||||
//const frag = await fetchShader('src/lib/shimeji/renderer/shaders/fragment_shader.frag');
|
//const frag = await fetchShader('src/lib/shimeji/renderer/shaders/fragment_shader.frag');
|
||||||
|
|
||||||
const engineConfig: WebGEngine.EngineConfig = {
|
const engineConfig: WebG.EngineConfig = {
|
||||||
canvas: canvas,
|
canvas: canvas,
|
||||||
vertexShaderUrl: 'src/lib/shimeji/renderer/shaders/vertex_shader.vert',
|
vertexShaderUrl: 'src/lib/shimeji/renderer/shaders/vertex_shader.vert',
|
||||||
fragmentShaderUrl: 'src/lib/shimeji/renderer/shaders/fragment_shader.frag',
|
fragmentShaderUrl: 'src/lib/shimeji/renderer/shaders/fragment_shader.frag',
|
||||||
@@ -42,9 +42,9 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const engine = await WebGEngine.Engine.Initialize(engineConfig);
|
const engine = await WebG.Engine.Initialize(engineConfig);
|
||||||
|
|
||||||
const drawArgs: WebGEngine.DrawCallArgs = {
|
const drawArgs: WebG.DrawCallArgs = {
|
||||||
vertices: [
|
vertices: [
|
||||||
new Vector2(200, 200),
|
new Vector2(200, 200),
|
||||||
new Vector2(700, 700),
|
new Vector2(700, 700),
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
engine.setDrawMode(WebGEngine.EngineDrawMode.TEXTURE);
|
engine.setDrawMode(WebG.EngineDrawMode.TEXTURE);
|
||||||
engine.draw(drawArgs);
|
engine.draw(drawArgs);
|
||||||
|
|
||||||
/* shimeji = new Shimeji(40, canvas, renderer);
|
/* shimeji = new Shimeji(40, canvas, renderer);
|
||||||
|
|||||||
Reference in New Issue
Block a user