format
This commit is contained in:
parent
f21e49c520
commit
0ad907f74a
@ -2,6 +2,7 @@ package kernel;
|
|||||||
|
|
||||||
import util.Vec.Vec2;
|
import util.Vec.Vec2;
|
||||||
import haxe.Exception;
|
import haxe.Exception;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
import cc.OS;
|
import cc.OS;
|
||||||
@ -23,7 +24,13 @@ class KernelEvents{
|
|||||||
public final onHttpSuccess:Signal<{url:String, handle:Any}>;
|
public final onHttpSuccess:Signal<{url:String, handle:Any}>;
|
||||||
public final onKey:Signal<{keyCode:Int, isHeld:Bool}>;
|
public final onKey:Signal<{keyCode:Int, isHeld:Bool}>;
|
||||||
public final onKeyUp:Signal<Int>;
|
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 onMonitorResize:Signal<String>;
|
||||||
public final onMonitorTouch:Signal<{addr:String, pos:Vec2<Int>}>;
|
public final onMonitorTouch:Signal<{addr:String, pos:Vec2<Int>}>;
|
||||||
public final onMouseClick:Signal<{button:ButtonType, 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 onHttpSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
||||||
private final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}> = Signal.trigger();
|
private final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}> = Signal.trigger();
|
||||||
private final onKeyUpTrigger:SignalTrigger<Int> = 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 onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger();
|
||||||
private final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Vec2<Int>}> = Signal.trigger();
|
private final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Vec2<Int>}> = Signal.trigger();
|
||||||
private final onMouseClickTrigger:SignalTrigger<{button:ButtonType, 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":
|
case "key_up":
|
||||||
this.onKeyUpTrigger.trigger(event[2]);
|
this.onKeyUpTrigger.trigger(event[2]);
|
||||||
case "modem_message":
|
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":
|
case "monitor_resize":
|
||||||
this.onMonitorResizeTrigger.trigger(event[2]);
|
this.onMonitorResizeTrigger.trigger(event[2]);
|
||||||
case "monitor_touch":
|
case "monitor_touch":
|
||||||
|
@ -12,6 +12,7 @@ import util.Color;
|
|||||||
**/
|
**/
|
||||||
class MainTerm implements TermWriteable {
|
class MainTerm implements TermWriteable {
|
||||||
public static var instance:MainTerm;
|
public static var instance:MainTerm;
|
||||||
|
|
||||||
public var onResize(default, null):Signal<Vec2<Int>>;
|
public var onResize(default, null):Signal<Vec2<Int>>;
|
||||||
|
|
||||||
private var onResizeTrigger:SignalTrigger<Vec2<Int>>;
|
private var onResizeTrigger:SignalTrigger<Vec2<Int>>;
|
||||||
@ -26,7 +27,6 @@ class MainTerm implements TermWriteable{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function write(text:String) {
|
public function write(text:String) {
|
||||||
Term.write(text);
|
Term.write(text);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,6 @@ class Net{
|
|||||||
responseBus.emit(Std.string(pack.msgID), pack);
|
responseBus.emit(Std.string(pack.msgID), pack);
|
||||||
case RouteDiscover:
|
case RouteDiscover:
|
||||||
handleRoute(pack, addr);
|
handleRoute(pack, addr);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +133,6 @@ class Net{
|
|||||||
Send a message. Dont care if its reaches its destination nor it has a response.
|
Send a message. Dont care if its reaches its destination nor it has a response.
|
||||||
**/
|
**/
|
||||||
public function sendAndForget(dest:Int, proto:String, data:Dynamic) {
|
public function sendAndForget(dest:Int, proto:String, data:Dynamic) {
|
||||||
|
|
||||||
var pack:Package = {
|
var pack:Package = {
|
||||||
toID: dest,
|
toID: dest,
|
||||||
fromID: networkID,
|
fromID: networkID,
|
||||||
@ -175,7 +173,6 @@ class Net{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function sendRaw(pack:Package) {
|
private function sendRaw(pack:Package) {
|
||||||
|
|
||||||
if (pack.toID == networkID) {
|
if (pack.toID == networkID) {
|
||||||
// Loopback
|
// Loopback
|
||||||
handelIncomming(pack);
|
handelIncomming(pack);
|
||||||
|
@ -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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,10 +11,9 @@ class Screen implements TermWriteable{
|
|||||||
private final nativ:cc.periphs.Monitor.Monitor;
|
private final nativ:cc.periphs.Monitor.Monitor;
|
||||||
private final addr:String;
|
private final addr:String;
|
||||||
|
|
||||||
|
|
||||||
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
|
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)
|
@:allow(kernel.peripherals)
|
||||||
public function new(nativePeripherals:cc.periphs.Monitor.Monitor, addr:String) {
|
public function new(nativePeripherals:cc.periphs.Monitor.Monitor, addr:String) {
|
||||||
|
@ -13,17 +13,18 @@ import lib.TermWriteable;
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TermBuffer implements TermWriteable {
|
class TermBuffer implements TermWriteable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
format [y][x]. First index is the line. Second index the char in the line.
|
format [y][x]. First index is the line. Second index the char in the line.
|
||||||
**/
|
**/
|
||||||
private var screenBuffer:Array<Array<Pixel>>;
|
private var screenBuffer:Array<Array<Pixel>>;
|
||||||
|
|
||||||
private var cursorPos:Vec2<Int> = {x: 0, y: 0};
|
private var cursorPos:Vec2<Int> = {x: 0, y: 0};
|
||||||
private var currentTextColor:Color = White;
|
private var currentTextColor:Color = White;
|
||||||
private var currentBgColor:Color = Black;
|
private var currentBgColor:Color = Black;
|
||||||
private var size:Vec2<Int> = {x: 51, y: 19}; // Default size set to default size of the main terminal
|
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>>;
|
public var onResize(default, null):Signal<Vec2<Int>>;
|
||||||
|
|
||||||
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
|
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
@ -97,7 +98,6 @@ class TermBuffer implements TermWriteable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// TermWriteable functions
|
// TermWriteable functions
|
||||||
//
|
//
|
||||||
@ -110,11 +110,14 @@ class TermBuffer implements TermWriteable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function scroll(y:Int) {
|
public function scroll(y:Int) {
|
||||||
screenBuffer.unshift([for (i in 0...size.x) {
|
screenBuffer.unshift([
|
||||||
|
for (i in 0...size.x)
|
||||||
|
{
|
||||||
char: " ",
|
char: " ",
|
||||||
textColor: White, // TODO: maybe replace with current bg/text color. Check nativ implementation
|
textColor: White, // TODO: maybe replace with current bg/text color. Check nativ implementation
|
||||||
bg: Black
|
bg: Black
|
||||||
}]);
|
}
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCursorPos():Vec2<Int> {
|
public function getCursorPos():Vec2<Int> {
|
||||||
|
@ -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 mouseUpTrigger:SignalTrigger<{button:ButtonType, pos:Vec2<Int>}>;
|
||||||
@:allow(kernel.ui.WindowManager) private final pasteTrigger:SignalTrigger<String>;
|
@:allow(kernel.ui.WindowManager) private final pasteTrigger:SignalTrigger<String>;
|
||||||
|
|
||||||
|
|
||||||
public function new(writer:VirtualTermWriter) {
|
public function new(writer:VirtualTermWriter) {
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
this.onResize = writer.onResize;
|
this.onResize = writer.onResize;
|
||||||
@ -46,7 +45,6 @@ class WindowContext implements TermWriteable {
|
|||||||
this.mouseScrollSignal = mouseScrollTrigger.asSignal();
|
this.mouseScrollSignal = mouseScrollTrigger.asSignal();
|
||||||
this.mouseUpSignal = mouseUpTrigger.asSignal();
|
this.mouseUpSignal = mouseUpTrigger.asSignal();
|
||||||
this.pasteSignal = pasteTrigger.asSignal();
|
this.pasteSignal = pasteTrigger.asSignal();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public var onResize(default, null):Signal<Vec2<Int>>;
|
public var onResize(default, null):Signal<Vec2<Int>>;
|
||||||
|
@ -8,7 +8,6 @@ class WindowManager {
|
|||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private function new() {
|
private function new() {
|
||||||
|
|
||||||
KernelEvents.instance.onKey.handle(params -> {
|
KernelEvents.instance.onKey.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.keyTrigger.trigger(params);
|
currentMainContext.keyTrigger.trigger(params);
|
||||||
@ -72,7 +71,6 @@ class WindowManager {
|
|||||||
return newContext;
|
return newContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getOutputs():Array<String> {
|
public function getOutputs():Array<String> {
|
||||||
var arr = Peripheral.instance.getScreens().map(screen -> return screen.getAddr());
|
var arr = Peripheral.instance.getScreens().map(screen -> return screen.getAddr());
|
||||||
arr.push("main");
|
arr.push("main");
|
||||||
@ -92,12 +90,10 @@ class WindowManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (outputMap.exists(output)) {
|
if (outputMap.exists(output)) {
|
||||||
outputMap[output].disable();
|
outputMap[output].disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
outputMap[output] = context;
|
outputMap[output] = context;
|
||||||
context.setTarget(target);
|
context.setTarget(target);
|
||||||
context.enable();
|
context.enable();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package lib;
|
package lib;
|
||||||
|
|
||||||
import util.Vec.Vec2;
|
|
||||||
import util.Color;
|
import util.Color;
|
||||||
import lib.TermWriteable;
|
import lib.TermWriteable;
|
||||||
|
|
||||||
@ -43,6 +42,5 @@ class TermIO {
|
|||||||
} else {
|
} else {
|
||||||
output.setCursorPos(0, cPos.y + 1);
|
output.setCursorPos(0, cPos.y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import util.Vec.Vec2;
|
|||||||
Interface describing a terminal. E.g. the main computer screen or a external screen.
|
Interface describing a terminal. E.g. the main computer screen or a external screen.
|
||||||
**/
|
**/
|
||||||
interface TermWriteable {
|
interface TermWriteable {
|
||||||
|
|
||||||
public var onResize(default, null):Signal<Vec2<Int>>;
|
public var onResize(default, null):Signal<Vec2<Int>>;
|
||||||
|
|
||||||
public function write(text:String):Void;
|
public function write(text:String):Void;
|
||||||
@ -24,6 +23,7 @@ interface TermWriteable {
|
|||||||
Even though CC is 1 based we use a 0 based index.
|
Even though CC is 1 based we use a 0 based index.
|
||||||
**/
|
**/
|
||||||
public function setCursorPos(x:Int, y:Int):Void;
|
public function setCursorPos(x:Int, y:Int):Void;
|
||||||
|
|
||||||
public function getCursorBlink():Bool;
|
public function getCursorBlink():Bool;
|
||||||
public function setCursorBlink(blink:Bool):Void;
|
public function setCursorBlink(blink:Bool):Void;
|
||||||
public function getSize():Vec2<Int>;
|
public function getSize():Vec2<Int>;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package lib.ui;
|
package lib.ui;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
import util.Vec.Vec2;
|
import util.Vec.Vec2;
|
||||||
|
|
||||||
interface IElement {
|
interface IElement {
|
||||||
|
@ -39,7 +39,6 @@ class ReactiveUI {
|
|||||||
context.setCursorPos(0, 0);
|
context.setCursorPos(0, 0);
|
||||||
|
|
||||||
for (key => pixel in screen) {
|
for (key => pixel in screen) {
|
||||||
|
|
||||||
if (key.y != currentLine) {
|
if (key.y != currentLine) {
|
||||||
currentLine = key.y;
|
currentLine = key.y;
|
||||||
context.setCursorPos(key.x, key.y);
|
context.setCursorPos(key.x, key.y);
|
||||||
|
@ -8,6 +8,7 @@ import util.MathI;
|
|||||||
|
|
||||||
class TextElement implements IElement {
|
class TextElement implements IElement {
|
||||||
public var changed(default, null):Signal<Noise>;
|
public var changed(default, null):Signal<Noise>;
|
||||||
|
|
||||||
private var changedTrigger:SignalTrigger<Noise>;
|
private var changedTrigger:SignalTrigger<Noise>;
|
||||||
|
|
||||||
private final text:Observable<String>;
|
private final text:Observable<String>;
|
||||||
@ -15,7 +16,6 @@ class TextElement implements IElement {
|
|||||||
private final fg:Color;
|
private final fg:Color;
|
||||||
|
|
||||||
public function new(text:Observable<String>, ?background:Color = Black, ?textColor:Color = White) {
|
public function new(text:Observable<String>, ?background:Color = Black, ?textColor:Color = White) {
|
||||||
|
|
||||||
setupTrigger();
|
setupTrigger();
|
||||||
|
|
||||||
this.text = text;
|
this.text = text;
|
||||||
|
@ -40,4 +40,3 @@ class BuildInfo {
|
|||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,9 +22,7 @@ class EventBusListner {
|
|||||||
class EventBus<T> {
|
class EventBus<T> {
|
||||||
private var listner:Map<String, SignalTrigger<T>> = new Map();
|
private var listner:Map<String, SignalTrigger<T>> = new Map();
|
||||||
|
|
||||||
public function new() {
|
public function new() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function on(eventName:String, callback:Callback<T>):EventBusListner {
|
public function on(eventName:String, callback:Callback<T>):EventBusListner {
|
||||||
if (!listner.exists(eventName)) {
|
if (!listner.exists(eventName)) {
|
||||||
@ -57,5 +55,4 @@ class EventBus<T>{
|
|||||||
}
|
}
|
||||||
id.link.cancel();
|
id.link.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -35,6 +35,5 @@ class Promise<T> {
|
|||||||
errorCB(e);
|
errorCB(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,7 +5,6 @@ package util;
|
|||||||
public final y:T;
|
public final y:T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@:structInit class Vec3<T> {
|
@:structInit class Vec3<T> {
|
||||||
public final x:T;
|
public final x:T;
|
||||||
public final y:T;
|
public final y:T;
|
||||||
|
Loading…
Reference in New Issue
Block a user