This commit is contained in:
Djeeberjr 2022-02-21 15:35:37 +01:00
parent f21e49c520
commit 0ad907f74a
33 changed files with 788 additions and 815 deletions

View File

@ -2,6 +2,7 @@ package kernel;
import util.Vec.Vec2;
import haxe.Exception;
using tink.CoreApi;
import cc.OS;
@ -23,7 +24,13 @@ class KernelEvents{
public final onHttpSuccess:Signal<{url:String, handle:Any}>;
public final onKey:Signal<{keyCode:Int, isHeld:Bool}>;
public final onKeyUp:Signal<Int>;
public final onModemMessage: Signal<{addr: String,channel:Int, replyChannel:Int,message:Dynamic,distance:Int}>;
public final onModemMessage:Signal<{
addr:String,
channel:Int,
replyChannel:Int,
message:Dynamic,
distance:Int
}>;
public final onMonitorResize:Signal<String>;
public final onMonitorTouch:Signal<{addr:String, pos:Vec2<Int>}>;
public final onMouseClick:Signal<{button:ButtonType, pos:Vec2<Int>}>;
@ -55,7 +62,13 @@ class KernelEvents{
private final onHttpSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
private final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}> = Signal.trigger();
private final onKeyUpTrigger:SignalTrigger<Int> = Signal.trigger();
private final onModemMessageTrigger: SignalTrigger<{addr: String,channel:Int, replyChannel:Int,message:Dynamic,distance:Int}> = Signal.trigger();
private final onModemMessageTrigger:SignalTrigger<{
addr:String,
channel:Int,
replyChannel:Int,
message:Dynamic,
distance:Int
}> = Signal.trigger();
private final onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger();
private final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Vec2<Int>}> = Signal.trigger();
private final onMouseClickTrigger:SignalTrigger<{button:ButtonType, pos:Vec2<Int>}> = Signal.trigger();
@ -142,7 +155,13 @@ class KernelEvents{
case "key_up":
this.onKeyUpTrigger.trigger(event[2]);
case "modem_message":
this.onModemMessageTrigger.trigger({addr: event[2],channel: event[3],replyChannel: event[4],message: event[5],distance: event[6]});
this.onModemMessageTrigger.trigger({
addr: event[2],
channel: event[3],
replyChannel: event[4],
message: event[5],
distance: event[6]
});
case "monitor_resize":
this.onMonitorResizeTrigger.trigger(event[2]);
case "monitor_touch":

View File

@ -12,6 +12,7 @@ import util.Color;
**/
class MainTerm implements TermWriteable {
public static var instance:MainTerm;
public var onResize(default, null):Signal<Vec2<Int>>;
private var onResizeTrigger:SignalTrigger<Vec2<Int>>;
@ -26,7 +27,6 @@ class MainTerm implements TermWriteable{
});
}
public function write(text:String) {
Term.write(text);
}

View File

@ -57,7 +57,6 @@ class Net{
responseBus.emit(Std.string(pack.msgID), pack);
case RouteDiscover:
handleRoute(pack, addr);
}
}
@ -134,7 +133,6 @@ class Net{
Send a message. Dont care if its reaches its destination nor it has a response.
**/
public function sendAndForget(dest:Int, proto:String, data:Dynamic) {
var pack:Package = {
toID: dest,
fromID: networkID,
@ -175,7 +173,6 @@ class Net{
}
private function sendRaw(pack:Package) {
if (pack.toID == networkID) {
// Loopback
handelIncomming(pack);

View File

@ -1,31 +0,0 @@
package kernel.peripherals;
class Item {
}
class Inventory {
public function size():Int {
}
public function list(): Map<Int,Item> {
}
public function getItemDetail(slot: Int): Item {
}
public function pushItems(toName: String, fromSlot: Int, ?limit:Int, toSlot: Int): Int {
}
public function pullItems(fromName: String, fromSlot: Int, ?limit:Int, ?toSlot: Int): Int {
}
}

View File

@ -11,10 +11,9 @@ class Screen implements TermWriteable{
private final nativ:cc.periphs.Monitor.Monitor;
private final addr:String;
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
public var onResize(default,null):Signal<Vec2<Int>>;
public var onResize(default, null):Signal<Vec2<Int>>;
@:allow(kernel.peripherals)
public function new(nativePeripherals:cc.periphs.Monitor.Monitor, addr:String) {

View File

@ -13,17 +13,18 @@ import lib.TermWriteable;
}
class TermBuffer implements TermWriteable {
/**
format [y][x]. First index is the line. Second index the char in the line.
**/
private var screenBuffer:Array<Array<Pixel>>;
private var cursorPos:Vec2<Int> = {x: 0, y: 0};
private var currentTextColor:Color = White;
private var currentBgColor:Color = Black;
private var size:Vec2<Int> = {x: 51, y: 19}; // Default size set to default size of the main terminal
public var onResize(default, null):Signal<Vec2<Int>>;
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
public function new() {
@ -97,7 +98,6 @@ class TermBuffer implements TermWriteable {
}
}
//
// TermWriteable functions
//
@ -110,11 +110,14 @@ class TermBuffer implements TermWriteable {
}
public function scroll(y:Int) {
screenBuffer.unshift([for (i in 0...size.x) {
screenBuffer.unshift([
for (i in 0...size.x)
{
char: " ",
textColor: White, // TODO: maybe replace with current bg/text color. Check nativ implementation
bg: Black
}]);
}
]);
}
public function getCursorPos():Vec2<Int> {

View File

@ -26,7 +26,6 @@ class WindowContext implements TermWriteable {
@:allow(kernel.ui.WindowManager) private final mouseUpTrigger:SignalTrigger<{button:ButtonType, pos:Vec2<Int>}>;
@:allow(kernel.ui.WindowManager) private final pasteTrigger:SignalTrigger<String>;
public function new(writer:VirtualTermWriter) {
this.writer = writer;
this.onResize = writer.onResize;
@ -46,7 +45,6 @@ class WindowContext implements TermWriteable {
this.mouseScrollSignal = mouseScrollTrigger.asSignal();
this.mouseUpSignal = mouseUpTrigger.asSignal();
this.pasteSignal = pasteTrigger.asSignal();
}
public var onResize(default, null):Signal<Vec2<Int>>;

View File

@ -8,7 +8,6 @@ class WindowManager {
@:allow(kernel.Init)
private function new() {
KernelEvents.instance.onKey.handle(params -> {
if (currentMainContext != null) {
currentMainContext.keyTrigger.trigger(params);
@ -72,7 +71,6 @@ class WindowManager {
return newContext;
}
public function getOutputs():Array<String> {
var arr = Peripheral.instance.getScreens().map(screen -> return screen.getAddr());
arr.push("main");
@ -92,12 +90,10 @@ class WindowManager {
}
}
if (outputMap.exists(output)) {
outputMap[output].disable();
}
outputMap[output] = context;
context.setTarget(target);
context.enable();

View File

@ -1,6 +1,5 @@
package lib;
import util.Vec.Vec2;
import util.Color;
import lib.TermWriteable;
@ -43,6 +42,5 @@ class TermIO {
} else {
output.setCursorPos(0, cPos.y + 1);
}
}
}

View File

@ -9,7 +9,6 @@ import util.Vec.Vec2;
Interface describing a terminal. E.g. the main computer screen or a external screen.
**/
interface TermWriteable {
public var onResize(default, null):Signal<Vec2<Int>>;
public function write(text:String):Void;
@ -24,6 +23,7 @@ interface TermWriteable {
Even though CC is 1 based we use a 0 based index.
**/
public function setCursorPos(x:Int, y:Int):Void;
public function getCursorBlink():Bool;
public function setCursorBlink(blink:Bool):Void;
public function getSize():Vec2<Int>;

View File

@ -1,6 +1,7 @@
package lib.ui;
using tink.CoreApi;
import util.Vec.Vec2;
interface IElement {

View File

@ -39,7 +39,6 @@ class ReactiveUI {
context.setCursorPos(0, 0);
for (key => pixel in screen) {
if (key.y != currentLine) {
currentLine = key.y;
context.setCursorPos(key.x, key.y);

View File

@ -8,6 +8,7 @@ import util.MathI;
class TextElement implements IElement {
public var changed(default, null):Signal<Noise>;
private var changedTrigger:SignalTrigger<Noise>;
private final text:Observable<String>;
@ -15,7 +16,6 @@ class TextElement implements IElement {
private final fg:Color;
public function new(text:Observable<String>, ?background:Color = Black, ?textColor:Color = White) {
setupTrigger();
this.text = text;

View File

@ -40,4 +40,3 @@ class BuildInfo {
#end
}
}

View File

@ -22,9 +22,7 @@ class EventBusListner {
class EventBus<T> {
private var listner:Map<String, SignalTrigger<T>> = new Map();
public function new() {
}
public function new() {}
public function on(eventName:String, callback:Callback<T>):EventBusListner {
if (!listner.exists(eventName)) {
@ -57,5 +55,4 @@ class EventBus<T>{
}
id.link.cancel();
}
}

View File

@ -35,6 +35,5 @@ class Promise<T> {
errorCB(e);
}
}
}
}

View File

@ -5,7 +5,6 @@ package util;
public final y:T;
}
@:structInit class Vec3<T> {
public final x:T;
public final y:T;