BIG FORMATING COMMIT
This commit is contained in:
parent
088fce0aaa
commit
91972107eb
@ -7,4 +7,3 @@ class Startup {
|
|||||||
main.run();
|
main.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,19 +8,19 @@ using Lambda;
|
|||||||
|
|
||||||
class Disk extends CLIAppBase {
|
class Disk extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("ls", (args)->{
|
registerSyncSubcommand("ls", (args) -> {
|
||||||
Peripheral.getAllDrives().foreach(drive -> {
|
Peripheral.getAllDrives().foreach(drive -> {
|
||||||
var addr = drive.getAddr();
|
var addr = drive.getAddr();
|
||||||
var label = drive.getDiskLabel();
|
var label = drive.getDiskLabel();
|
||||||
var id = drive.getDiskID();
|
var id = drive.getDiskID();
|
||||||
|
|
||||||
if (drive.isDiskPresent()){
|
if (drive.isDiskPresent()) {
|
||||||
if (drive.hasAudio()){
|
if (drive.hasAudio()) {
|
||||||
handle.writeLine('${addr} => ${label} [AUDIO]');
|
handle.writeLine('${addr} => ${label} [AUDIO]');
|
||||||
}else{
|
} else {
|
||||||
handle.writeLine('${addr} => ${label} (${id})');
|
handle.writeLine('${addr} => ${label} (${id})');
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
handle.writeLine('${addr} => [NO DISK]');
|
handle.writeLine('${addr} => [NO DISK]');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,26 +28,26 @@ class Disk extends CLIAppBase {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("play", (args)->{
|
registerSyncSubcommand("play", (args) -> {
|
||||||
if (args.length < 1){
|
if (args.length < 1) {
|
||||||
handle.writeLine("Missing drive address");
|
handle.writeLine("Missing drive address");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioDiskPlayPause(args[0], true);
|
return audioDiskPlayPause(args[0], true);
|
||||||
},"<drive>");
|
}, "<drive>");
|
||||||
|
|
||||||
registerSyncSubcommand("stop", (args) -> {
|
registerSyncSubcommand("stop", (args) -> {
|
||||||
if (args.length < 1){
|
if (args.length < 1) {
|
||||||
handle.writeLine("Missing drive address");
|
handle.writeLine("Missing drive address");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioDiskPlayPause(args[0], false);
|
return audioDiskPlayPause(args[0], false);
|
||||||
},"<drive>");
|
}, "<drive>");
|
||||||
|
|
||||||
registerSyncSubcommand("eject", (args)->{
|
registerSyncSubcommand("eject", (args) -> {
|
||||||
if (args.length < 1){
|
if (args.length < 1) {
|
||||||
handle.writeLine("Missing drive address");
|
handle.writeLine("Missing drive address");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -55,22 +55,22 @@ class Disk extends CLIAppBase {
|
|||||||
var driveAddr = args[0];
|
var driveAddr = args[0];
|
||||||
var drive = Peripheral.getDrive(driveAddr);
|
var drive = Peripheral.getDrive(driveAddr);
|
||||||
|
|
||||||
if (drive == null){
|
if (drive == null) {
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
handle.writeLine("Drive not found: " + driveAddr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
if (!drive.isDiskPresent()) {
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
drive.ejectDisk();
|
drive.ejectDisk();
|
||||||
return true;
|
return true;
|
||||||
},"<drive>");
|
}, "<drive>");
|
||||||
|
|
||||||
registerSyncSubcommand("lable",(args) -> {
|
registerSyncSubcommand("lable", (args) -> {
|
||||||
if (args.length < 1){
|
if (args.length < 1) {
|
||||||
handle.writeLine("Missing drive address");
|
handle.writeLine("Missing drive address");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -79,49 +79,49 @@ class Disk extends CLIAppBase {
|
|||||||
var drive = Peripheral.getDrive(driveAddr);
|
var drive = Peripheral.getDrive(driveAddr);
|
||||||
var label:String = args[1];
|
var label:String = args[1];
|
||||||
|
|
||||||
if (drive == null){
|
if (drive == null) {
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
handle.writeLine("Drive not found: " + driveAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
if (!drive.isDiskPresent()) {
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label == null || label == ""){
|
if (label == null || label == "") {
|
||||||
handle.writeLine(drive.getDiskLabel());
|
handle.writeLine(drive.getDiskLabel());
|
||||||
}else{
|
} else {
|
||||||
var err = drive.setDiskLabel(label);
|
var err = drive.setDiskLabel(label);
|
||||||
if (err != null){
|
if (err != null) {
|
||||||
handle.writeLine("Failed to set lable");
|
handle.writeLine("Failed to set lable");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},"<drive> [label]");
|
}, "<drive> [label]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function audioDiskPlayPause(driveAddr: String, play: Bool): Bool {
|
private function audioDiskPlayPause(driveAddr:String, play:Bool):Bool {
|
||||||
var drive = Peripheral.getDrive(driveAddr);
|
var drive = Peripheral.getDrive(driveAddr);
|
||||||
|
|
||||||
if (drive == null){
|
if (drive == null) {
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
handle.writeLine("Drive not found: " + driveAddr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
if (!drive.isDiskPresent()) {
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drive.hasAudio()){
|
if (!drive.hasAudio()) {
|
||||||
handle.writeLine("Disk in drive: " + driveAddr + " does not have audio");
|
handle.writeLine("Disk in drive: " + driveAddr + " does not have audio");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (play){
|
if (play) {
|
||||||
drive.playAudio();
|
drive.playAudio();
|
||||||
}else{
|
} else {
|
||||||
drive.stopAudio();
|
drive.stopAudio();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,19 +9,19 @@ using tink.CoreApi;
|
|||||||
|
|
||||||
class GPS extends CLIAppBase {
|
class GPS extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("set", (args)->{
|
registerSyncSubcommand("set", (args) -> {
|
||||||
var x: Float = Std.parseFloat(args[0]);
|
var x:Float = Std.parseFloat(args[0]);
|
||||||
var y: Float = Std.parseFloat(args[1]);
|
var y:Float = Std.parseFloat(args[1]);
|
||||||
var z: Float = Std.parseFloat(args[2]);
|
var z:Float = Std.parseFloat(args[2]);
|
||||||
|
|
||||||
var pos: Pos3 = new Vec3<Float>(x, y, z);
|
|
||||||
|
|
||||||
kernel.gps.GPS.setManualPosition(pos);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},"<x> <y> <z>");
|
|
||||||
|
|
||||||
registerSyncSubcommand("status",(args)->{
|
var pos:Pos3 = new Vec3<Float>(x, y, z);
|
||||||
|
|
||||||
|
kernel.gps.GPS.setManualPosition(pos);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, "<x> <y> <z>");
|
||||||
|
|
||||||
|
registerSyncSubcommand("status", (args) -> {
|
||||||
var pos = kernel.gps.GPS.getPosition();
|
var pos = kernel.gps.GPS.getPosition();
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||||
@ -29,28 +29,28 @@ class GPS extends CLIAppBase {
|
|||||||
handle.writeLine("Position not available");
|
handle.writeLine("Position not available");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc = kernel.gps.GPS.getAccuracy();
|
var acc = kernel.gps.GPS.getAccuracy();
|
||||||
if (acc == 1){
|
if (acc == 1) {
|
||||||
handle.writeLine("Accuracy: Low");
|
handle.writeLine("Accuracy: Low");
|
||||||
} else if (acc == 2){
|
} else if (acc == 2) {
|
||||||
handle.writeLine("Accuracy: Medium");
|
handle.writeLine("Accuracy: Medium");
|
||||||
} else if (acc == 3){
|
} else if (acc == 3) {
|
||||||
handle.writeLine("Accuracy: High");
|
handle.writeLine("Accuracy: High");
|
||||||
}
|
}
|
||||||
|
|
||||||
var ins = INS.getHeading();
|
var ins = INS.getHeading();
|
||||||
if (ins != null) {
|
if (ins != null) {
|
||||||
handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
||||||
} else {
|
} else {
|
||||||
handle.writeLine("INS heading not available");
|
handle.writeLine("INS heading not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerAsyncSubcommand("locate",(args)->{
|
registerAsyncSubcommand("locate", (args) -> {
|
||||||
return kernel.gps.GPS.locate().map((pos)->{
|
return kernel.gps.GPS.locate().map((pos) -> {
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||||
} else {
|
} else {
|
||||||
@ -60,8 +60,8 @@ class GPS extends CLIAppBase {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
registerAsyncSubcommand("ins",(args)->{
|
registerAsyncSubcommand("ins", (args) -> {
|
||||||
return INS.align().map((_)->{
|
return INS.align().map((_) -> {
|
||||||
handle.writeLine("INS aligned");
|
handle.writeLine("INS aligned");
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,6 @@ import kernel.ps.Process;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class HelloWorld implements Process {
|
class HelloWorld implements Process {
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
@ -15,7 +14,7 @@ class HelloWorld implements Process {
|
|||||||
|
|
||||||
var c = new HelloWorldServiceRPC(0);
|
var c = new HelloWorldServiceRPC(0);
|
||||||
|
|
||||||
c.getNumber().handle((res)->{
|
c.getNumber().handle((res) -> {
|
||||||
Log.debug("Got number: " + res);
|
Log.debug("Got number: " + res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,18 +8,18 @@ using tink.CoreApi;
|
|||||||
|
|
||||||
@:build(macros.rpc.RPC.buildRPC())
|
@:build(macros.rpc.RPC.buildRPC())
|
||||||
class HelloWorldService implements Process {
|
class HelloWorldService implements Process {
|
||||||
private var handle:ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
RPC.generateRPCPackageHandle();
|
RPC.generateRPCPackageHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@rpc
|
@rpc
|
||||||
public function getNumber():Int{
|
public function getNumber():Int {
|
||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ import kernel.ps.ProcessHandle;
|
|||||||
import kernel.ps.Process;
|
import kernel.ps.Process;
|
||||||
|
|
||||||
class ID implements Process {
|
class ID implements Process {
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
handle.writeLine("ID: " + kernel.net.Net.networkID);
|
handle.writeLine("ID: " + kernel.net.Net.networkID);
|
||||||
handle.close();
|
handle.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,64 +4,64 @@ import kernel.KernelSettings;
|
|||||||
import lib.CLIAppBase;
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
class KSettings extends CLIAppBase {
|
class KSettings extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("get", (args)->{
|
registerSyncSubcommand("get", (args) -> {
|
||||||
var key = args[0];
|
var key = args[0];
|
||||||
|
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
handle.writeLine("Key not specified");
|
handle.writeLine("Key not specified");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = switch (key){
|
var value = switch (key) {
|
||||||
case "hostname":
|
case "hostname":
|
||||||
KernelSettings.hostname;
|
KernelSettings.hostname;
|
||||||
case "sitecontroller":
|
case "sitecontroller":
|
||||||
Std.string(KernelSettings.siteController);
|
Std.string(KernelSettings.siteController);
|
||||||
default:
|
default:
|
||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
handle.writeLine("Key not found or not set");
|
handle.writeLine("Key not found or not set");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.writeLine(value);
|
handle.writeLine(value);
|
||||||
return true;
|
return true;
|
||||||
}," <key>");
|
}, " <key>");
|
||||||
|
|
||||||
registerSyncSubcommand("set", (args)->{
|
registerSyncSubcommand("set", (args) -> {
|
||||||
var key = args[0];
|
var key = args[0];
|
||||||
|
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
handle.writeLine("Key not specified");
|
handle.writeLine("Key not specified");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = args[1];
|
var value = args[1];
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
handle.writeLine("Value not specified");
|
handle.writeLine("Value not specified");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (key){
|
switch (key) {
|
||||||
case "hostname":
|
case "hostname":
|
||||||
KernelSettings.hostname = value;
|
KernelSettings.hostname = value;
|
||||||
case "sitecontroller":
|
case "sitecontroller":
|
||||||
KernelSettings.siteController = Std.parseInt(value);
|
KernelSettings.siteController = Std.parseInt(value);
|
||||||
default:
|
default:
|
||||||
handle.writeLine("Key not found");
|
handle.writeLine("Key not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}," <key> <value>");
|
}, " <key> <value>");
|
||||||
|
|
||||||
registerSyncSubcommand("list", (args)->{
|
registerSyncSubcommand("list", (args) -> {
|
||||||
handle.writeLine("hostname");
|
handle.writeLine("hostname");
|
||||||
handle.writeLine("sitecontroller");
|
handle.writeLine("sitecontroller");
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,12 @@ import lib.ui.UIApp;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class KernelLog implements Process {
|
class KernelLog implements Process {
|
||||||
private var handle: ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
private var ctx: WindowContext;
|
private var ctx:WindowContext;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle: ProcessHandle):Void {
|
public function run(handle:ProcessHandle):Void {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var statelessCtx = handle.createStatelessWindowContext();
|
var statelessCtx = handle.createStatelessWindowContext();
|
||||||
@ -24,23 +24,23 @@ class KernelLog implements Process {
|
|||||||
|
|
||||||
statelessCtx.setRenderFunc(this.render);
|
statelessCtx.setRenderFunc(this.render);
|
||||||
|
|
||||||
Log.onLog.handle(()->{
|
Log.onLog.handle(() -> {
|
||||||
statelessCtx.requestRender();
|
statelessCtx.requestRender();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function render() {
|
private function render() {
|
||||||
ctx.clear();
|
ctx.clear();
|
||||||
ctx.setCursorPos(0,0);
|
ctx.setCursorPos(0, 0);
|
||||||
|
|
||||||
var lines = Log.getLines();
|
var lines = Log.getLines();
|
||||||
var height = ctx.getSize().y;
|
var height = ctx.getSize().y;
|
||||||
var start = MathI.max(lines.length - height,0);
|
var start = MathI.max(lines.length - height, 0);
|
||||||
|
|
||||||
for (i in start...lines.length) {
|
for (i in start...lines.length) {
|
||||||
var line = lines[i];
|
var line = lines[i];
|
||||||
|
|
||||||
switch (line.level){
|
switch (line.level) {
|
||||||
case Info:
|
case Info:
|
||||||
ctx.setTextColor(Color.White);
|
ctx.setTextColor(Color.White);
|
||||||
ctx.write("[INFO] ");
|
ctx.write("[INFO] ");
|
||||||
@ -59,7 +59,7 @@ class KernelLog implements Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.write(line.message);
|
ctx.write(line.message);
|
||||||
ctx.setCursorPos(0,ctx.getCursorPos().y + 1);
|
ctx.setCursorPos(0, ctx.getCursorPos().y + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,17 @@ import kernel.ps.ProcessHandle;
|
|||||||
import kernel.ps.Process;
|
import kernel.ps.Process;
|
||||||
|
|
||||||
class LSPS implements Process {
|
class LSPS implements Process {
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
var pids = ProcessManager.listProcesses();
|
var pids = ProcessManager.listProcesses();
|
||||||
|
|
||||||
handle.writeLine('Count: ${pids.length}');
|
handle.writeLine('Count: ${pids.length}');
|
||||||
|
|
||||||
for (pid in pids) {
|
for (pid in pids) {
|
||||||
handle.writeLine('${pid}');
|
handle.writeLine('${pid}');
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.close();
|
handle.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,17 @@ using tink.CoreApi;
|
|||||||
|
|
||||||
class Net extends CLIAppBase {
|
class Net extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("route", (args)->{
|
registerSyncSubcommand("route", (args) -> {
|
||||||
var routes = Routing.getRouteTable();
|
var routes = Routing.getRouteTable();
|
||||||
|
|
||||||
for(k => v in routes) {
|
for (k => v in routes) {
|
||||||
handle.writeLine('${k} => ${v.interf.name()}(${v.cost})');
|
handle.writeLine('${k} => ${v.interf.name()}(${v.cost})');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("iface", (args)->{
|
registerSyncSubcommand("iface", (args) -> {
|
||||||
var modems = Peripheral.getAllModems();
|
var modems = Peripheral.getAllModems();
|
||||||
|
|
||||||
for (modem in modems) {
|
for (modem in modems) {
|
||||||
@ -28,7 +28,7 @@ class Net extends CLIAppBase {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("proto",(args)->{
|
registerSyncSubcommand("proto", (args) -> {
|
||||||
var protos = kernel.net.Net.getActiveProtocols();
|
var protos = kernel.net.Net.getActiveProtocols();
|
||||||
|
|
||||||
for (proto in protos) {
|
for (proto in protos) {
|
||||||
@ -38,20 +38,20 @@ class Net extends CLIAppBase {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerAsyncSubcommand("ping",(args)->{
|
registerAsyncSubcommand("ping", (args) -> {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return Future.sync(false);
|
return Future.sync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var toID:Null<Int> = Std.parseInt(args[0]);
|
var toID:Null<Int> = Std.parseInt(args[0]);
|
||||||
|
|
||||||
if (toID == null) {
|
if (toID == null) {
|
||||||
handle.write("Invalid ID");
|
handle.write("Invalid ID");
|
||||||
return Future.sync(false);
|
return Future.sync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return kernel.net.Net.ping(toID).map(result -> {
|
return kernel.net.Net.ping(toID).map(result -> {
|
||||||
switch (result){
|
switch (result) {
|
||||||
case Success(_):
|
case Success(_):
|
||||||
handle.write("Ping succeeded");
|
handle.write("Ping succeeded");
|
||||||
case Failure(failure):
|
case Failure(failure):
|
||||||
@ -60,6 +60,6 @@ class Net extends CLIAppBase {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
},"<id>");
|
}, "<id>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,35 +4,36 @@ import kernel.peripherals.Peripherals.Peripheral;
|
|||||||
import lib.CLIAppBase;
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
class Perf extends CLIAppBase {
|
class Perf extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("inspect",(args)->{
|
registerSyncSubcommand("inspect", (args) -> {
|
||||||
if (args.length < 1) return false;
|
if (args.length < 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
var result = Peripheral.inspect(args[0]);
|
var result = Peripheral.inspect(args[0]);
|
||||||
|
|
||||||
if (result == null){
|
if (result == null) {
|
||||||
handle.writeLine("No peripheral found on side "+args[0]);
|
handle.writeLine("No peripheral found on side " + args[0]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.writeLine("Types:");
|
handle.writeLine("Types:");
|
||||||
for (type in result.types){
|
for (type in result.types) {
|
||||||
handle.writeLine(" "+type);
|
handle.writeLine(" " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.writeLine("Methods:");
|
handle.writeLine("Methods:");
|
||||||
for (method in result.methods){
|
for (method in result.methods) {
|
||||||
handle.writeLine(" "+method);
|
handle.writeLine(" " + method);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},"<side>");
|
}, "<side>");
|
||||||
|
|
||||||
registerSyncSubcommand("list",(args)->{
|
registerSyncSubcommand("list", (args) -> {
|
||||||
for (addr in Peripheral.getAllAddresses()){
|
for (addr in Peripheral.getAllAddresses()) {
|
||||||
handle.writeLine('$addr => ${Peripheral.getTypes(addr).join(", ")}');
|
handle.writeLine('$addr => ${Peripheral.getTypes(addr).join(", ")}');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,22 @@ import kernel.peripherals.Peripherals.Peripheral;
|
|||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Redstone extends CLIAppBase{
|
class Redstone extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("on", (args)-> {
|
registerSyncSubcommand("on", (args) -> {
|
||||||
Peripheral.getRedstone(args[0]).setOutput(true);
|
Peripheral.getRedstone(args[0]).setOutput(true);
|
||||||
return true;
|
return true;
|
||||||
},"<side>");
|
}, "<side>");
|
||||||
|
|
||||||
registerSyncSubcommand("off", (args)-> {
|
registerSyncSubcommand("off", (args) -> {
|
||||||
Peripheral.getRedstone(args[0]).setOutput(false);
|
Peripheral.getRedstone(args[0]).setOutput(false);
|
||||||
return true;
|
return true;
|
||||||
},"<side>");
|
}, "<side>");
|
||||||
|
|
||||||
registerSyncSubcommand("get", (args)-> {
|
registerSyncSubcommand("get", (args) -> {
|
||||||
var value = Peripheral.getRedstone(args[0]).getAnalogInput();
|
var value = Peripheral.getRedstone(args[0]).getAnalogInput();
|
||||||
handle.write("Analog input: " + value);
|
handle.write("Analog input: " + value);
|
||||||
return true;
|
return true;
|
||||||
},"<side>");
|
}, "<side>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,81 +6,80 @@ import lib.CLIAppBase;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Service extends CLIAppBase {
|
class Service extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("start", (args) ->{
|
registerSyncSubcommand("start", (args) -> {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = args[0];
|
var name = args[0];
|
||||||
|
|
||||||
var result = ServiceManager.start(name);
|
var result = ServiceManager.start(name);
|
||||||
return handleResult(result);
|
return handleResult(result);
|
||||||
},"<name>");
|
}, "<name>");
|
||||||
|
|
||||||
registerSyncSubcommand("stop", (args) ->{
|
registerSyncSubcommand("stop", (args) -> {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = args[0];
|
var name = args[0];
|
||||||
|
|
||||||
var result = ServiceManager.stop(name);
|
var result = ServiceManager.stop(name);
|
||||||
return handleResult(result);
|
return handleResult(result);
|
||||||
},"<name>");
|
}, "<name>");
|
||||||
|
|
||||||
registerSyncSubcommand("register", (args) ->{
|
registerSyncSubcommand("register", (args) -> {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = args[0];
|
var name = args[0];
|
||||||
var binName = args[1];
|
var binName = args[1];
|
||||||
var rest = args.slice(2);
|
var rest = args.slice(2);
|
||||||
|
|
||||||
var result = ServiceManager.register(name, binName, rest);
|
var result = ServiceManager.register(name, binName, rest);
|
||||||
return handleResult(result);
|
return handleResult(result);
|
||||||
},"<name> <binary> [args...]");
|
}, "<name> <binary> [args...]");
|
||||||
|
|
||||||
registerSyncSubcommand("unregister", (args) ->{
|
registerSyncSubcommand("unregister", (args) -> {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = args[0];
|
var name = args[0];
|
||||||
|
|
||||||
var result = ServiceManager.unregister(name);
|
var result = ServiceManager.unregister(name);
|
||||||
return handleResult(result);
|
return handleResult(result);
|
||||||
},"<name>");
|
}, "<name>");
|
||||||
|
|
||||||
registerSyncSubcommand("list", (args) ->{
|
registerSyncSubcommand("list", (args) -> {
|
||||||
|
var list = ServiceManager.listRunning();
|
||||||
var list = ServiceManager.listRunning();
|
|
||||||
|
|
||||||
for (name in list) {
|
|
||||||
this.handle.writeLine(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
for (name in list) {
|
||||||
});
|
this.handle.writeLine(name);
|
||||||
|
}
|
||||||
|
|
||||||
registerSyncSubcommand("enable", (args) ->{
|
return true;
|
||||||
if (args.length < 1) {
|
});
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceManager.enable(args[0]);
|
registerSyncSubcommand("enable", (args) -> {
|
||||||
return true;
|
if (args.length < 1) {
|
||||||
},"<name>");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleResult(res: Outcome<Noise,String>): Bool {
|
ServiceManager.enable(args[0]);
|
||||||
switch (res) {
|
return true;
|
||||||
case Success(_):
|
}, "<name>");
|
||||||
return true;
|
}
|
||||||
case Failure(e):
|
|
||||||
this.handle.write(e);
|
private function handleResult(res:Outcome<Noise, String>):Bool {
|
||||||
return false;
|
switch (res) {
|
||||||
}
|
case Success(_):
|
||||||
}
|
return true;
|
||||||
}
|
case Failure(e):
|
||||||
|
this.handle.write(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,18 +15,18 @@ class Terminal implements Process {
|
|||||||
private var handle:ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
private var ctx:WindowContext;
|
private var ctx:WindowContext;
|
||||||
private var requestRender: () -> Void;
|
private var requestRender:() -> Void;
|
||||||
|
|
||||||
private var input:String = "";
|
private var input:String = "";
|
||||||
private var backlog:Array<String> = [];
|
private var backlog:Array<String> = [];
|
||||||
private var history:Array<String> = [];
|
private var history:Array<String> = [];
|
||||||
private var historyIndex:Int = 0;
|
private var historyIndex:Int = 0;
|
||||||
|
|
||||||
private var runningPID:PID = -1;
|
private var runningPID:PID = -1;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle: ProcessHandle): Void {
|
public function run(handle:ProcessHandle):Void {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var statelessContext = handle.createStatelessWindowContext();
|
var statelessContext = handle.createStatelessWindowContext();
|
||||||
@ -38,7 +38,8 @@ class Terminal implements Process {
|
|||||||
|
|
||||||
// Add input event handlers
|
// Add input event handlers
|
||||||
handle.addCallbackLink(this.ctx.onChar.handle(char -> {
|
handle.addCallbackLink(this.ctx.onChar.handle(char -> {
|
||||||
if (this.runningPID > 0) return;
|
if (this.runningPID > 0)
|
||||||
|
return;
|
||||||
this.input += char;
|
this.input += char;
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
}));
|
}));
|
||||||
@ -47,11 +48,13 @@ class Terminal implements Process {
|
|||||||
handle.addCallbackLink(this.ctx.onKey.handle(e -> {
|
handle.addCallbackLink(this.ctx.onKey.handle(e -> {
|
||||||
switch (e.keyCode) {
|
switch (e.keyCode) {
|
||||||
case 259: // Backspace
|
case 259: // Backspace
|
||||||
if (this.runningPID > 0) return;
|
if (this.runningPID > 0)
|
||||||
|
return;
|
||||||
this.input = this.input.substr(0, this.input.length - 1);
|
this.input = this.input.substr(0, this.input.length - 1);
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
case 257: // Enter
|
case 257: // Enter
|
||||||
if (this.runningPID > 0) return;
|
if (this.runningPID > 0)
|
||||||
|
return;
|
||||||
this.backlog.push("> " + this.input);
|
this.backlog.push("> " + this.input);
|
||||||
var command = this.input;
|
var command = this.input;
|
||||||
this.input = "";
|
this.input = "";
|
||||||
@ -145,7 +148,7 @@ class Terminal implements Process {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.runningPID = ProcessManager.run(ps,{
|
this.runningPID = ProcessManager.run(ps, {
|
||||||
args: commandArgs,
|
args: commandArgs,
|
||||||
onWrite: (s:String) -> {
|
onWrite: (s:String) -> {
|
||||||
if (s == "") {
|
if (s == "") {
|
||||||
@ -159,7 +162,7 @@ class Terminal implements Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (line in s.split("\n")) {
|
for (line in s.split("\n")) {
|
||||||
if (line == ""){
|
if (line == "") {
|
||||||
this.backlog.push("");
|
this.backlog.push("");
|
||||||
} else {
|
} else {
|
||||||
this.backlog[this.backlog.length - 1] += s;
|
this.backlog[this.backlog.length - 1] += s;
|
||||||
@ -170,7 +173,7 @@ class Terminal implements Process {
|
|||||||
this.backlog.shift();
|
this.backlog.shift();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
},
|
},
|
||||||
onExit: (success:Bool) -> {
|
onExit: (success:Bool) -> {
|
||||||
@ -205,7 +208,7 @@ class Terminal implements Process {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Type.createInstance(bin.c,[]);
|
return Type.createInstance(bin.c, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function moveCursorToInput() {
|
private function moveCursorToInput() {
|
||||||
|
@ -6,32 +6,32 @@ using tink.CoreApi;
|
|||||||
|
|
||||||
class Turtle extends CLIAppBase {
|
class Turtle extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("forward", (args)->{
|
registerSyncSubcommand("forward", (args) -> {
|
||||||
return perform(kernel.turtle.Turtle.instance.forward());
|
return perform(kernel.turtle.Turtle.instance.forward());
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("back", (args)->{
|
registerSyncSubcommand("back", (args) -> {
|
||||||
return perform(kernel.turtle.Turtle.instance.back());
|
return perform(kernel.turtle.Turtle.instance.back());
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("left", (args)->{
|
registerSyncSubcommand("left", (args) -> {
|
||||||
return perform(kernel.turtle.Turtle.instance.turnLeft());
|
return perform(kernel.turtle.Turtle.instance.turnLeft());
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("right", (args)->{
|
registerSyncSubcommand("right", (args) -> {
|
||||||
return perform(kernel.turtle.Turtle.instance.turnRight());
|
return perform(kernel.turtle.Turtle.instance.turnRight());
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("up", (args)->{
|
registerSyncSubcommand("up", (args) -> {
|
||||||
return perform(kernel.turtle.Turtle.instance.up());
|
return perform(kernel.turtle.Turtle.instance.up());
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("down", (args)->{
|
registerSyncSubcommand("down", (args) -> {
|
||||||
return perform(kernel.turtle.Turtle.instance.down());
|
return perform(kernel.turtle.Turtle.instance.down());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function perform(outcome: Outcome<Noise,String>): Bool {
|
private function perform(outcome:Outcome<Noise, String>):Bool {
|
||||||
switch outcome {
|
switch outcome {
|
||||||
case Success(_):
|
case Success(_):
|
||||||
return true;
|
return true;
|
||||||
@ -40,5 +40,4 @@ class Turtle extends CLIAppBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,51 +8,51 @@ import lib.exporter.Import;
|
|||||||
import lib.CLIAppBase;
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
class Res extends CLIAppBase {
|
class Res extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerAsyncSubcommand("get", (args)->{
|
registerAsyncSubcommand("get", (args) -> {
|
||||||
var url = args[0];
|
var url = args[0];
|
||||||
|
|
||||||
return Import.get(url).map((res)->{
|
return Import.get(url).map((res) -> {
|
||||||
switch (res){
|
switch (res) {
|
||||||
case Success(data):
|
case Success(data):
|
||||||
handle.writeLine(Std.string(data));
|
handle.writeLine(Std.string(data));
|
||||||
case Failure(err):
|
case Failure(err):
|
||||||
handle.writeLine("Error: ");
|
handle.writeLine("Error: ");
|
||||||
handle.writeLine(Std.string(err));
|
handle.writeLine(Std.string(err));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
},"<url>");
|
}, "<url>");
|
||||||
|
|
||||||
registerAsyncSubcommand("register",(args)->{
|
registerAsyncSubcommand("register", (args) -> {
|
||||||
var srv: Null<ResManager> = ServiceManager.get("resmgr");
|
var srv:Null<ResManager> = ServiceManager.get("resmgr");
|
||||||
|
|
||||||
var addr = args[0];
|
var addr = args[0];
|
||||||
var name = args[1];
|
var name = args[1];
|
||||||
|
|
||||||
if (srv == null) {
|
if (srv == null) {
|
||||||
handle.writeLine("Error: resmgr not found");
|
handle.writeLine("Error: resmgr not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var perf: kernel.peripherals.Redstone = Peripheral.getRedstone(addr);
|
var perf:kernel.peripherals.Redstone = Peripheral.getRedstone(addr);
|
||||||
|
|
||||||
if (perf == null) {
|
if (perf == null) {
|
||||||
handle.writeLine("Error: peripheral not found");
|
handle.writeLine("Error: peripheral not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return srv.register(name,new Export(perf)).map((res)->{
|
return srv.register(name, new Export(perf)).map((res) -> {
|
||||||
switch (res){
|
switch (res) {
|
||||||
case Success(_):
|
case Success(_):
|
||||||
handle.writeLine("Success");
|
handle.writeLine("Success");
|
||||||
return true;
|
return true;
|
||||||
case Failure(err):
|
case Failure(err):
|
||||||
handle.writeLine("Error: ");
|
handle.writeLine("Error: ");
|
||||||
handle.writeLine(Std.string(err));
|
handle.writeLine(Std.string(err));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},"<addr> <name>");
|
}, "<addr> <name>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,78 +14,76 @@ import kernel.net.Package.GenericPackage;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class ResManager implements Process {
|
class ResManager implements Process {
|
||||||
private var handle:ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
private var exports:Map<String,Export> = [];
|
private var exports:Map<String, Export> = [];
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
Net.registerProto("res",handlePackage);
|
Net.registerProto("res", handlePackage);
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(id: String, export: Export): Promise<Noise>{
|
public function register(id:String, export:Export):Promise<Noise> {
|
||||||
if (exports.exists(id)){
|
if (exports.exists(id)) {
|
||||||
return Promise.reject(new Error("Ressource already exists: " + id));
|
return Promise.reject(new Error("Ressource already exists: " + id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return registerName(id).next((success)->{
|
return registerName(id).next((success) -> {
|
||||||
exports.set(id,export);
|
exports.set(id, export);
|
||||||
persist();
|
persist();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handlePackage(pack: GenericPackage){
|
private function handlePackage(pack:GenericPackage) {
|
||||||
var requestPack: Package<Request> = cast pack;
|
var requestPack:Package<Request> = cast pack;
|
||||||
var id = requestPack.data.id;
|
var id = requestPack.data.id;
|
||||||
|
|
||||||
if (!exports.exists(id)){
|
if (!exports.exists(id)) {
|
||||||
requestPack.respond(lib.exporter.Response.NotFound);
|
requestPack.respond(lib.exporter.Response.NotFound);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var export = exports.get(id);
|
var export = exports.get(id);
|
||||||
var response = export.handleRequest(requestPack.data);
|
var response = export.handleRequest(requestPack.data);
|
||||||
|
|
||||||
requestPack.respond(response);
|
requestPack.respond(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerName(id: String){
|
private function registerName(id:String) {
|
||||||
return RessourceNames.register(id, Net.networkID);
|
return RessourceNames.register(id, Net.networkID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function persist(){
|
private function persist() {
|
||||||
var store = new KVStore("export");
|
var store = new KVStore("export");
|
||||||
|
|
||||||
var saveExports: Array<{name: String, addr: String, type: String}> =
|
var saveExports:Array<{name:String, addr:String, type:String}> = [for (k => v in this.exports) {name: k, addr: v.getAddr(), type: v.getType()}];
|
||||||
[for (k => v in this.exports) {name: k, addr: v.getAddr(), type: v.getType()}];
|
|
||||||
|
|
||||||
store.set("exports",saveExports);
|
store.set("exports", saveExports);
|
||||||
|
|
||||||
store.save();
|
store.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function load(){
|
private function load() {
|
||||||
var store = new KVStore("export");
|
var store = new KVStore("export");
|
||||||
|
|
||||||
var savedExports: Array<{name: String, addr: String, type: String}> = store.get("exports",[]);
|
var savedExports:Array<{name:String, addr:String, type:String}> = store.get("exports", []);
|
||||||
|
|
||||||
for (export in savedExports){
|
for (export in savedExports) {
|
||||||
var perph = Peripheral.getFromType(export.addr,export.type);
|
var perph = Peripheral.getFromType(export.addr, export.type);
|
||||||
|
|
||||||
if (perph == null){
|
if (perph == null) {
|
||||||
handle.writeLine('Could not load export: ${export.name} on ${export.addr}');
|
handle.writeLine('Could not load export: ${export.name} on ${export.addr}');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// I dont know if cast is the best way to do this
|
// I dont know if cast is the best way to do this
|
||||||
// But since we know that this is a IExportable we can do this (I think)
|
// But since we know that this is a IExportable we can do this (I think)
|
||||||
exports.set(export.name, new Export(cast perph));
|
exports.set(export.name, new Export(cast perph));
|
||||||
|
|
||||||
handle.writeLine('Loaded export: ${export.name} on ${export.addr}');
|
handle.writeLine('Loaded export: ${export.name} on ${export.addr}');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,46 +9,51 @@ import kernel.ps.ProcessHandle;
|
|||||||
import kernel.ps.Process;
|
import kernel.ps.Process;
|
||||||
|
|
||||||
class PFClient implements Process {
|
class PFClient implements Process {
|
||||||
private var handle:ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
private var ctx: WindowContext;
|
private var ctx:WindowContext;
|
||||||
private var requestRender:Void -> Void;
|
private var requestRender:Void->Void;
|
||||||
private var root:RootElement;
|
private var root:RootElement;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var stateless = handle.createStatelessWindowContext();
|
var stateless = handle.createStatelessWindowContext();
|
||||||
this.ctx = stateless.ctx;
|
this.ctx = stateless.ctx;
|
||||||
this.requestRender = stateless.requestRender;
|
this.requestRender = stateless.requestRender;
|
||||||
|
|
||||||
stateless.setRenderFunc(this.render);
|
stateless.setRenderFunc(this.render);
|
||||||
|
|
||||||
this.root = new RootElement();
|
this.root = new RootElement();
|
||||||
this.root.setTitle("Pathfinder");
|
this.root.setTitle("Pathfinder");
|
||||||
|
|
||||||
this.ctx.delegateEvents(this.root);
|
this.ctx.delegateEvents(this.root);
|
||||||
|
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function render() {
|
private function render() {
|
||||||
var acc = kernel.gps.GPS.getAccuracy();
|
var acc = kernel.gps.GPS.getAccuracy();
|
||||||
var pos: Pos3 = kernel.gps.GPS.getPosition() ?? {x: 0, y: 0, z: 0};
|
var pos:Pos3 = kernel.gps.GPS.getPosition() ?? {x: 0, y: 0, z: 0};
|
||||||
|
|
||||||
var childre: Array<UIElement> = [
|
var childre:Array<UIElement> = [
|
||||||
new TextElement('Acc: ${acc}'),
|
new TextElement('Acc: ${acc}'),
|
||||||
new TextElement('Pos: X:${pos.x} Y:${pos.y} Z:${pos.z}'),
|
new TextElement('Pos: X:${pos.x} Y:${pos.y} Z:${pos.z}'),
|
||||||
new TextElement('UPDATE', { style: {bgColor: Gray}, uiEvents: {onClick: () -> {
|
new TextElement('UPDATE', {
|
||||||
kernel.gps.GPS.locate().handle((pos) ->{
|
style: {bgColor: Gray},
|
||||||
this.requestRender();
|
uiEvents: {
|
||||||
});
|
onClick: () -> {
|
||||||
}}}),
|
kernel.gps.GPS.locate().handle((pos) -> {
|
||||||
];
|
this.requestRender();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
this.root.setChildren(childre);
|
this.root.setChildren(childre);
|
||||||
this.root.render(ctx.getSize()).renderToContext(ctx);
|
this.root.render(ctx.getSize()).renderToContext(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,8 @@ class SiteRessourceController implements Process {
|
|||||||
return ressources.get(name);
|
return ressources.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function list():Array<String> {
|
private inline function list():Array<String> {
|
||||||
return [ for (k in ressources.keys()) k];
|
return [for (k in ressources.keys()) k];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function load() {
|
private function load() {
|
||||||
|
@ -2,8 +2,8 @@ package kernel;
|
|||||||
|
|
||||||
@:keep
|
@:keep
|
||||||
class DCEHack {
|
class DCEHack {
|
||||||
// Dont actually call this
|
// Dont actually call this
|
||||||
public static function load():Array<kernel.ps.Process>{
|
public static function load():Array<kernel.ps.Process> {
|
||||||
macros.DCEHack.dceGenerateCreate();
|
macros.DCEHack.dceGenerateCreate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,22 +3,26 @@ package kernel;
|
|||||||
import cc.OS;
|
import cc.OS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Make sure that a function is called at the end of the current event loop.
|
Make sure that a function is called at the end of the current event loop.
|
||||||
Like setTimeout(func, 0) in JavaScript.
|
Like setTimeout(func, 0) in JavaScript.
|
||||||
**/
|
**/
|
||||||
class EndOfLoop {
|
class EndOfLoop {
|
||||||
private static var backlog:Array<Void -> Void> = [];
|
private static var backlog:Array<Void->Void> = [];
|
||||||
private static var isQueued = false;
|
private static var isQueued = false;
|
||||||
|
|
||||||
public static function endOfLoop(func: Void -> Void) {
|
public static function endOfLoop(func:Void->Void) {
|
||||||
backlog.push(func);
|
backlog.push(func);
|
||||||
if (!isQueued) { OS.queueEvent("endofloop", null); }
|
if (!isQueued) {
|
||||||
}
|
OS.queueEvent("endofloop", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@:allow(kernel.KernelEvents)
|
@:allow(kernel.KernelEvents)
|
||||||
private static function run() {
|
private static function run() {
|
||||||
for (func in backlog) { func(); }
|
for (func in backlog) {
|
||||||
backlog = [];
|
func();
|
||||||
isQueued = false;
|
}
|
||||||
}
|
backlog = [];
|
||||||
|
isQueued = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@ class Entrypoint {
|
|||||||
public static function main() {
|
public static function main() {
|
||||||
try {
|
try {
|
||||||
Init.initKernel();
|
Init.initKernel();
|
||||||
}catch(e){
|
} catch (e) {
|
||||||
Log.error('Error in init: ${e.toString()}');
|
Log.error('Error in init: ${e.toString()}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Startup.main();
|
Startup.main();
|
||||||
}catch(e){
|
} catch (e) {
|
||||||
Log.error('Error in startup: ${e.toString()}');
|
Log.error('Error in startup: ${e.toString()}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,9 @@ import lib.Debug;
|
|||||||
import kernel.ui.WindowManager;
|
import kernel.ui.WindowManager;
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
import kernel.net.Net;
|
import kernel.net.Net;
|
||||||
|
|
||||||
import kernel.DCEHack; // Important for DCE hack
|
import kernel.DCEHack; // Important for DCE hack
|
||||||
|
|
||||||
class Init {
|
class Init {
|
||||||
|
|
||||||
@:allow(kernel.KernelEvents)
|
@:allow(kernel.KernelEvents)
|
||||||
private static var mainEvent:MainEvent;
|
private static var mainEvent:MainEvent;
|
||||||
|
|
||||||
@ -30,7 +28,7 @@ class Init {
|
|||||||
WindowManager.init();
|
WindowManager.init();
|
||||||
MainTerm.instance = new MainTerm();
|
MainTerm.instance = new MainTerm();
|
||||||
|
|
||||||
if (Turtle.isTurtle()){
|
if (Turtle.isTurtle()) {
|
||||||
Turtle.instance = new Turtle();
|
Turtle.instance = new Turtle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +38,7 @@ class Init {
|
|||||||
GPS.init();
|
GPS.init();
|
||||||
|
|
||||||
// Register default terminate handler
|
// Register default terminate handler
|
||||||
KernelEvents.onTerminate.handle(_->{
|
KernelEvents.onTerminate.handle(_ -> {
|
||||||
KernelEvents.shutdown();
|
KernelEvents.shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ class Init {
|
|||||||
FS.makeDir("/var/ns");
|
FS.makeDir("/var/ns");
|
||||||
}
|
}
|
||||||
|
|
||||||
Init.mainEvent = MainLoop.add(()->{
|
Init.mainEvent = MainLoop.add(() -> {
|
||||||
KernelEvents.startEventLoop();
|
KernelEvents.startEventLoop();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ class KernelEvents {
|
|||||||
Depends on: (Nothing)
|
Depends on: (Nothing)
|
||||||
**/
|
**/
|
||||||
public static var onAlarm(default, null):Signal<Int>;
|
public static var onAlarm(default, null):Signal<Int>;
|
||||||
|
|
||||||
public static var onChar(default, null):Signal<String>;
|
public static var onChar(default, null):Signal<String>;
|
||||||
public static var onDisk(default, null):Signal<String>;
|
public static var onDisk(default, null):Signal<String>;
|
||||||
public static var onDiskEject(default, null):Signal<String>;
|
public static var onDiskEject(default, null):Signal<String>;
|
||||||
@ -93,10 +94,10 @@ class KernelEvents {
|
|||||||
private static final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger();
|
private static final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger();
|
||||||
private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
||||||
|
|
||||||
private static var stopLoop:Bool = false;
|
private static var stopLoop:Bool = false;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
onAlarm = onAlarmTrigger.asSignal();
|
onAlarm = onAlarmTrigger.asSignal();
|
||||||
onChar = onCharTrigger.asSignal();
|
onChar = onCharTrigger.asSignal();
|
||||||
onDisk = onDiskTrigger.asSignal();
|
onDisk = onDiskTrigger.asSignal();
|
||||||
@ -133,21 +134,20 @@ class KernelEvents {
|
|||||||
Start pulling events. Blocking.
|
Start pulling events. Blocking.
|
||||||
**/
|
**/
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function startEventLoop() {
|
private static function startEventLoop() {
|
||||||
while (!stopLoop) {
|
while (!stopLoop) {
|
||||||
var event:Table<Int, Dynamic> = pullEvents();
|
var event:Table<Int, Dynamic> = pullEvents();
|
||||||
|
|
||||||
var eventName:String = event[1];
|
var eventName:String = event[1];
|
||||||
try {
|
try {
|
||||||
fireSignal(eventName,event);
|
fireSignal(eventName, event);
|
||||||
}catch(e:Dynamic) {
|
} catch (e:Dynamic) {
|
||||||
Log.error('Error while handling event: $eventName: ${e}');
|
Log.error('Error while handling event: $eventName: ${e}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function shutdown() {
|
public static function shutdown() {
|
||||||
|
|
||||||
// clearing screens
|
// clearing screens
|
||||||
for (screen in Peripheral.getAllScreens()) {
|
for (screen in Peripheral.getAllScreens()) {
|
||||||
screen.reset();
|
screen.reset();
|
||||||
@ -159,11 +159,11 @@ class KernelEvents {
|
|||||||
Init.mainEvent.stop();
|
Init.mainEvent.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function pullEvents():Table<Int, Dynamic> {
|
private static function pullEvents():Table<Int, Dynamic> {
|
||||||
return cast TableTools.pack(Coroutine.yield(null));
|
return cast TableTools.pack(Coroutine.yield(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function fireSignal(eventName: String,event:Table<Int, Dynamic> ) {
|
private static function fireSignal(eventName:String, event:Table<Int, Dynamic>) {
|
||||||
switch eventName {
|
switch eventName {
|
||||||
case "alarm":
|
case "alarm":
|
||||||
onAlarmTrigger.trigger(event[2]);
|
onAlarmTrigger.trigger(event[2]);
|
||||||
@ -252,36 +252,66 @@ class KernelEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:allow(lib.Debug)
|
@:allow(lib.Debug)
|
||||||
private static function printListenerCount() {
|
private static function printListenerCount() {
|
||||||
if (onAlarmTrigger.getLength() > 0) Log.debug("onAlarm: " + onAlarmTrigger.getLength());
|
if (onAlarmTrigger.getLength() > 0)
|
||||||
if (onCharTrigger.getLength() > 0) Log.debug("onChar: " + onCharTrigger.getLength());
|
Log.debug("onAlarm: " + onAlarmTrigger.getLength());
|
||||||
if (onDiskTrigger.getLength() > 0) Log.debug("onDisk: " + onDiskTrigger.getLength());
|
if (onCharTrigger.getLength() > 0)
|
||||||
if (onDiskEjectTrigger.getLength() > 0) Log.debug("onDiskEject: " + onDiskEjectTrigger.getLength());
|
Log.debug("onChar: " + onCharTrigger.getLength());
|
||||||
if (onHttpCheckTrigger.getLength() > 0) Log.debug("onHttpCheck: " + onHttpCheckTrigger.getLength());
|
if (onDiskTrigger.getLength() > 0)
|
||||||
if (onHttpFailureTrigger.getLength() > 0) Log.debug("onHttpFailure: " + onHttpFailureTrigger.getLength());
|
Log.debug("onDisk: " + onDiskTrigger.getLength());
|
||||||
if (onHttpSuccessTrigger.getLength() > 0) Log.debug("onHttpSuccess: " + onHttpSuccessTrigger.getLength());
|
if (onDiskEjectTrigger.getLength() > 0)
|
||||||
if (onKeyTrigger.getLength() > 0) Log.debug("onKey: " + onKeyTrigger.getLength());
|
Log.debug("onDiskEject: " + onDiskEjectTrigger.getLength());
|
||||||
if (onKeyUpTrigger.getLength() > 0) Log.debug("onKeyUp: " + onKeyUpTrigger.getLength());
|
if (onHttpCheckTrigger.getLength() > 0)
|
||||||
if (onModemMessageTrigger.getLength() > 0) Log.debug("onModemMessage: " + onModemMessageTrigger.getLength());
|
Log.debug("onHttpCheck: " + onHttpCheckTrigger.getLength());
|
||||||
if (onMonitorResizeTrigger.getLength() > 0) Log.debug("onMonitorResize: " + onMonitorResizeTrigger.getLength());
|
if (onHttpFailureTrigger.getLength() > 0)
|
||||||
if (onMonitorTouchTrigger.getLength() > 0) Log.debug("onMonitorTouch: " + onMonitorTouchTrigger.getLength());
|
Log.debug("onHttpFailure: " + onHttpFailureTrigger.getLength());
|
||||||
if (onMouseClickTrigger.getLength() > 0) Log.debug("onMouseClick: " + onMouseClickTrigger.getLength());
|
if (onHttpSuccessTrigger.getLength() > 0)
|
||||||
if (onMouseDragTrigger.getLength() > 0) Log.debug("onMouseDrag: " + onMouseDragTrigger.getLength());
|
Log.debug("onHttpSuccess: " + onHttpSuccessTrigger.getLength());
|
||||||
if (onMouseScrollTrigger.getLength() > 0) Log.debug("onMouseScroll: " + onMouseScrollTrigger.getLength());
|
if (onKeyTrigger.getLength() > 0)
|
||||||
if (onMouseUpTrigger.getLength() > 0) Log.debug("onMouseUp: " + onMouseUpTrigger.getLength());
|
Log.debug("onKey: " + onKeyTrigger.getLength());
|
||||||
if (onPasteTrigger.getLength() > 0) Log.debug("onPaste: " + onPasteTrigger.getLength());
|
if (onKeyUpTrigger.getLength() > 0)
|
||||||
if (onPeripheralTrigger.getLength() > 0) Log.debug("onPeripheral: " + onPeripheralTrigger.getLength());
|
Log.debug("onKeyUp: " + onKeyUpTrigger.getLength());
|
||||||
if (onPeripheralDetachTrigger.getLength() > 0) Log.debug("onPeripheralDetach: " + onPeripheralDetachTrigger.getLength());
|
if (onModemMessageTrigger.getLength() > 0)
|
||||||
if (onRedstoneTrigger.getLength() > 0) Log.debug("onRedstone: " + onRedstoneTrigger.getLength());
|
Log.debug("onModemMessage: " + onModemMessageTrigger.getLength());
|
||||||
if (onSpeakerAudioEmptyTrigger.getLength() > 0) Log.debug("onSpeakerAudioEmpty: " + onSpeakerAudioEmptyTrigger.getLength());
|
if (onMonitorResizeTrigger.getLength() > 0)
|
||||||
if (onTaskCompleteTrigger.getLength() > 0) Log.debug("onTaskComplete: " + onTaskCompleteTrigger.getLength());
|
Log.debug("onMonitorResize: " + onMonitorResizeTrigger.getLength());
|
||||||
if (onTermResizeTrigger.getLength() > 0) Log.debug("onTermResize: " + onTermResizeTrigger.getLength());
|
if (onMonitorTouchTrigger.getLength() > 0)
|
||||||
if (onTerminateTrigger.getLength() > 0) Log.debug("onTerminate: " + onTerminateTrigger.getLength());
|
Log.debug("onMonitorTouch: " + onMonitorTouchTrigger.getLength());
|
||||||
if (onTimerTrigger.getLength() > 0) Log.debug("onTimer: " + onTimerTrigger.getLength());
|
if (onMouseClickTrigger.getLength() > 0)
|
||||||
if (onTurtleInventoryTrigger.getLength() > 0) Log.debug("onTurtleInventory: " + onTurtleInventoryTrigger.getLength());
|
Log.debug("onMouseClick: " + onMouseClickTrigger.getLength());
|
||||||
if (onWebsocketCloseTrigger.getLength() > 0) Log.debug("onWebsocketClose: " + onWebsocketCloseTrigger.getLength());
|
if (onMouseDragTrigger.getLength() > 0)
|
||||||
if (onWebsocketFailureTrigger.getLength() > 0) Log.debug("onWebsocketFailure: " + onWebsocketFailureTrigger.getLength());
|
Log.debug("onMouseDrag: " + onMouseDragTrigger.getLength());
|
||||||
if (onWebsocketMessageTrigger.getLength() > 0) Log.debug("onWebsocketMessage: " + onWebsocketMessageTrigger.getLength());
|
if (onMouseScrollTrigger.getLength() > 0)
|
||||||
if (onWebsocketSuccessTrigger.getLength() > 0) Log.debug("onWebsocketSuccess: " + onWebsocketSuccessTrigger.getLength());
|
Log.debug("onMouseScroll: " + onMouseScrollTrigger.getLength());
|
||||||
|
if (onMouseUpTrigger.getLength() > 0)
|
||||||
|
Log.debug("onMouseUp: " + onMouseUpTrigger.getLength());
|
||||||
|
if (onPasteTrigger.getLength() > 0)
|
||||||
|
Log.debug("onPaste: " + onPasteTrigger.getLength());
|
||||||
|
if (onPeripheralTrigger.getLength() > 0)
|
||||||
|
Log.debug("onPeripheral: " + onPeripheralTrigger.getLength());
|
||||||
|
if (onPeripheralDetachTrigger.getLength() > 0)
|
||||||
|
Log.debug("onPeripheralDetach: " + onPeripheralDetachTrigger.getLength());
|
||||||
|
if (onRedstoneTrigger.getLength() > 0)
|
||||||
|
Log.debug("onRedstone: " + onRedstoneTrigger.getLength());
|
||||||
|
if (onSpeakerAudioEmptyTrigger.getLength() > 0)
|
||||||
|
Log.debug("onSpeakerAudioEmpty: " + onSpeakerAudioEmptyTrigger.getLength());
|
||||||
|
if (onTaskCompleteTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTaskComplete: " + onTaskCompleteTrigger.getLength());
|
||||||
|
if (onTermResizeTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTermResize: " + onTermResizeTrigger.getLength());
|
||||||
|
if (onTerminateTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTerminate: " + onTerminateTrigger.getLength());
|
||||||
|
if (onTimerTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTimer: " + onTimerTrigger.getLength());
|
||||||
|
if (onTurtleInventoryTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTurtleInventory: " + onTurtleInventoryTrigger.getLength());
|
||||||
|
if (onWebsocketCloseTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketClose: " + onWebsocketCloseTrigger.getLength());
|
||||||
|
if (onWebsocketFailureTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketFailure: " + onWebsocketFailureTrigger.getLength());
|
||||||
|
if (onWebsocketMessageTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketMessage: " + onWebsocketMessageTrigger.getLength());
|
||||||
|
if (onWebsocketSuccessTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketSuccess: " + onWebsocketSuccessTrigger.getLength());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,51 +6,53 @@ import lib.KVStore;
|
|||||||
import cc.Settings;
|
import cc.Settings;
|
||||||
|
|
||||||
class KernelSettings {
|
class KernelSettings {
|
||||||
private static inline function setAllowStartup(value: Bool) {
|
private static inline function setAllowStartup(value:Bool) {
|
||||||
Settings.set("shell.allow_startup", value);
|
Settings.set("shell.allow_startup", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static inline function setAllowStartupFromFloppy(value: Bool) {
|
private static inline function setAllowStartupFromFloppy(value:Bool) {
|
||||||
Settings.set("shell.allow_disk_startup", value);
|
Settings.set("shell.allow_disk_startup", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function set(name: String, value: Dynamic) {
|
private static function set(name:String, value:Dynamic) {
|
||||||
var kvstore = new KVStore("kernel");
|
var kvstore = new KVStore("kernel");
|
||||||
kvstore.set(name, value);
|
kvstore.set(name, value);
|
||||||
kvstore.save();
|
kvstore.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function get(name: String): Null<Dynamic> {
|
private static function get(name:String):Null<Dynamic> {
|
||||||
var kvstore = new KVStore("kernel");
|
var kvstore = new KVStore("kernel");
|
||||||
return kvstore.get(name);
|
return kvstore.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var hostname(get,set): String;
|
public static var hostname(get, set):String;
|
||||||
private static var _hostname:String = get("hostname");
|
private static var _hostname:String = get("hostname");
|
||||||
private static inline function get_hostname():String {
|
|
||||||
|
private static inline function get_hostname():String {
|
||||||
return _hostname;
|
return _hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static inline function set_hostname(value:String):String {
|
private static inline function set_hostname(value:String):String {
|
||||||
OS.setComputerLabel(value);
|
OS.setComputerLabel(value);
|
||||||
set("hostname", value);
|
set("hostname", value);
|
||||||
_hostname = value;
|
_hostname = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var siteController(get,set): NetworkID;
|
public static var siteController(get, set):NetworkID;
|
||||||
private static var _siteController:NetworkID = get("siteController");
|
private static var _siteController:NetworkID = get("siteController");
|
||||||
|
|
||||||
private static function get_siteController():NetworkID {
|
private static function get_siteController():NetworkID {
|
||||||
return _siteController;
|
return _siteController;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function set_siteController(value:NetworkID):NetworkID {
|
private static function set_siteController(value:NetworkID):NetworkID {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return get_siteController();
|
return get_siteController();
|
||||||
}
|
}
|
||||||
|
|
||||||
set("siteController", value);
|
set("siteController", value);
|
||||||
_siteController = value;
|
_siteController = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,6 @@ class MainTerm implements TermWriteable {
|
|||||||
this.setBackgroundColor(Black);
|
this.setBackgroundColor(Black);
|
||||||
this.setTextColor(White);
|
this.setTextColor(White);
|
||||||
this.clear();
|
this.clear();
|
||||||
this.setCursorPos(0,0);
|
this.setCursorPos(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ package kernel.binstore;
|
|||||||
import kernel.ps.Process;
|
import kernel.ps.Process;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Represents a callable program.
|
Represents a callable program.
|
||||||
**/
|
**/
|
||||||
typedef Bin = {
|
typedef Bin = {
|
||||||
c: Class<Process>,
|
c:Class<Process>,
|
||||||
name: String,
|
name:String,
|
||||||
aliases: Array<String>,
|
aliases:Array<String>,
|
||||||
}
|
}
|
||||||
|
@ -22,53 +22,53 @@ import bin.Disk;
|
|||||||
import haxe.ds.ReadOnlyArray;
|
import haxe.ds.ReadOnlyArray;
|
||||||
|
|
||||||
class BinStore {
|
class BinStore {
|
||||||
private static final store:ReadOnlyArray<Bin> = [
|
private static final store:ReadOnlyArray<Bin> = [
|
||||||
{c: Disk, name: "Disk", aliases: ["disk"]},
|
{c: Disk, name: "Disk", aliases: ["disk"]},
|
||||||
{c: GPS, name: "GPS", aliases: ["gps"]},
|
{c: GPS, name: "GPS", aliases: ["gps"]},
|
||||||
{c: HelloWorld, name: "HelloWorld", aliases: ["hello"]},
|
{c: HelloWorld, name: "HelloWorld", aliases: ["hello"]},
|
||||||
{c: KernelLog, name: "KernelLog", aliases: ["log"]},
|
{c: KernelLog, name: "KernelLog", aliases: ["log"]},
|
||||||
{c: Net, name: "Net", aliases: ["net"]},
|
{c: Net, name: "Net", aliases: ["net"]},
|
||||||
{c: Redstone, name: "Redstone", aliases: ["redstone","rs"]},
|
{c: Redstone, name: "Redstone", aliases: ["redstone", "rs"]},
|
||||||
{c: Terminal, name: "Terminal", aliases: ["terminal","term"]},
|
{c: Terminal, name: "Terminal", aliases: ["terminal", "term"]},
|
||||||
{c: Turtle, name: "Turtle", aliases: ["turtle"]},
|
{c: Turtle, name: "Turtle", aliases: ["turtle"]},
|
||||||
{c: LSPS, name: "PM", aliases: ["lsps"]},
|
{c: LSPS, name: "PM", aliases: ["lsps"]},
|
||||||
{c: Service, name: "Service", aliases: ["service","srv"]},
|
{c: Service, name: "Service", aliases: ["service", "srv"]},
|
||||||
{c: HelloWorldService, name: "HelloWorldService", aliases: ["hello-service"] },
|
{c: HelloWorldService, name: "HelloWorldService", aliases: ["hello-service"]},
|
||||||
{c: SiteRessourceController, name: "SiteRessourceController", aliases: ["srsc"]},
|
{c: SiteRessourceController, name: "SiteRessourceController", aliases: ["srsc"]},
|
||||||
{c: CLI, name: "SRSC CLI", aliases: ["srsc-cli"]},
|
{c: CLI, name: "SRSC CLI", aliases: ["srsc-cli"]},
|
||||||
{c: Perf, name: "Perf", aliases: ["perf"]},
|
{c: Perf, name: "Perf", aliases: ["perf"]},
|
||||||
{c: KSettings, name: "KSettings", aliases: ["ksettings","ks"]},
|
{c: KSettings, name: "KSettings", aliases: ["ksettings", "ks"]},
|
||||||
{c: ResManager, name: "ResManager", aliases: ["resmanager","resmgr"]},
|
{c: ResManager, name: "ResManager", aliases: ["resmanager", "resmgr"]},
|
||||||
{c: Res, name: "Res", aliases: ["res"]},
|
{c: Res, name: "Res", aliases: ["res"]},
|
||||||
{c: ID , name: "ID", aliases: ["id"]},
|
{c: ID, name: "ID", aliases: ["id"]},
|
||||||
{c: PFClient, name: "PFClient", aliases: ["pfclient"]}
|
{c: PFClient, name: "PFClient", aliases: ["pfclient"]}
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function getBinByName(name:String):Null<Bin> {
|
public static function getBinByName(name:String):Null<Bin> {
|
||||||
for (bin in store) {
|
for (bin in store) {
|
||||||
if (bin.name == name) {
|
if (bin.name == name) {
|
||||||
return bin;
|
return bin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getBinByAlias(alias:String):Null<Bin> {
|
public static function getBinByAlias(alias:String):Null<Bin> {
|
||||||
for (bin in store) {
|
for (bin in store) {
|
||||||
for (a in bin.aliases) {
|
for (a in bin.aliases) {
|
||||||
if (a == alias) {
|
if (a == alias) {
|
||||||
return bin;
|
return bin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getNameByAlias(alias: String): String {
|
public static function getNameByAlias(alias:String):String {
|
||||||
var bin = getBinByAlias(alias);
|
var bin = getBinByAlias(alias);
|
||||||
if (bin == null) {
|
if (bin == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return bin.name;
|
return bin.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,79 +13,79 @@ using lua.Table;
|
|||||||
Wrapper to interact with the filesystem.
|
Wrapper to interact with the filesystem.
|
||||||
**/
|
**/
|
||||||
class FS {
|
class FS {
|
||||||
public static inline function list(path: String):ReadOnlyArray<String> {
|
public static inline function list(path:String):ReadOnlyArray<String> {
|
||||||
return FileSystem.list(path).toArray();
|
return FileSystem.list(path).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function combine(base: String, part: String): String {
|
public static inline function combine(base:String, part:String):String {
|
||||||
return FileSystem.combine(base,part);
|
return FileSystem.combine(base, part);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function getName(path: String): String {
|
public static inline function getName(path:String):String {
|
||||||
return FileSystem.getName(path);
|
return FileSystem.getName(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function getDir(path: String): String {
|
public static inline function getDir(path:String):String {
|
||||||
return FileSystem.getDir(path);
|
return FileSystem.getDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function getSize(path: String):Int {
|
public static inline function getSize(path:String):Int {
|
||||||
return FileSystem.getSize(path);
|
return FileSystem.getSize(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function exists(path: String):Bool {
|
public static inline function exists(path:String):Bool {
|
||||||
return FileSystem.exists(path);
|
return FileSystem.exists(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function isDir(path: String): Bool {
|
public static inline function isDir(path:String):Bool {
|
||||||
return FileSystem.isDir(path);
|
return FileSystem.isDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function isReadOnly(path: String):Bool {
|
public static inline function isReadOnly(path:String):Bool {
|
||||||
return FileSystem.isReadOnly(path);
|
return FileSystem.isReadOnly(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function makeDir(path: String):Void {
|
public static inline function makeDir(path:String):Void {
|
||||||
FileSystem.makeDir(path);
|
FileSystem.makeDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function move(src:String,dest:String):Void {
|
public static inline function move(src:String, dest:String):Void {
|
||||||
FileSystem.move(src,dest);
|
FileSystem.move(src, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function copy(src:String,dest:String):Void {
|
public static inline function copy(src:String, dest:String):Void {
|
||||||
FileSystem.copy(src,dest);
|
FileSystem.copy(src, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function delete(path: String):Void {
|
public static inline function delete(path:String):Void {
|
||||||
FileSystem.delete(path);
|
FileSystem.delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openRead(path:String): ReadHandle{
|
public static inline function openRead(path:String):ReadHandle {
|
||||||
return FileSystem.open(path,Read);
|
return FileSystem.open(path, Read);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openWrite(path: String): WriteHandle {
|
public static inline function openWrite(path:String):WriteHandle {
|
||||||
return FileSystem.open(path,Write);
|
return FileSystem.open(path, Write);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openAppend(path: String): WriteHandle {
|
public static inline function openAppend(path:String):WriteHandle {
|
||||||
return FileSystem.open(path,Append);
|
return FileSystem.open(path, Append);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openReadBinary(path:String): ReadBinaryHandle {
|
public static inline function openReadBinary(path:String):ReadBinaryHandle {
|
||||||
return FileSystem.open(path,BinaryRead);
|
return FileSystem.open(path, BinaryRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openWriteBinary(path: String): WriteBinaryHandle {
|
public static inline function openWriteBinary(path:String):WriteBinaryHandle {
|
||||||
return FileSystem.open(path,BinaryWrite);
|
return FileSystem.open(path, BinaryWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openAppendBinary(path: String): WriteBinaryHandle {
|
public static inline function openAppendBinary(path:String):WriteBinaryHandle {
|
||||||
return FileSystem.open(path,BinaryAppend);
|
return FileSystem.open(path, BinaryAppend);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function find(pattern: String):ReadOnlyArray<String> {
|
public static inline function find(pattern:String):ReadOnlyArray<String> {
|
||||||
return FileSystem.find(pattern).toArray();
|
return FileSystem.find(pattern).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ class FS {
|
|||||||
return FileSystem.getCapacity(path);
|
return FileSystem.getCapacity(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function attributes(path: String):FileAttributes {
|
public static inline function attributes(path:String):FileAttributes {
|
||||||
return FileSystem.attributes(path);
|
return FileSystem.attributes(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,107 +5,103 @@ import cc.FileSystem.FileHandle;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
abstract ReadHandle(FileHandle) from FileHandle {
|
abstract ReadHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readLine(?withTrailing:Bool = false):Null<String>{
|
public inline function readLine(?withTrailing:Bool = false):Null<String> {
|
||||||
return this.readLine(withTrailing);
|
return this.readLine(withTrailing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readAll():Null<String>{
|
public inline function readAll():Null<String> {
|
||||||
return this.readAll();
|
return this.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function read(?count:Int = 1):Null<String>{
|
public inline function read(?count:Int = 1):Null<String> {
|
||||||
return this.read(count);
|
return this.read(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract WriteHandle(FileHandle) from FileHandle {
|
abstract WriteHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function write(data:String):Void{
|
public inline function write(data:String):Void {
|
||||||
this.write(data);
|
this.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function writeLine(data:String):Void{
|
public inline function writeLine(data:String):Void {
|
||||||
this.writeLine(data);
|
this.writeLine(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function flush():Void{
|
public inline function flush():Void {
|
||||||
this.flush();
|
this.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract ReadBinaryHandle(FileHandle) from FileHandle {
|
abstract ReadBinaryHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readLine(?withTrailing:Bool = false):Null<String>{
|
public inline function readLine(?withTrailing:Bool = false):Null<String> {
|
||||||
return this.readLine(withTrailing);
|
return this.readLine(withTrailing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readAll():Null<String>{
|
public inline function readAll():Null<String> {
|
||||||
return this.readAll();
|
return this.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function read(count:Int):Null<String>{
|
public inline function read(count:Int):Null<String> {
|
||||||
return this.read(count);
|
return this.read(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readByte():Null<Int>{
|
public inline function readByte():Null<Int> {
|
||||||
return this.read();
|
return this.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void{
|
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void {
|
||||||
this.seek(whence,offset);
|
this.seek(whence, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract WriteBinaryHandle(FileHandle) from FileHandle {
|
abstract WriteBinaryHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function write(data: String):Void{
|
public inline function write(data:String):Void {
|
||||||
this.write(data);
|
this.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
public inline function writeByte(data: Int):Void{
|
public inline function writeByte(data:Int):Void {
|
||||||
// this.write(data);
|
// this.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function flush():Void{
|
public inline function flush():Void {
|
||||||
this.flush();
|
this.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void{
|
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void {
|
||||||
this.seek(whence,offset);
|
this.seek(whence, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@ class GPS {
|
|||||||
private static var shouldDoWholeNumberCheck = true;
|
private static var shouldDoWholeNumberCheck = true;
|
||||||
private static var posAccuracy = 0; // 0 = unkown, 1 = (ins,best guess), 2 = (stored/manual,should be right), 3 = (gps,confirmed)
|
private static var posAccuracy = 0; // 0 = unkown, 1 = (ins,best guess), 2 = (stored/manual,should be right), 3 = (gps,confirmed)
|
||||||
private static var cachedPosition:Pos3;
|
private static var cachedPosition:Pos3;
|
||||||
private static var lastPositionResponse: Array<{pos:Pos3,dist:Float}> = [];
|
private static var lastPositionResponse:Array<{pos:Pos3, dist:Float}> = [];
|
||||||
|
|
||||||
private static var futureResolve: (pos:Null<Pos3>) -> Void = null;
|
private static var futureResolve:(pos:Null<Pos3>) -> Void = null;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
@ -30,7 +30,7 @@ class GPS {
|
|||||||
|
|
||||||
public static function setManualPosition(pos:Pos3) {
|
public static function setManualPosition(pos:Pos3) {
|
||||||
var kvstore = new KVStore("gps");
|
var kvstore = new KVStore("gps");
|
||||||
kvstore.set("mpos",pos);
|
kvstore.set("mpos", pos);
|
||||||
kvstore.save();
|
kvstore.save();
|
||||||
|
|
||||||
if (cachedPosition == null) {
|
if (cachedPosition == null) {
|
||||||
@ -61,7 +61,7 @@ class GPS {
|
|||||||
public static function locate():Future<Null<Pos3>> {
|
public static function locate():Future<Null<Pos3>> {
|
||||||
// TODO: implenet a timeout
|
// TODO: implenet a timeout
|
||||||
// TODO: dont send a request twice if the last one is still pending or we moved
|
// TODO: dont send a request twice if the last one is still pending or we moved
|
||||||
return new Future<Null<Pos3>>((resolve)->{
|
return new Future<Null<Pos3>>((resolve) -> {
|
||||||
futureResolve = resolve;
|
futureResolve = resolve;
|
||||||
sendPositionRequest();
|
sendPositionRequest();
|
||||||
return null;
|
return null;
|
||||||
@ -73,10 +73,11 @@ class GPS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static function persistCachedPositon() {
|
private static function persistCachedPositon() {
|
||||||
if (cachedPosition == null) return;
|
if (cachedPosition == null)
|
||||||
|
return;
|
||||||
var kvstore = new KVStore("gps");
|
var kvstore = new KVStore("gps");
|
||||||
|
|
||||||
kvstore.set("cpos",cachedPosition);
|
kvstore.set("cpos", cachedPosition);
|
||||||
kvstore.save();
|
kvstore.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ class GPS {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPos != null && cPos != null && mPos != cPos){
|
if (mPos != null && cPos != null && mPos != cPos) {
|
||||||
// Both are different, so we can use the manual position
|
// Both are different, so we can use the manual position
|
||||||
cachedPosition = mPos;
|
cachedPosition = mPos;
|
||||||
posAccuracy = 1;
|
posAccuracy = 1;
|
||||||
@ -114,7 +115,6 @@ class GPS {
|
|||||||
posAccuracy = 2;
|
posAccuracy = 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function sendPositionRequest() {
|
private static function sendPositionRequest() {
|
||||||
@ -122,33 +122,39 @@ class GPS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:allow(kernel.net.Net)
|
@:allow(kernel.net.Net)
|
||||||
private static function handlePackage(pack:Package<Noise>, dist: Float,iface: INetworkInterface) {
|
private static function handlePackage(pack:Package<Noise>, dist:Float, iface:INetworkInterface) {
|
||||||
switch (pack.type) {
|
switch (pack.type) {
|
||||||
case GPSRequest:
|
case GPSRequest:
|
||||||
if (!shouldRespond) return;
|
if (!shouldRespond)
|
||||||
if (posAccuracy < 2) return;
|
return;
|
||||||
if (cachedPosition == null) return;
|
if (posAccuracy < 2)
|
||||||
|
return;
|
||||||
|
if (cachedPosition == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var response = new Package(Net.networkID,pack.fromID, pack.msgID, GPSResponse(cachedPosition),null,0);
|
var response = new Package(Net.networkID, pack.fromID, pack.msgID, GPSResponse(cachedPosition), null, 0);
|
||||||
iface.send(pack.fromID,Net.networkID,response);
|
iface.send(pack.fromID, Net.networkID, response);
|
||||||
case GPSResponse(pos):
|
case GPSResponse(pos):
|
||||||
if (lastPositionResponse.contains({pos:pos,dist:dist})) return; // Ignore duplicate responses
|
if (lastPositionResponse.contains({pos: pos, dist: dist}))
|
||||||
|
return; // Ignore duplicate responses
|
||||||
|
|
||||||
lastPositionResponse.push({pos:pos,dist:dist});
|
lastPositionResponse.push({pos: pos, dist: dist});
|
||||||
|
|
||||||
// TODO: wait for a few seconds before calculating the position, so we can get more responses
|
// TODO: wait for a few seconds before calculating the position, so we can get more responses
|
||||||
|
|
||||||
if (lastPositionResponse.length < 4) return; // We need at least 3 responses to calculate the position
|
if (lastPositionResponse.length < 4)
|
||||||
|
return; // We need at least 3 responses to calculate the position
|
||||||
|
|
||||||
var calculatedPosition = calculatePosition();
|
var calculatedPosition = calculatePosition();
|
||||||
|
|
||||||
if (calculatedPosition != null){
|
if (calculatedPosition != null) {
|
||||||
calculatedPosition = calculatedPosition.round();
|
calculatedPosition = calculatedPosition.round();
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPositionResponse = []; // Reset the response array
|
lastPositionResponse = []; // Reset the response array
|
||||||
|
|
||||||
if (calculatedPosition == null) return;
|
if (calculatedPosition == null)
|
||||||
|
return;
|
||||||
cachedPosition = calculatedPosition;
|
cachedPosition = calculatedPosition;
|
||||||
posAccuracy = 3;
|
posAccuracy = 3;
|
||||||
|
|
||||||
@ -158,7 +164,8 @@ class GPS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static function calculatePosition():Null<Pos3> {
|
private static function calculatePosition():Null<Pos3> {
|
||||||
if (lastPositionResponse.length < 3) return null;
|
if (lastPositionResponse.length < 3)
|
||||||
|
return null;
|
||||||
|
|
||||||
// do a simple trilateration with the last 3 responses for now
|
// do a simple trilateration with the last 3 responses for now
|
||||||
var p1 = lastPositionResponse[0].pos;
|
var p1 = lastPositionResponse[0].pos;
|
||||||
@ -169,13 +176,14 @@ class GPS {
|
|||||||
var r2 = lastPositionResponse[1].dist;
|
var r2 = lastPositionResponse[1].dist;
|
||||||
var r3 = lastPositionResponse[2].dist;
|
var r3 = lastPositionResponse[2].dist;
|
||||||
|
|
||||||
var result = trilateration(p1,p2,p3,r1,r2,r3);
|
var result = trilateration(p1, p2, p3, r1, r2, r3);
|
||||||
|
|
||||||
if (result.a.close(result.b)) return result.a;
|
if (result.a.close(result.b))
|
||||||
|
return result.a;
|
||||||
|
|
||||||
// If we have more than 3 responses, we can use the 4th response to determine which of the two positions is correct
|
// If we have more than 3 responses, we can use the 4th response to determine which of the two positions is correct
|
||||||
// TODO: if this is a pocket computer we cant use this since it can move freely
|
// TODO: if this is a pocket computer we cant use this since it can move freely
|
||||||
if (lastPositionResponse.length > 3){
|
if (lastPositionResponse.length > 3) {
|
||||||
var err1 = Math.abs(result.a.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
var err1 = Math.abs(result.a.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
||||||
var err2 = Math.abs(result.b.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
var err2 = Math.abs(result.b.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
||||||
|
|
||||||
@ -184,12 +192,15 @@ class GPS {
|
|||||||
return null; // The two positions are essentially the same, so we cant determine which one is correct
|
return null; // The two positions are essentially the same, so we cant determine which one is correct
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err1 < err2) return result.a;
|
if (err1 < err2)
|
||||||
if (err2 < err1) return result.b;
|
return result.a;
|
||||||
|
if (err2 < err1)
|
||||||
|
return result.b;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last resort, just use the position that is closest to a whole number (whithin a resonable margin of error)
|
// last resort, just use the position that is closest to a whole number (whithin a resonable margin of error)
|
||||||
if (!shouldDoWholeNumberCheck) return null;
|
if (!shouldDoWholeNumberCheck)
|
||||||
|
return null;
|
||||||
|
|
||||||
// TODO: mark the position as not so accurate if we use this method
|
// TODO: mark the position as not so accurate if we use this method
|
||||||
|
|
||||||
@ -208,7 +219,7 @@ class GPS {
|
|||||||
/**
|
/**
|
||||||
Determines the position(s) of a point given 3 other points and the distance to each of them.
|
Determines the position(s) of a point given 3 other points and the distance to each of them.
|
||||||
**/
|
**/
|
||||||
private static function trilateration(p1:Pos3,p2:Pos3,p3: Pos3,r1:Float,r2:Float,r3:Float):Pair<Pos3,Pos3> {
|
private static function trilateration(p1:Pos3, p2:Pos3, p3:Pos3, r1:Float, r2:Float, r3:Float):Pair<Pos3, Pos3> {
|
||||||
var a2b = p2 - p1;
|
var a2b = p2 - p1;
|
||||||
var a2c = p3 - p1;
|
var a2c = p3 - p1;
|
||||||
|
|
||||||
@ -227,9 +238,9 @@ class GPS {
|
|||||||
var zSquared = r1 * r1 - x * x - y * y;
|
var zSquared = r1 * r1 - x * x - y * y;
|
||||||
if (zSquared > 0) {
|
if (zSquared > 0) {
|
||||||
var z = Math.sqrt(zSquared);
|
var z = Math.sqrt(zSquared);
|
||||||
return new Pair(result + (ez * z),result - (ez * z));
|
return new Pair(result + (ez * z), result - (ez * z));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair(result,result);
|
return new Pair(result, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import lib.Pos3;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class INS {
|
class INS {
|
||||||
private static var heading: Null<Pos3> = null;
|
private static var heading:Null<Pos3> = null;
|
||||||
private static var alingment: Int = 1; // 0 = degraded, 1 = not aligned, 2 = aligned
|
private static var alingment:Int = 1; // 0 = degraded, 1 = not aligned, 2 = aligned
|
||||||
|
|
||||||
@:allow(kernel.turtle.Turtle)
|
@:allow(kernel.turtle.Turtle)
|
||||||
private static function moveForward() {
|
private static function moveForward() {
|
||||||
@ -40,7 +40,8 @@ class INS {
|
|||||||
|
|
||||||
@:allow(kernel.turtle.Turtle)
|
@:allow(kernel.turtle.Turtle)
|
||||||
private static function turnLeft() {
|
private static function turnLeft() {
|
||||||
if (heading == null) return;
|
if (heading == null)
|
||||||
|
return;
|
||||||
if (heading.x == 0 && heading.z == -1) {
|
if (heading.x == 0 && heading.z == -1) {
|
||||||
heading = {x: -1, y: 0, z: 0};
|
heading = {x: -1, y: 0, z: 0};
|
||||||
} else if (heading.x == -1 && heading.z == 0) {
|
} else if (heading.x == -1 && heading.z == 0) {
|
||||||
@ -54,7 +55,8 @@ class INS {
|
|||||||
|
|
||||||
@:allow(kernel.turtle.Turtle)
|
@:allow(kernel.turtle.Turtle)
|
||||||
private static function turnRight() {
|
private static function turnRight() {
|
||||||
if (heading == null) return;
|
if (heading == null)
|
||||||
|
return;
|
||||||
if (heading.x == 0 && heading.z == -1) {
|
if (heading.x == 0 && heading.z == -1) {
|
||||||
heading = {x: 1, y: 0, z: 0};
|
heading = {x: 1, y: 0, z: 0};
|
||||||
} else if (heading.x == -1 && heading.z == 0) {
|
} else if (heading.x == -1 && heading.z == 0) {
|
||||||
@ -66,7 +68,7 @@ class INS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function move(dir: Null<Pos3>) {
|
private static function move(dir:Null<Pos3>) {
|
||||||
Log.debug('INS move: $dir');
|
Log.debug('INS move: $dir');
|
||||||
var pos = GPS.getPosition();
|
var pos = GPS.getPosition();
|
||||||
var newPos = pos + dir;
|
var newPos = pos + dir;
|
||||||
@ -77,17 +79,16 @@ class INS {
|
|||||||
return heading;
|
return heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function align(): Promise<Noise> {
|
public static function align():Promise<Noise> {
|
||||||
Log.info("Aligning INS");
|
Log.info("Aligning INS");
|
||||||
return new Promise<Noise>((resolve,reject)->{
|
return new Promise<Noise>((resolve, reject) -> {
|
||||||
|
if (Turtle.instance.getFuelLevel() < 2) {
|
||||||
if (Turtle.instance.getFuelLevel() < 2){
|
|
||||||
Log.warn("Not enough fuel to align");
|
Log.warn("Not enough fuel to align");
|
||||||
reject(new Error("Not enough fuel to align"));
|
reject(new Error("Not enough fuel to align"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPS.locate().handle((pos1)->{
|
GPS.locate().handle((pos1) -> {
|
||||||
Log.debug('pos1: $pos1');
|
Log.debug('pos1: $pos1');
|
||||||
if (pos1 == null) {
|
if (pos1 == null) {
|
||||||
Log.warn("GPS not available for 1st position");
|
Log.warn("GPS not available for 1st position");
|
||||||
@ -103,7 +104,7 @@ class INS {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPS.locate().handle((pos2)->{
|
GPS.locate().handle((pos2) -> {
|
||||||
Log.debug('pos2: $pos2');
|
Log.debug('pos2: $pos2');
|
||||||
if (pos2 == null) {
|
if (pos2 == null) {
|
||||||
Log.warn("GPS not available for 2nd position");
|
Log.warn("GPS not available for 2nd position");
|
||||||
@ -111,7 +112,7 @@ class INS {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cHeading = calcHeading(pos1,pos2,moved);
|
var cHeading = calcHeading(pos1, pos2, moved);
|
||||||
if (cHeading == null) {
|
if (cHeading == null) {
|
||||||
Log.error("Can't calculate heading");
|
Log.error("Can't calculate heading");
|
||||||
reject(new Error("Can't calculate heading"));
|
reject(new Error("Can't calculate heading"));
|
||||||
@ -124,7 +125,6 @@ class INS {
|
|||||||
|
|
||||||
resolve(Noise);
|
resolve(Noise);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@ -138,7 +138,7 @@ class INS {
|
|||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
Turtle.instance.turnLeft(); // TODO: Check if successfull
|
Turtle.instance.turnLeft(); // TODO: Check if successfull
|
||||||
if (Turtle.instance.forward().isSuccess()){
|
if (Turtle.instance.forward().isSuccess()) {
|
||||||
return 2;
|
return 2;
|
||||||
} else if (Turtle.instance.back().isSuccess()) {
|
} else if (Turtle.instance.back().isSuccess()) {
|
||||||
return 3;
|
return 3;
|
||||||
@ -149,7 +149,7 @@ class INS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calcHeading(pos1: Pos3,pos2:Pos3,moved:Int): Null<Pos3> {
|
private static function calcHeading(pos1:Pos3, pos2:Pos3, moved:Int):Null<Pos3> {
|
||||||
if (moved == 0) {
|
if (moved == 0) {
|
||||||
return pos1 - pos2;
|
return pos1 - pos2;
|
||||||
} else if (moved == 1) {
|
} else if (moved == 1) {
|
||||||
@ -200,5 +200,4 @@ class INS {
|
|||||||
private static function rotatePos3ToLeft(pos3:Pos3):Pos3 {
|
private static function rotatePos3ToLeft(pos3:Pos3):Pos3 {
|
||||||
return rotatePos3ToRight(rotatePos3ToRight(rotatePos3ToRight(pos3)));
|
return rotatePos3ToRight(rotatePos3ToRight(rotatePos3ToRight(pos3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,15 @@ package kernel.http;
|
|||||||
using lua.Table;
|
using lua.Table;
|
||||||
|
|
||||||
class HTTPFailure {
|
class HTTPFailure {
|
||||||
|
|
||||||
public final reason:String;
|
public final reason:String;
|
||||||
public final statusCode:Null<StatusCode>;
|
public final statusCode:Null<StatusCode>;
|
||||||
public final headers:Map<String,String>;
|
public final headers:Map<String, String>;
|
||||||
public final body:String;
|
public final body:String;
|
||||||
|
|
||||||
@:allow(kernel.http)
|
@:allow(kernel.http)
|
||||||
private function new(failReason: String, ?handle: cc.HTTP.HTTPResponse) {
|
private function new(failReason:String, ?handle:cc.HTTP.HTTPResponse) {
|
||||||
this.reason = failReason;
|
this.reason = failReason;
|
||||||
if (handle != null){
|
if (handle != null) {
|
||||||
this.statusCode = handle.getResponseCode();
|
this.statusCode = handle.getResponseCode();
|
||||||
this.headers = handle.getResponseHeaders().toMap();
|
this.headers = handle.getResponseHeaders().toMap();
|
||||||
this.body = handle.readAll();
|
this.body = handle.readAll();
|
||||||
|
@ -6,21 +6,21 @@ using tink.CoreApi;
|
|||||||
Wrapper for the native HTTP request function.
|
Wrapper for the native HTTP request function.
|
||||||
**/
|
**/
|
||||||
class Http {
|
class Http {
|
||||||
public static function request(url:String,?body:String,?options: String):Future<Outcome<HTTPResponse,HTTPFailure>> {
|
public static function request(url:String, ?body:String, ?options:String):Future<Outcome<HTTPResponse, HTTPFailure>> {
|
||||||
return new Future<Outcome<HTTPResponse,HTTPFailure>>((resolve) -> {
|
return new Future<Outcome<HTTPResponse, HTTPFailure>>((resolve) -> {
|
||||||
KernelEvents.onHttpFailure.handle((params)->{
|
KernelEvents.onHttpFailure.handle((params) -> {
|
||||||
if (params.url == url){
|
if (params.url == url) {
|
||||||
resolve(Failure(new HTTPFailure(params.failReason,params.handle)));
|
resolve(Failure(new HTTPFailure(params.failReason, params.handle)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.onHttpSuccess.handle((params) -> {
|
KernelEvents.onHttpSuccess.handle((params) -> {
|
||||||
if (params.url == url){
|
if (params.url == url) {
|
||||||
resolve(Success(new HTTPResponse(params.handle)));
|
resolve(Success(new HTTPResponse(params.handle)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cc.HTTP.request(url,body);
|
cc.HTTP.request(url, body);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
@ -3,13 +3,12 @@ package kernel.http;
|
|||||||
using lua.Table;
|
using lua.Table;
|
||||||
|
|
||||||
class HTTPResponse {
|
class HTTPResponse {
|
||||||
|
|
||||||
public final statusCode:StatusCode;
|
public final statusCode:StatusCode;
|
||||||
public final headers:Map<String,String>;
|
public final headers:Map<String, String>;
|
||||||
public final body:String;
|
public final body:String;
|
||||||
|
|
||||||
@:allow(kernel.http)
|
@:allow(kernel.http)
|
||||||
private function new(handle: cc.HTTP.HTTPResponse) {
|
private function new(handle:cc.HTTP.HTTPResponse) {
|
||||||
this.statusCode = handle.getResponseCode();
|
this.statusCode = handle.getResponseCode();
|
||||||
this.headers = handle.getResponseHeaders().toMap();
|
this.headers = handle.getResponseHeaders().toMap();
|
||||||
this.body = handle.readAll();
|
this.body = handle.readAll();
|
||||||
|
@ -24,28 +24,28 @@ class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function info(msg:Dynamic, ?pos:haxe.PosInfos) {
|
public static function info(msg:Dynamic, ?pos:haxe.PosInfos) {
|
||||||
log({level: Info, message: Std.string(msg),time: 0},pos);
|
log({level: Info, message: Std.string(msg), time: 0}, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) {
|
public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) {
|
||||||
log({level: Warn, message: Std.string(msg),time: 0},pos);
|
log({level: Warn, message: Std.string(msg), time: 0}, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function error(msg:Dynamic, ?pos:haxe.PosInfos) {
|
public static function error(msg:Dynamic, ?pos:haxe.PosInfos) {
|
||||||
log({level: Error, message: Std.string(msg),time: 0},pos);
|
log({level: Error, message: Std.string(msg), time: 0}, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) {
|
public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) {
|
||||||
#if debug
|
#if debug
|
||||||
log({level: Debug, message: Std.string(msg),time: 0},pos);
|
log({level: Debug, message: Std.string(msg), time: 0}, pos);
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
|
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
|
||||||
log({level: Silly, message: Std.string(msg),time: 0},pos);
|
log({level: Silly, message: Std.string(msg), time: 0}, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function log(line: LogLine, ?pos:haxe.PosInfos) {
|
private static function log(line:LogLine, ?pos:haxe.PosInfos) {
|
||||||
line.origin = pos.className;
|
line.origin = pos.className;
|
||||||
logLines.push(line);
|
logLines.push(line);
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package kernel.log;
|
package kernel.log;
|
||||||
|
|
||||||
typedef LogLine = {
|
typedef LogLine = {
|
||||||
level: LogLevel,
|
level:LogLevel,
|
||||||
message: String,
|
message:String,
|
||||||
time: Int,
|
time:Int,
|
||||||
?origin: String,
|
?origin:String,
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
package kernel.net;
|
package kernel.net;
|
||||||
|
|
||||||
import kernel.net.Package.GenericPackage;
|
import kernel.net.Package.GenericPackage;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A object that is able to send and receive messages.
|
A object that is able to send and receive messages.
|
||||||
**/
|
**/
|
||||||
interface INetworkInterface {
|
interface INetworkInterface {
|
||||||
public function listen(chan: Int):Void;
|
public function listen(chan:Int):Void;
|
||||||
public function close(chan: Int):Void;
|
public function close(chan:Int):Void;
|
||||||
public function isListening(chan: Int): Bool;
|
public function isListening(chan:Int):Bool;
|
||||||
public function closeAll(): Void;
|
public function closeAll():Void;
|
||||||
public function send(chan: Int,replyChan: Int,payload: Any):Void;
|
public function send(chan:Int, replyChan:Int, payload:Any):Void;
|
||||||
public function name():String;
|
public function name():String;
|
||||||
public function getBaseRoutingCost():Int;
|
public function getBaseRoutingCost():Int;
|
||||||
public var onMessage (default, null): Signal<{pack:GenericPackage,?dist:Float}>;
|
public var onMessage(default, null):Signal<{pack:GenericPackage, ?dist:Float}>;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package kernel.net;
|
|||||||
|
|
||||||
import kernel.net.Package.GenericPackage;
|
import kernel.net.Package.GenericPackage;
|
||||||
import kernel.log.Log;
|
import kernel.log.Log;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,17 +11,17 @@ using tink.CoreApi;
|
|||||||
class Loopback implements INetworkInterface {
|
class Loopback implements INetworkInterface {
|
||||||
public static final instance:Loopback = new Loopback();
|
public static final instance:Loopback = new Loopback();
|
||||||
|
|
||||||
public var onMessage(default, null):Signal<{pack:GenericPackage,dist:Null<Float>}>;
|
public var onMessage(default, null):Signal<{pack:GenericPackage, dist:Null<Float>}>;
|
||||||
|
|
||||||
private final onMessageTrigger: SignalTrigger<{pack:GenericPackage,dist:Null<Float>}> = Signal.trigger();
|
private final onMessageTrigger:SignalTrigger<{pack:GenericPackage, dist:Null<Float>}> = Signal.trigger();
|
||||||
private var openChans: Array<Int> = [];
|
private var openChans:Array<Int> = [];
|
||||||
|
|
||||||
private function new() {
|
private function new() {
|
||||||
this.onMessage = onMessageTrigger.asSignal();
|
this.onMessage = onMessageTrigger.asSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listen(chan:Int) {
|
public function listen(chan:Int) {
|
||||||
if (!this.openChans.contains(chan)){
|
if (!this.openChans.contains(chan)) {
|
||||||
this.openChans.push(chan);
|
this.openChans.push(chan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,9 +39,9 @@ class Loopback implements INetworkInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function send(chan:Int, replyChan:Int, payload:Any) {
|
public function send(chan:Int, replyChan:Int, payload:Any) {
|
||||||
if (this.openChans.contains(chan)){
|
if (this.openChans.contains(chan)) {
|
||||||
this.onMessageTrigger.trigger({pack:payload,dist:null});
|
this.onMessageTrigger.trigger({pack: payload, dist: null});
|
||||||
}else{
|
} else {
|
||||||
Log.silly("Loopback got package on non open channel");
|
Log.silly("Loopback got package on non open channel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,20 +21,21 @@ class Net {
|
|||||||
Depends on: KernelEvents
|
Depends on: KernelEvents
|
||||||
**/
|
**/
|
||||||
public static inline final BRODCAST_PORT:Int = 65533;
|
public static inline final BRODCAST_PORT:Int = 65533;
|
||||||
|
|
||||||
public static inline final MESSAGE_TIMEOUT:Int = 3;
|
public static inline final MESSAGE_TIMEOUT:Int = 3;
|
||||||
public static inline final DEFAULT_TTL:Int = 10;
|
public static inline final DEFAULT_TTL:Int = 10;
|
||||||
|
|
||||||
public static final networkID:NetworkID = OS.getComputerID();
|
public static final networkID:NetworkID = OS.getComputerID();
|
||||||
private static final responseBus:Map<Int, Callback<Outcome<GenericPackage,Error>>> = new Map();
|
private static final responseBus:Map<Int, Callback<Outcome<GenericPackage, Error>>> = new Map();
|
||||||
private static final protoHandlers:Map<String, Callback<GenericPackage>> = new Map();
|
private static final protoHandlers:Map<String, Callback<GenericPackage>> = new Map();
|
||||||
private static var interfaces:Array<INetworkInterface>;
|
private static var interfaces:Array<INetworkInterface>;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
interfaces = [for (e in Peripheral.getAllModems()) e ]; // TODO: is this the way to do it?
|
interfaces = [for (e in Peripheral.getAllModems()) e]; // TODO: is this the way to do it?
|
||||||
interfaces.push(Loopback.instance);
|
interfaces.push(Loopback.instance);
|
||||||
|
|
||||||
for (interf in interfaces){
|
for (interf in interfaces) {
|
||||||
setupInterf(interf);
|
setupInterf(interf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +62,8 @@ class Net {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function setupInterf(interf: INetworkInterface) {
|
private static function setupInterf(interf:INetworkInterface) {
|
||||||
interf.onMessage.handle(e -> handle(e.pack,interf,e.dist));
|
interf.onMessage.handle(e -> handle(e.pack, interf, e.dist));
|
||||||
interf.listen(networkID);
|
interf.listen(networkID);
|
||||||
interf.listen(BRODCAST_PORT);
|
interf.listen(BRODCAST_PORT);
|
||||||
}
|
}
|
||||||
@ -70,8 +71,8 @@ class Net {
|
|||||||
/**
|
/**
|
||||||
Called when a new package comes in.
|
Called when a new package comes in.
|
||||||
**/
|
**/
|
||||||
private static function handle(pack:GenericPackage,interf: INetworkInterface, ?dist: Float) {
|
private static function handle(pack:GenericPackage, interf:INetworkInterface, ?dist:Float) {
|
||||||
if (pack.toID == networkID || pack.toID == Net.BRODCAST_PORT){
|
if (pack.toID == networkID || pack.toID == Net.BRODCAST_PORT) {
|
||||||
switch pack.type {
|
switch pack.type {
|
||||||
case Data(_) | DataNoResponse(_):
|
case Data(_) | DataNoResponse(_):
|
||||||
// Let a local proccess handle it
|
// Let a local proccess handle it
|
||||||
@ -83,16 +84,16 @@ class Net {
|
|||||||
}
|
}
|
||||||
case RouteDiscover(_) | RouteDiscoverResponse(_) | RouteDiscoverUpdate(_):
|
case RouteDiscover(_) | RouteDiscoverResponse(_) | RouteDiscoverUpdate(_):
|
||||||
// Delegate to Routing
|
// Delegate to Routing
|
||||||
Routing.handleRoutePackage(cast pack,interf);
|
Routing.handleRoutePackage(cast pack, interf);
|
||||||
case GPSRequest | GPSResponse(_):
|
case GPSRequest | GPSResponse(_):
|
||||||
if (dist == null) {
|
if (dist == null) {
|
||||||
Log.silly("Got a GPS package but no distance was provided");
|
Log.silly("Got a GPS package but no distance was provided");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Delegate to GPS
|
// Delegate to GPS
|
||||||
GPS.handlePackage(cast pack,dist,interf);
|
GPS.handlePackage(cast pack, dist, interf);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
// New message received but its not ment for us. Forward if possible.
|
// New message received but its not ment for us. Forward if possible.
|
||||||
forwardPackage(pack);
|
forwardPackage(pack);
|
||||||
}
|
}
|
||||||
@ -118,13 +119,12 @@ class Net {
|
|||||||
sendRaw(pack);
|
sendRaw(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function forwardPackage(pack: GenericPackage) {
|
private static function forwardPackage(pack:GenericPackage) {
|
||||||
if (pack.ttl == 0){
|
if (pack.ttl == 0) {
|
||||||
|
|
||||||
if (pack.type.match(Data(_))) {
|
if (pack.type.match(Data(_))) {
|
||||||
// If the package is a data package and the ttl hits 0
|
// If the package is a data package and the ttl hits 0
|
||||||
// we send a "died" message to the sender
|
// we send a "died" message to the sender
|
||||||
sendAndForget(pack.fromID, "icmp", {type:"died", msgID: pack.msgID});
|
sendAndForget(pack.fromID, "icmp", {type: "died", msgID: pack.msgID});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop package
|
// Drop package
|
||||||
@ -133,7 +133,7 @@ class Net {
|
|||||||
|
|
||||||
pack.ttl--;
|
pack.ttl--;
|
||||||
|
|
||||||
if (!sendRaw(pack)){
|
if (!sendRaw(pack)) {
|
||||||
// Cant forward
|
// Cant forward
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,13 +174,13 @@ class Net {
|
|||||||
Just send the package to the right modem.
|
Just send the package to the right modem.
|
||||||
Returns true if message was send
|
Returns true if message was send
|
||||||
**/
|
**/
|
||||||
private static function sendRaw(pack:GenericPackage): Bool {
|
private static function sendRaw(pack:GenericPackage):Bool {
|
||||||
var route = Routing.getRouteToID(pack.toID);
|
var route = Routing.getRouteToID(pack.toID);
|
||||||
if (route == null){
|
if (route == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
route.interf.send(route.rep,networkID,pack);
|
route.interf.send(route.rep, networkID, pack);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,8 +200,7 @@ class Net {
|
|||||||
|
|
||||||
var timeout:Timer = null;
|
var timeout:Timer = null;
|
||||||
|
|
||||||
responseBus[pack.msgID] = ((reponse:Outcome<GenericPackage,Error>) -> {
|
responseBus[pack.msgID] = ((reponse:Outcome<GenericPackage, Error>) -> {
|
||||||
|
|
||||||
switch reponse {
|
switch reponse {
|
||||||
case Success(pack):
|
case Success(pack):
|
||||||
resolve(pack);
|
resolve(pack);
|
||||||
@ -217,10 +216,10 @@ class Net {
|
|||||||
|
|
||||||
timeout = new Timer(MESSAGE_TIMEOUT, () -> {
|
timeout = new Timer(MESSAGE_TIMEOUT, () -> {
|
||||||
responseBus.remove(pack.msgID);
|
responseBus.remove(pack.msgID);
|
||||||
reject(new Error(InternalError,"Message timeout"));
|
reject(new Error(InternalError, "Message timeout"));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!sendRaw(pack)){
|
if (!sendRaw(pack)) {
|
||||||
reject(new Error("ID unreachable"));
|
reject(new Error("ID unreachable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,9 +245,9 @@ class Net {
|
|||||||
/**
|
/**
|
||||||
Sends a ping package to the given id. Returns true if there was a response.
|
Sends a ping package to the given id. Returns true if there was a response.
|
||||||
**/
|
**/
|
||||||
public static function ping(toID: NetworkID): Promise<Noise> {
|
public static function ping(toID:NetworkID):Promise<Noise> {
|
||||||
return new Promise<Noise>((resolve,reject)->{
|
return new Promise<Noise>((resolve, reject) -> {
|
||||||
sendAndAwait(toID,"icmp",{type:"ping"}).handle(pack -> {
|
sendAndAwait(toID, "icmp", {type: "ping"}).handle(pack -> {
|
||||||
switch pack {
|
switch pack {
|
||||||
case Success(_):
|
case Success(_):
|
||||||
resolve(Noise);
|
resolve(Noise);
|
||||||
@ -260,7 +259,7 @@ class Net {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getActiveProtocols(): ReadOnlyArray<String> {
|
public static function getActiveProtocols():ReadOnlyArray<String> {
|
||||||
var arr = new Array<String>();
|
var arr = new Array<String>();
|
||||||
|
|
||||||
for (proto in protoHandlers.keys()) {
|
for (proto in protoHandlers.keys()) {
|
||||||
@ -272,7 +271,7 @@ class Net {
|
|||||||
|
|
||||||
@:allow(kernel.gps.GPS)
|
@:allow(kernel.gps.GPS)
|
||||||
private static function brodcastGPSRequest() {
|
private static function brodcastGPSRequest() {
|
||||||
var pack: Package<Noise> = {
|
var pack:Package<Noise> = {
|
||||||
fromID: networkID,
|
fromID: networkID,
|
||||||
toID: Net.BRODCAST_PORT,
|
toID: Net.BRODCAST_PORT,
|
||||||
ttl: 0, // Prevent forwarding
|
ttl: 0, // Prevent forwarding
|
||||||
@ -282,7 +281,8 @@ class Net {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (modem in Peripheral.getAllModems()) {
|
for (modem in Peripheral.getAllModems()) {
|
||||||
if (!modem.isWireless()) continue;
|
if (!modem.isWireless())
|
||||||
|
continue;
|
||||||
modem.send(Net.BRODCAST_PORT, networkID, pack);
|
modem.send(Net.BRODCAST_PORT, networkID, pack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,15 @@ package kernel.net;
|
|||||||
import lib.Pos3;
|
import lib.Pos3;
|
||||||
|
|
||||||
typedef NetworkID = Int;
|
typedef NetworkID = Int;
|
||||||
typedef GenericPackage = Package<Dynamic> ;
|
typedef GenericPackage = Package<Dynamic>;
|
||||||
|
|
||||||
enum PackageTypes {
|
enum PackageTypes {
|
||||||
Data(proto:String);
|
Data(proto:String);
|
||||||
DataNoResponse(proto:String);
|
DataNoResponse(proto:String);
|
||||||
Response;
|
Response;
|
||||||
RouteDiscover(reachableIDs: Array<{id:NetworkID,cost:Int}>);
|
RouteDiscover(reachableIDs:Array<{id:NetworkID, cost:Int}>);
|
||||||
RouteDiscoverResponse(reachableIDs: Array<{id:NetworkID,cost:Int}>);
|
RouteDiscoverResponse(reachableIDs:Array<{id:NetworkID, cost:Int}>);
|
||||||
RouteDiscoverUpdate(reachableIDs: Array<{id:NetworkID,cost:Int}>);
|
RouteDiscoverUpdate(reachableIDs:Array<{id:NetworkID, cost:Int}>);
|
||||||
GPSResponse(pos:Pos3);
|
GPSResponse(pos:Pos3);
|
||||||
GPSRequest();
|
GPSRequest();
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ enum PackageTypes {
|
|||||||
public final msgID:Int;
|
public final msgID:Int;
|
||||||
public final type:PackageTypes;
|
public final type:PackageTypes;
|
||||||
public final data:T;
|
public final data:T;
|
||||||
public var ttl: Int;
|
public var ttl:Int;
|
||||||
|
|
||||||
public function new(fromID:NetworkID, toID:NetworkID, msgID:Int, type:PackageTypes, data:T, ttl:Int) {
|
public function new(fromID:NetworkID, toID:NetworkID, msgID:Int, type:PackageTypes, data:T, ttl:Int) {
|
||||||
this.fromID = fromID;
|
this.fromID = fromID;
|
||||||
|
@ -20,7 +20,6 @@ class Routing {
|
|||||||
/**
|
/**
|
||||||
Depends on: Peripheral
|
Depends on: Peripheral
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public static inline final UPDATE_WAIT_TIME:Float = 1;
|
public static inline final UPDATE_WAIT_TIME:Float = 1;
|
||||||
|
|
||||||
public static var onNewNeigbor(default, null):Signal<Int>;
|
public static var onNewNeigbor(default, null):Signal<Int>;
|
||||||
|
@ -168,8 +168,7 @@ class BigReactor implements IPeripheral {
|
|||||||
// getFuelStats
|
// getFuelStats
|
||||||
// getEnergyStats
|
// getEnergyStats
|
||||||
// getCoolantFluidStats
|
// getCoolantFluidStats
|
||||||
// getHotFluidStats
|
// getHotFluidStats
|
||||||
|
|
||||||
// TODO: need research
|
// TODO: need research
|
||||||
// isMethodAvailable(method: String): Bool
|
// isMethodAvailable(method: String): Bool
|
||||||
// mbGetMaximumCoordinate(): Pos3
|
// mbGetMaximumCoordinate(): Pos3
|
||||||
|
@ -4,47 +4,47 @@ import cc.Peripheral;
|
|||||||
import kernel.net.Package.NetworkID;
|
import kernel.net.Package.NetworkID;
|
||||||
|
|
||||||
class Computer implements IPeripheral {
|
class Computer implements IPeripheral {
|
||||||
public static inline final TYPE_NAME:String = "computer";
|
public static inline final TYPE_NAME:String = "computer";
|
||||||
|
|
||||||
private final addr:String;
|
private final addr:String;
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
private function new(addr: String) {
|
private function new(addr:String) {
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddr():String {
|
public function getAddr():String {
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getType():String {
|
public function getType():String {
|
||||||
return Computer.TYPE_NAME;
|
return Computer.TYPE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isOn():Bool {
|
public function isOn():Bool {
|
||||||
return Peripheral.call(addr, "isOn");
|
return Peripheral.call(addr, "isOn");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLabel():Null<String> {
|
public function getLabel():Null<String> {
|
||||||
return Peripheral.call(addr, "getLabel");
|
return Peripheral.call(addr, "getLabel");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return -1 if no ID set yet
|
Return -1 if no ID set yet
|
||||||
**/
|
**/
|
||||||
public function getID():NetworkID{
|
public function getID():NetworkID {
|
||||||
return Peripheral.call(addr, "getID");
|
return Peripheral.call(addr, "getID");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reboot() {
|
public function reboot() {
|
||||||
Peripheral.call(addr, "reboot");
|
Peripheral.call(addr, "reboot");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shutdown() {
|
public function shutdown() {
|
||||||
Peripheral.call(addr, "shutdown");
|
Peripheral.call(addr, "shutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function turnOn() {
|
public function turnOn() {
|
||||||
Peripheral.call(addr, "turnOn");
|
Peripheral.call(addr, "turnOn");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
import cc.Peripheral;
|
import cc.Peripheral;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Drive implements IPeripheral {
|
class Drive implements IPeripheral {
|
||||||
@ -15,21 +16,21 @@ class Drive implements IPeripheral {
|
|||||||
private final onDiskEjectTrigger:SignalTrigger<Noise> = Signal.trigger();
|
private final onDiskEjectTrigger:SignalTrigger<Noise> = Signal.trigger();
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
private function new(addr: String) {
|
private function new(addr:String) {
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
this.native = Peripheral.wrap(addr);
|
this.native = Peripheral.wrap(addr);
|
||||||
|
|
||||||
this.onDiskInsert = this.onDiskInsertTrigger.asSignal();
|
this.onDiskInsert = this.onDiskInsertTrigger.asSignal();
|
||||||
this.onDiskEject = this.onDiskEjectTrigger.asSignal();
|
this.onDiskEject = this.onDiskEjectTrigger.asSignal();
|
||||||
|
|
||||||
KernelEvents.onDisk.handle((addr) ->{
|
KernelEvents.onDisk.handle((addr) -> {
|
||||||
if (addr == this.addr){
|
if (addr == this.addr) {
|
||||||
this.onDiskInsertTrigger.trigger(null);
|
this.onDiskInsertTrigger.trigger(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.onDiskEject.handle((addr)->{
|
KernelEvents.onDiskEject.handle((addr) -> {
|
||||||
if (addr == this.addr){
|
if (addr == this.addr) {
|
||||||
this.onDiskEjectTrigger.trigger(null);
|
this.onDiskEjectTrigger.trigger(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -43,14 +44,14 @@ class Drive implements IPeripheral {
|
|||||||
return TYPE_NAME;
|
return TYPE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function isDiskPresent(): Bool {
|
public inline function isDiskPresent():Bool {
|
||||||
return this.native.isDiskPresent();
|
return this.native.isDiskPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The label of the disk, or `null` if either no disk is inserted or the disk doesn't have a label.
|
The label of the disk, or `null` if either no disk is inserted or the disk doesn't have a label.
|
||||||
**/
|
**/
|
||||||
public inline function getDiskLabel(): Null<String> {
|
public inline function getDiskLabel():Null<String> {
|
||||||
return this.native.getDiskLabel();
|
return this.native.getDiskLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,11 +59,11 @@ class Drive implements IPeripheral {
|
|||||||
this.native.setDiskLabel();
|
this.native.setDiskLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function setDiskLabel(label: String): Null<Error> {
|
public inline function setDiskLabel(label:String):Null<Error> {
|
||||||
try {
|
try {
|
||||||
this.native.setDiskLabel(label);
|
this.native.setDiskLabel(label);
|
||||||
return null;
|
return null;
|
||||||
} catch (e: Dynamic) {
|
} catch (e:Dynamic) {
|
||||||
return new Error("Invalid label");
|
return new Error("Invalid label");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,7 +80,7 @@ class Drive implements IPeripheral {
|
|||||||
return this.getMountPath();
|
return this.getMountPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getAudioTitle(): Null<String> {
|
public inline function getAudioTitle():Null<String> {
|
||||||
return this.native.getAudioTitle();
|
return this.native.getAudioTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ class Drive implements IPeripheral {
|
|||||||
this.native.ejectDisk();
|
this.native.ejectDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getDiskID(): Int {
|
public inline function getDiskID():Int {
|
||||||
return this.native.getDiskID();
|
return this.native.getDiskID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,24 +3,24 @@ package kernel.peripherals;
|
|||||||
import lib.exporter.ExportConfig;
|
import lib.exporter.ExportConfig;
|
||||||
import lib.exporter.IExportable;
|
import lib.exporter.IExportable;
|
||||||
|
|
||||||
class EnergyStorage implements IPeripheral implements IExportable{
|
class EnergyStorage implements IPeripheral implements IExportable {
|
||||||
public static inline final TYPE_NAME:String = "energyCell";
|
public static inline final TYPE_NAME:String = "energyCell";
|
||||||
|
|
||||||
private final addr:String;
|
private final addr:String;
|
||||||
private final native: cc.periphs.EnergyStorage;
|
private final native:cc.periphs.EnergyStorage;
|
||||||
|
|
||||||
public function new(addr: String) {
|
public function new(addr:String) {
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
this.native = cc.Peripheral.wrap(addr);
|
this.native = cc.Peripheral.wrap(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEnergy(): Int {
|
public function getEnergy():Int {
|
||||||
return this.native.getEnergy();
|
return this.native.getEnergy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEnergyCapacity(): Int {
|
public function getEnergyCapacity():Int {
|
||||||
return this.native.getEnergyCapacity();
|
return this.native.getEnergyCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddr():String {
|
public function getAddr():String {
|
||||||
return this.addr;
|
return this.addr;
|
||||||
@ -32,10 +32,10 @@ class EnergyStorage implements IPeripheral implements IExportable{
|
|||||||
|
|
||||||
public function export():ExportConfig {
|
public function export():ExportConfig {
|
||||||
return {
|
return {
|
||||||
getDelegates: [
|
getDelegates: [
|
||||||
"energy" => _ -> Number(this.getEnergy()),
|
"energy" => _ -> Number(this.getEnergy()),
|
||||||
"capacity" => _ -> Number(this.getEnergyCapacity()),
|
"capacity" => _ -> Number(this.getEnergyCapacity()),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
interface IPeripheral {
|
interface IPeripheral {
|
||||||
public function getAddr(): String;
|
public function getAddr():String;
|
||||||
public function getType(): String;
|
public function getType():String;
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
public static inline final TYPE_NAME:String = "modem";
|
public static inline final TYPE_NAME:String = "modem";
|
||||||
|
|
||||||
public final addr:String;
|
public final addr:String;
|
||||||
public var onMessage(default, null):Signal<{pack:GenericPackage,dist:Null<Float>}>;
|
public var onMessage(default, null):Signal<{pack:GenericPackage, dist:Null<Float>}>;
|
||||||
|
|
||||||
private final onMessageTrigger:SignalTrigger<{pack:GenericPackage,dist:Null<Float>}> = Signal.trigger();
|
private final onMessageTrigger:SignalTrigger<{pack:GenericPackage, dist:Null<Float>}> = Signal.trigger();
|
||||||
private final native:cc.periphs.Modem.Modem;
|
private final native:cc.periphs.Modem.Modem;
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
@ -22,9 +22,9 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
this.native = Peripheral.wrap(addr);
|
this.native = Peripheral.wrap(addr);
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
|
|
||||||
KernelEvents.onModemMessage.handle(params ->{
|
KernelEvents.onModemMessage.handle(params -> {
|
||||||
try{
|
try {
|
||||||
if (params.addr == this.addr){
|
if (params.addr == this.addr) {
|
||||||
var pack:GenericPackage = {
|
var pack:GenericPackage = {
|
||||||
fromID: params.message.fromID,
|
fromID: params.message.fromID,
|
||||||
toID: params.message.toID,
|
toID: params.message.toID,
|
||||||
@ -36,7 +36,7 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
|
|
||||||
this.onMessageTrigger.trigger({pack: pack, dist: params.distance});
|
this.onMessageTrigger.trigger({pack: pack, dist: params.distance});
|
||||||
}
|
}
|
||||||
}catch(e:Dynamic){
|
} catch (e:Dynamic) {
|
||||||
Log.error("Error while parsing modem message");
|
Log.error("Error while parsing modem message");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -79,9 +79,9 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseRoutingCost():Int {
|
public function getBaseRoutingCost():Int {
|
||||||
if (this.native.isWireless()){
|
if (this.native.isWireless()) {
|
||||||
return 2; // Prefere messages over cable
|
return 2; // Prefere messages over cable
|
||||||
}else{
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,15 @@ using tink.CoreApi;
|
|||||||
Class responseable for retrieving peripherals.
|
Class responseable for retrieving peripherals.
|
||||||
**/
|
**/
|
||||||
class Peripheral {
|
class Peripheral {
|
||||||
public static function getAllAddresses(): Array<String> {
|
public static function getAllAddresses():Array<String> {
|
||||||
return cc.Peripheral.getNames().toArray();
|
return cc.Peripheral.getNames().toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isPresent(addr: String): Bool {
|
public static function isPresent(addr:String):Bool {
|
||||||
return cc.Peripheral.isPresent(addr);
|
return cc.Peripheral.isPresent(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTypes(addr: String): Array<String> {
|
public static function getTypes(addr:String):Array<String> {
|
||||||
if (!cc.Peripheral.isPresent(addr)) {
|
if (!cc.Peripheral.isPresent(addr)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -27,11 +27,11 @@ class Peripheral {
|
|||||||
return cc.Peripheral.getType(addr).toArray();
|
return cc.Peripheral.getType(addr).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findAddrByType(type: String): Array<String> {
|
public static function findAddrByType(type:String):Array<String> {
|
||||||
return getAllAddresses().filter(addr -> getTypes(addr).contains(type));
|
return getAllAddresses().filter(addr -> getTypes(addr).contains(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function safeGetAddr(addr: String, type: String): Null<String> {
|
private static function safeGetAddr(addr:String, type:String):Null<String> {
|
||||||
if (!isPresent(addr)) {
|
if (!isPresent(addr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -44,15 +44,15 @@ class Peripheral {
|
|||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function inspect(addr: String): Null<{ types: Array<String>, methods: Array<String>}> {
|
public static function inspect(addr:String):Null<{types:Array<String>, methods:Array<String>}> {
|
||||||
if (!isPresent(addr)) {
|
if (!isPresent(addr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var types = getTypes(addr);
|
var types = getTypes(addr);
|
||||||
var methodsMap = cc.Peripheral.getMethods(addr).toArray();
|
var methodsMap = cc.Peripheral.getMethods(addr).toArray();
|
||||||
var methods: Array<String> = [];
|
var methods:Array<String> = [];
|
||||||
|
|
||||||
for (method in methodsMap) {
|
for (method in methodsMap) {
|
||||||
methods.push(method);
|
methods.push(method);
|
||||||
}
|
}
|
||||||
@ -67,8 +67,8 @@ class Peripheral {
|
|||||||
Cast peripheral to a specific type.
|
Cast peripheral to a specific type.
|
||||||
This is a temporary solution, maybe forever.
|
This is a temporary solution, maybe forever.
|
||||||
**/
|
**/
|
||||||
public static function getFromType(addr: String, type: String): Null<IPeripheral> {
|
public static function getFromType(addr:String, type:String):Null<IPeripheral> {
|
||||||
switch (type){
|
switch (type) {
|
||||||
case Computer.TYPE_NAME:
|
case Computer.TYPE_NAME:
|
||||||
return getComputer(addr);
|
return getComputer(addr);
|
||||||
case Screen.TYPE_NAME:
|
case Screen.TYPE_NAME:
|
||||||
@ -88,69 +88,74 @@ class Peripheral {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getScreen(addr: String): Null<Screen> {
|
public static function getScreen(addr:String):Null<Screen> {
|
||||||
var addr = safeGetAddr(addr, Screen.TYPE_NAME);
|
var addr = safeGetAddr(addr, Screen.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Screen(addr);
|
return new Screen(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAllScreens():Array<Screen> {
|
||||||
public static function getAllScreens(): Array<Screen> {
|
return [for (addr in findAddrByType(Screen.TYPE_NAME)) new Screen(addr)];
|
||||||
return [ for (addr in findAddrByType(Screen.TYPE_NAME)) new Screen(addr)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getModem(addr: String): Null<Modem> {
|
public static function getModem(addr:String):Null<Modem> {
|
||||||
var addr = safeGetAddr(addr, Modem.TYPE_NAME);
|
var addr = safeGetAddr(addr, Modem.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Modem(addr);
|
return new Modem(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllModems(): Array<Modem> {
|
public static function getAllModems():Array<Modem> {
|
||||||
return [ for (addr in findAddrByType(Modem.TYPE_NAME)) new Modem(addr)];
|
return [for (addr in findAddrByType(Modem.TYPE_NAME)) new Modem(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDrive(addr: String): Null<Drive> {
|
public static function getDrive(addr:String):Null<Drive> {
|
||||||
var addr = safeGetAddr(addr, Drive.TYPE_NAME);
|
var addr = safeGetAddr(addr, Drive.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Drive(addr);
|
return new Drive(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllDrives(): Array<Drive> {
|
public static function getAllDrives():Array<Drive> {
|
||||||
return [ for (addr in findAddrByType(Drive.TYPE_NAME)) new Drive(addr)];
|
return [for (addr in findAddrByType(Drive.TYPE_NAME)) new Drive(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRedstone(side: String): Redstone {
|
public static function getRedstone(side:String):Redstone {
|
||||||
// TODO: maybe handle restone differently to not duplicate event listeners
|
// TODO: maybe handle restone differently to not duplicate event listeners
|
||||||
return new Redstone(side);
|
return new Redstone(side);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPrinter(addr: String):Null<Printer> {
|
public static function getPrinter(addr:String):Null<Printer> {
|
||||||
var addr = safeGetAddr(addr, Printer.TYPE_NAME);
|
var addr = safeGetAddr(addr, Printer.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Printer(addr);
|
return new Printer(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllPrinters(): Array<Printer> {
|
public static function getAllPrinters():Array<Printer> {
|
||||||
return [ for (addr in findAddrByType(Printer.TYPE_NAME)) new Printer(addr)];
|
return [for (addr in findAddrByType(Printer.TYPE_NAME)) new Printer(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEnergyStorage(addr: String): Null<EnergyStorage> {
|
public static function getEnergyStorage(addr:String):Null<EnergyStorage> {
|
||||||
var addr = safeGetAddr(addr, EnergyStorage.TYPE_NAME);
|
var addr = safeGetAddr(addr, EnergyStorage.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new EnergyStorage(addr);
|
return new EnergyStorage(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllEnergyStorages(): Array<EnergyStorage> {
|
public static function getAllEnergyStorages():Array<EnergyStorage> {
|
||||||
return [ for (addr in findAddrByType(EnergyStorage.TYPE_NAME)) new EnergyStorage(addr)];
|
return [for (addr in findAddrByType(EnergyStorage.TYPE_NAME)) new EnergyStorage(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getComputer(addr: String): Null<Computer> {
|
public static function getComputer(addr:String):Null<Computer> {
|
||||||
var addr = safeGetAddr(addr, Computer.TYPE_NAME);
|
var addr = safeGetAddr(addr, Computer.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Computer(addr);
|
return new Computer(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllComputers(): Array<Computer> {
|
public static function getAllComputers():Array<Computer> {
|
||||||
return [ for (addr in findAddrByType(Computer.TYPE_NAME)) new Computer(addr)];
|
return [for (addr in findAddrByType(Computer.TYPE_NAME)) new Computer(addr)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class Printer implements IPeripheral {
|
|||||||
private final native:cc.periphs.Printer.Printer;
|
private final native:cc.periphs.Printer.Printer;
|
||||||
private final addr:String;
|
private final addr:String;
|
||||||
|
|
||||||
public function new(addr: String) {
|
public function new(addr:String) {
|
||||||
this.native = Peripheral.wrap(addr);
|
this.native = Peripheral.wrap(addr);
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
}
|
}
|
||||||
@ -23,36 +23,34 @@ class Printer implements IPeripheral {
|
|||||||
return TYPE_NAME;
|
return TYPE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(text: String){
|
public function write(text:String) {}
|
||||||
|
|
||||||
}
|
public function getCurserPos():Pos {
|
||||||
|
|
||||||
public function getCurserPos(): Pos {
|
|
||||||
return new Pos({x: 0, y: 0});
|
return new Pos({x: 0, y: 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCurserPos(pos: Pos){
|
public function setCurserPos(pos:Pos) {
|
||||||
this.native.setCursorPos(pos.x, pos.y);
|
this.native.setCursorPos(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPageSize(): Rect {
|
public function getPageSize():Rect {
|
||||||
var pos = this.native.getPageSize();
|
var pos = this.native.getPageSize();
|
||||||
return new Rect({x: 0, y: 0}, {x: pos.x, y: pos.y});
|
return new Rect({x: 0, y: 0}, {x: pos.x, y: pos.y});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newPage(): Bool{
|
public function newPage():Bool {
|
||||||
return this.native.newPage();
|
return this.native.newPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function endPage(): Bool{
|
public function endPage():Bool {
|
||||||
return this.native.endPage();
|
return this.native.endPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPageTitle(title: String){
|
public function setPageTitle(title:String) {
|
||||||
this.native.setPageTitle(title);
|
this.native.setPageTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInkLevel(): Float{
|
public function getInkLevel():Float {
|
||||||
return this.native.getInkLevel();
|
return this.native.getInkLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,33 +7,33 @@ import lib.Color;
|
|||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
abstract BundleMask(Int) from cc.Colors.Color to cc.Colors.Color {
|
abstract BundleMask(Int) from cc.Colors.Color to cc.Colors.Color {
|
||||||
public inline function new(i:Int) {
|
public inline function new(i:Int) {
|
||||||
this = i;
|
this = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:from
|
@:from
|
||||||
public static function fromColor(c: Color) {
|
public static function fromColor(c:Color) {
|
||||||
return new BundleMask(c);
|
return new BundleMask(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:op(A + B)
|
@:op(A + B)
|
||||||
@:op(A | B)
|
@:op(A | B)
|
||||||
public inline function combine(rhs: BundleMask):BundleMask {
|
public inline function combine(rhs:BundleMask):BundleMask {
|
||||||
return this | rhs;
|
return this | rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:op(A + B)
|
@:op(A + B)
|
||||||
@:op(A | B)
|
@:op(A | B)
|
||||||
public inline function combineWithColor(rhs: Color):BundleMask {
|
public inline function combineWithColor(rhs:Color):BundleMask {
|
||||||
return this | rhs;
|
return this | rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getComponents(): ReadOnlyArray<Color> {
|
public function getComponents():ReadOnlyArray<Color> {
|
||||||
var components: Array<Color> = [];
|
var components:Array<Color> = [];
|
||||||
var mask = 1;
|
var mask = 1;
|
||||||
for (i in 0...16){
|
for (i in 0...16) {
|
||||||
if ((this & mask) > 0 ){
|
if ((this & mask) > 0) {
|
||||||
components.push(mask);
|
components.push(mask);
|
||||||
}
|
}
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
@ -57,19 +57,18 @@ class Redstone implements IPeripheral implements IExportable {
|
|||||||
private var bundleInputState:BundleMask;
|
private var bundleInputState:BundleMask;
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
private function new(side: Side) {
|
private function new(side:Side) {
|
||||||
this.addr = side;
|
this.addr = side;
|
||||||
this.onChange = this.onChangeTrigger.asSignal();
|
this.onChange = this.onChangeTrigger.asSignal();
|
||||||
|
|
||||||
updateState();
|
updateState();
|
||||||
|
|
||||||
KernelEvents.onRedstone.handle(()->{
|
KernelEvents.onRedstone.handle(() -> {
|
||||||
if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState != this.getBundledInput())){
|
if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState != this.getBundledInput())) {
|
||||||
updateState();
|
updateState();
|
||||||
this.onChangeTrigger.trigger(null);
|
this.onChangeTrigger.trigger(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddr():String {
|
public function getAddr():String {
|
||||||
@ -87,35 +86,35 @@ class Redstone implements IPeripheral implements IExportable {
|
|||||||
|
|
||||||
public inline function setOutput(on:Bool):Void {
|
public inline function setOutput(on:Bool):Void {
|
||||||
this.analogInputState = 15;
|
this.analogInputState = 15;
|
||||||
cc.Redstone.setOutput(this.addr,on);
|
cc.Redstone.setOutput(this.addr, on);
|
||||||
}
|
}
|
||||||
|
|
||||||
@export("output")
|
@export("output")
|
||||||
public inline function getOutput(): Bool {
|
public inline function getOutput():Bool {
|
||||||
return cc.Redstone.getOutput(this.addr);
|
return cc.Redstone.getOutput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@export("input")
|
@export("input")
|
||||||
public inline function getInput(): Bool {
|
public inline function getInput():Bool {
|
||||||
return cc.Redstone.getInput(this.addr);
|
return cc.Redstone.getInput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function setAnalogOutput(strength:Int): Void {
|
public inline function setAnalogOutput(strength:Int):Void {
|
||||||
this.analogInputState = strength;
|
this.analogInputState = strength;
|
||||||
cc.Redstone.setAnalogOutput(this.addr,strength);
|
cc.Redstone.setAnalogOutput(this.addr, strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getAnalogOutput(): Int {
|
public inline function getAnalogOutput():Int {
|
||||||
return cc.Redstone.getAnalogOutput(this.addr);
|
return cc.Redstone.getAnalogOutput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getAnalogInput(): Int {
|
public inline function getAnalogInput():Int {
|
||||||
return cc.Redstone.getAnalogInput(this.addr);
|
return cc.Redstone.getAnalogInput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function setBundledOutput(output: BundleMask) {
|
public inline function setBundledOutput(output:BundleMask) {
|
||||||
this.bundleInputState = output;
|
this.bundleInputState = output;
|
||||||
cc.Redstone.setBundledOutput(this.addr,output);
|
cc.Redstone.setBundledOutput(this.addr, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getBundledOutput():BundleMask {
|
public inline function getBundledOutput():BundleMask {
|
||||||
@ -126,7 +125,7 @@ class Redstone implements IPeripheral implements IExportable {
|
|||||||
return cc.Redstone.getBundledInput(this.addr);
|
return cc.Redstone.getBundledInput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function testBundledInput(mask: Color): Bool {
|
public inline function testBundledInput(mask:Color):Bool {
|
||||||
return cc.Redstone.testBundledInput(this.addr,mask);
|
return cc.Redstone.testBundledInput(this.addr, mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ class Screen implements TermWriteable implements IPeripheral {
|
|||||||
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>> = Signal.trigger();
|
private final onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
|
||||||
|
|
||||||
public final onResize:Signal<Vec2<Int>>;
|
public final onResize:Signal<Vec2<Int>>;
|
||||||
|
|
||||||
@ -119,6 +119,6 @@ class Screen implements TermWriteable implements IPeripheral {
|
|||||||
this.setBackgroundColor(Black);
|
this.setBackgroundColor(Black);
|
||||||
this.setTextColor(White);
|
this.setTextColor(White);
|
||||||
this.clear();
|
this.clear();
|
||||||
this.setCursorPos(0,0);
|
this.setCursorPos(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ enum abstract Side(String) to String {
|
|||||||
var Back = "back";
|
var Back = "back";
|
||||||
|
|
||||||
@:from
|
@:from
|
||||||
static public function fromString(s: String) {
|
static public function fromString(s:String) {
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case "top":
|
case "top":
|
||||||
return Top;
|
return Top;
|
||||||
|
@ -5,5 +5,5 @@ package kernel.ps;
|
|||||||
**/
|
**/
|
||||||
@:autoBuild(macros.DCEHack.DCEHack.dceInclude())
|
@:autoBuild(macros.DCEHack.DCEHack.dceInclude())
|
||||||
interface Process {
|
interface Process {
|
||||||
public function run(handle: ProcessHandle): Void;
|
public function run(handle:ProcessHandle):Void;
|
||||||
}
|
}
|
||||||
|
@ -4,32 +4,33 @@ import kernel.ps.ProcessManager.PID;
|
|||||||
import kernel.ui.WindowContext;
|
import kernel.ui.WindowContext;
|
||||||
import kernel.ui.WindowManager;
|
import kernel.ui.WindowManager;
|
||||||
import haxe.ds.ReadOnlyArray;
|
import haxe.ds.ReadOnlyArray;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
typedef HandleConfig = {
|
typedef HandleConfig = {
|
||||||
?args: Array<String>,
|
?args:Array<String>,
|
||||||
?onWrite: Callback<String>,
|
?onWrite:Callback<String>,
|
||||||
?onExit: Callback<Bool>,
|
?onExit:Callback<Bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProcessHandle {
|
class ProcessHandle {
|
||||||
public var args(get,null): ReadOnlyArray<String>;
|
public var args(get, null):ReadOnlyArray<String>;
|
||||||
|
|
||||||
private final pid: PID;
|
private final pid:PID;
|
||||||
private final config:HandleConfig;
|
private final config:HandleConfig;
|
||||||
private final closeFuture: Future<Bool>;
|
private final closeFuture:Future<Bool>;
|
||||||
private var closeFutureResolev: Bool -> Void;
|
private var closeFutureResolev:Bool->Void;
|
||||||
private final windowContexts: Array<WindowContext> = [];
|
private final windowContexts:Array<WindowContext> = [];
|
||||||
private final cbLinks:Array<CallbackLink> = [];
|
private final cbLinks:Array<CallbackLink> = [];
|
||||||
private final deferFuncs:Array<Void -> Void> = [];
|
private final deferFuncs:Array<Void->Void> = [];
|
||||||
private var hasExited: Bool = false;
|
private var hasExited:Bool = false;
|
||||||
|
|
||||||
@:allow(kernel.ps.ProcessManager)
|
@:allow(kernel.ps.ProcessManager)
|
||||||
private function new(config: HandleConfig,pid: PID) {
|
private function new(config:HandleConfig, pid:PID) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
|
|
||||||
this.closeFuture = new Future<Bool>((trigger)->{
|
this.closeFuture = new Future<Bool>((trigger) -> {
|
||||||
this.closeFutureResolev = trigger;
|
this.closeFutureResolev = trigger;
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@ -39,42 +40,45 @@ class ProcessHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onExit(): Future<Bool> {
|
public function onExit():Future<Bool> {
|
||||||
return this.closeFuture;
|
return this.closeFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(success: Bool = true): Void {
|
public function close(success:Bool = true):Void {
|
||||||
this.hasExited = true;
|
this.hasExited = true;
|
||||||
this.dispose();
|
this.dispose();
|
||||||
|
|
||||||
EndOfLoop.endOfLoop(() ->{this.closeFutureResolev(success);});
|
EndOfLoop.endOfLoop(() -> {
|
||||||
|
this.closeFutureResolev(success);
|
||||||
|
});
|
||||||
ProcessManager.removeProcess(this.pid);
|
ProcessManager.removeProcess(this.pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(message: String): Void {
|
public function write(message:String):Void {
|
||||||
if (this.hasExited) return;
|
if (this.hasExited)
|
||||||
if (this.config.onWrite != null){
|
return;
|
||||||
|
if (this.config.onWrite != null) {
|
||||||
this.config.onWrite.invoke(message);
|
this.config.onWrite.invoke(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function writeLine(message: String): Void {
|
public function writeLine(message:String):Void {
|
||||||
this.write(message + "\n");
|
this.write(message + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createBufferdWindowContext(): WindowContext {
|
public function createBufferdWindowContext():WindowContext {
|
||||||
var ctx = WindowManager.createNewContext();
|
var ctx = WindowManager.createNewContext();
|
||||||
this.windowContexts.push(ctx);
|
this.windowContexts.push(ctx);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createStatelessWindowContext(): {ctx:WindowContext, setRenderFunc: (() -> Void) -> Void, requestRender:() -> Void} {
|
public function createStatelessWindowContext():{ctx:WindowContext, setRenderFunc:(() -> Void)->Void, requestRender:() -> Void} {
|
||||||
var ctx = WindowManager.createNewStatelessContext();
|
var ctx = WindowManager.createNewStatelessContext();
|
||||||
this.windowContexts.push(ctx.ctx);
|
this.windowContexts.push(ctx.ctx);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWindowContexts(): ReadOnlyArray<WindowContext> {
|
public function getWindowContexts():ReadOnlyArray<WindowContext> {
|
||||||
return this.windowContexts;
|
return this.windowContexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,15 +92,15 @@ class ProcessHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPid(): PID {
|
public function getPid():PID {
|
||||||
return this.pid;
|
return this.pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addCallbackLink(link: CallbackLink) {
|
public function addCallbackLink(link:CallbackLink) {
|
||||||
this.cbLinks.push(link);
|
this.cbLinks.push(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDeferFunc(func: Void -> Void) {
|
public function addDeferFunc(func:Void->Void) {
|
||||||
this.deferFuncs.push(func);
|
this.deferFuncs.push(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,26 +8,26 @@ using tink.CoreApi;
|
|||||||
typedef PID = Int;
|
typedef PID = Int;
|
||||||
|
|
||||||
class ProcessManager {
|
class ProcessManager {
|
||||||
private static final processList = new Map<PID,ProcessHandle>();
|
private static final processList = new Map<PID, ProcessHandle>();
|
||||||
|
|
||||||
public static function run(process:Process, config: HandleConfig):PID {
|
public static function run(process:Process, config:HandleConfig):PID {
|
||||||
var pid = createPID();
|
var pid = createPID();
|
||||||
var handle = new ProcessHandle(config, pid);
|
var handle = new ProcessHandle(config, pid);
|
||||||
|
|
||||||
processList.set(pid, handle);
|
processList.set(pid, handle);
|
||||||
|
|
||||||
try{
|
try {
|
||||||
process.run(handle);
|
process.run(handle);
|
||||||
}catch(e:Dynamic){
|
} catch (e:Dynamic) {
|
||||||
Log.error("Error while running process: " + e);
|
Log.error("Error while running process: " + e);
|
||||||
handle.close(false);
|
handle.close(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function kill(pid: PID) {
|
public static function kill(pid:PID) {
|
||||||
if (!processList.exists(pid)){
|
if (!processList.exists(pid)) {
|
||||||
Log.warn("Trying to kill non-existing process: " + pid);
|
Log.warn("Trying to kill non-existing process: " + pid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ class ProcessManager {
|
|||||||
handle.close();
|
handle.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createPID(): PID {
|
private static function createPID():PID {
|
||||||
// TODO: better PID generation
|
// TODO: better PID generation
|
||||||
|
|
||||||
// generate a random PID
|
// generate a random PID
|
||||||
@ -45,7 +45,7 @@ class ProcessManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:allow(kernel.ui.WindowManager)
|
@:allow(kernel.ui.WindowManager)
|
||||||
private static function getProcess(pid:PID):Null<ProcessHandle>{
|
private static function getProcess(pid:PID):Null<ProcessHandle> {
|
||||||
return processList.get(pid);
|
return processList.get(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,33 +7,32 @@ import kernel.binstore.BinStore;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Service {
|
class Service {
|
||||||
public final binName:String;
|
public final binName:String;
|
||||||
public final name:String;
|
public final name:String;
|
||||||
public final args:Array<String>;
|
public final args:Array<String>;
|
||||||
public var pid:PID;
|
public var pid:PID;
|
||||||
public var ps: Process;
|
public var ps:Process;
|
||||||
|
|
||||||
@:allow(kernel.service.ServiceManager)
|
@:allow(kernel.service.ServiceManager)
|
||||||
private function new(binName: String,name: String,?args: Array<String> ) {
|
private function new(binName:String, name:String, ?args:Array<String>) {
|
||||||
this.binName = binName;
|
this.binName = binName;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.args = args ?? [];
|
this.args = args ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start() {
|
public function start() {
|
||||||
var bin = BinStore.getBinByAlias(this.binName);
|
var bin = BinStore.getBinByAlias(this.binName);
|
||||||
|
|
||||||
if (bin == null){
|
if (bin == null) {
|
||||||
throw new Error('Bin ${this.binName} not found');
|
throw new Error('Bin ${this.binName} not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ps = Type.createInstance(bin.c,this.args);
|
|
||||||
|
|
||||||
this.pid = ProcessManager.run(this.ps,{});
|
this.ps = Type.createInstance(bin.c, this.args);
|
||||||
}
|
|
||||||
|
|
||||||
public function stop() {
|
this.pid = ProcessManager.run(this.ps, {});
|
||||||
ProcessManager.kill(this.pid);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public function stop() {
|
||||||
|
ProcessManager.kill(this.pid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,135 +7,134 @@ import lib.KVStore;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class ServiceManager {
|
class ServiceManager {
|
||||||
private static final services:Map<String,Service> = new Map();
|
private static final services:Map<String, Service> = new Map();
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
startAllEnabled();
|
startAllEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Add a service to be automatically started.
|
|
||||||
**/
|
|
||||||
public static function enable(name: String) {
|
|
||||||
if (!services.exists(name)){
|
|
||||||
return; // Service must be started
|
|
||||||
}
|
|
||||||
|
|
||||||
var store = KVStore.getStoreForClass();
|
/**
|
||||||
|
Add a service to be automatically started.
|
||||||
|
**/
|
||||||
|
public static function enable(name:String) {
|
||||||
|
if (!services.exists(name)) {
|
||||||
|
return; // Service must be started
|
||||||
|
}
|
||||||
|
|
||||||
var enabled = store.get("enabled",[]);
|
var store = KVStore.getStoreForClass();
|
||||||
enabled.push(name);
|
|
||||||
store.set("enabled",enabled);
|
|
||||||
|
|
||||||
store.save();
|
var enabled = store.get("enabled", []);
|
||||||
}
|
enabled.push(name);
|
||||||
|
store.set("enabled", enabled);
|
||||||
|
|
||||||
/**
|
store.save();
|
||||||
Remove a service from being automatically started.
|
}
|
||||||
**/
|
|
||||||
private static function disable(name: String) {
|
|
||||||
var store = KVStore.getStoreForClass();
|
|
||||||
var enabled: Array<String> = store.get("enabled");
|
|
||||||
var index = enabled.indexOf(name);
|
|
||||||
if (index == -1){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enabled.splice(index,1);
|
/**
|
||||||
store.save();
|
Remove a service from being automatically started.
|
||||||
}
|
**/
|
||||||
|
private static function disable(name:String) {
|
||||||
|
var store = KVStore.getStoreForClass();
|
||||||
|
var enabled:Array<String> = store.get("enabled");
|
||||||
|
var index = enabled.indexOf(name);
|
||||||
|
if (index == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
private static function startAllEnabled() {
|
enabled.splice(index, 1);
|
||||||
var store = KVStore.getStoreForClass();
|
store.save();
|
||||||
var enabled: Array<String> = store.get("enabled",[]);
|
}
|
||||||
for (name in enabled){
|
|
||||||
start(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function load(name: String): Null<Service> {
|
private static function startAllEnabled() {
|
||||||
var store = new KVStore('service/${name}');
|
var store = KVStore.getStoreForClass();
|
||||||
store.load();
|
var enabled:Array<String> = store.get("enabled", []);
|
||||||
if (!store.exists("service")){
|
for (name in enabled) {
|
||||||
return null;
|
start(name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return store.get("service");
|
private static function load(name:String):Null<Service> {
|
||||||
}
|
var store = new KVStore('service/${name}');
|
||||||
|
store.load();
|
||||||
|
if (!store.exists("service")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static function register(name: String, binName: String,args: Array<String>): Outcome<Noise,String> {
|
return store.get("service");
|
||||||
if (BinStore.getBinByAlias(binName) == null){
|
}
|
||||||
return Failure("bin not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (load(name) != null){
|
public static function register(name:String, binName:String, args:Array<String>):Outcome<Noise, String> {
|
||||||
return Failure("service already exists");
|
if (BinStore.getBinByAlias(binName) == null) {
|
||||||
}
|
return Failure("bin not found");
|
||||||
|
}
|
||||||
|
|
||||||
var service = new Service(binName,name,args);
|
if (load(name) != null) {
|
||||||
|
return Failure("service already exists");
|
||||||
|
}
|
||||||
|
|
||||||
var store = new KVStore('service/${name}');
|
var service = new Service(binName, name, args);
|
||||||
store.set("service",service);
|
|
||||||
store.save();
|
|
||||||
|
|
||||||
Log.info('Service ${name} registered');
|
var store = new KVStore('service/${name}');
|
||||||
return Success(Noise);
|
store.set("service", service);
|
||||||
}
|
store.save();
|
||||||
|
|
||||||
public static function unregister(name: String): Outcome<Noise,String> {
|
Log.info('Service ${name} registered');
|
||||||
if (services.exists(name)){
|
return Success(Noise);
|
||||||
return Failure("service is running");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
KVStore.removeNamespace('service/${name}');
|
public static function unregister(name:String):Outcome<Noise, String> {
|
||||||
Log.info('Service ${name} unregistered');
|
if (services.exists(name)) {
|
||||||
return Success(Noise);
|
return Failure("service is running");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function start(name: String): Outcome<Noise,String> {
|
|
||||||
var service = load(name);
|
|
||||||
if (service == null){
|
|
||||||
return Failure("service not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
service.start();
|
KVStore.removeNamespace('service/${name}');
|
||||||
services.set(name,service);
|
Log.info('Service ${name} unregistered');
|
||||||
|
return Success(Noise);
|
||||||
|
}
|
||||||
|
|
||||||
Log.info('Service ${name} started');
|
public static function start(name:String):Outcome<Noise, String> {
|
||||||
return Success(Noise);
|
var service = load(name);
|
||||||
}
|
if (service == null) {
|
||||||
|
return Failure("service not found");
|
||||||
|
}
|
||||||
|
|
||||||
public static function stop(name: String): Outcome<Noise,String> {
|
service.start();
|
||||||
if (!services.exists(name)){
|
services.set(name, service);
|
||||||
return Failure("service not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
var service = services.get(name);
|
Log.info('Service ${name} started');
|
||||||
service.stop();
|
return Success(Noise);
|
||||||
services.remove(name);
|
}
|
||||||
|
|
||||||
Log.info('Service ${name} stopped');
|
public static function stop(name:String):Outcome<Noise, String> {
|
||||||
return Success(Noise);
|
if (!services.exists(name)) {
|
||||||
}
|
return Failure("service not found");
|
||||||
|
}
|
||||||
|
|
||||||
public static function listRunning(): Array<String> {
|
var service = services.get(name);
|
||||||
var running = [];
|
service.stop();
|
||||||
for (name in services.keys()){
|
services.remove(name);
|
||||||
running.push(name);
|
|
||||||
}
|
|
||||||
return running;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get(name: String): Null<Dynamic> {
|
Log.info('Service ${name} stopped');
|
||||||
if (!services.exists(name)){
|
return Success(Noise);
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Maybe there is a way to check types here?
|
public static function listRunning():Array<String> {
|
||||||
|
var running = [];
|
||||||
var srv = services.get(name);
|
for (name in services.keys()) {
|
||||||
return srv.ps;
|
running.push(name);
|
||||||
}
|
}
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(name:String):Null<Dynamic> {
|
||||||
|
if (!services.exists(name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Maybe there is a way to check types here?
|
||||||
|
|
||||||
|
var srv = services.get(name);
|
||||||
|
return srv.ps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,42 +36,48 @@ class Turtle {
|
|||||||
public function forward():Outcome<Noise, String> {
|
public function forward():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.forward();
|
var r = cc.Turtle.forward();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveForward();
|
if (r2.isSuccess())
|
||||||
|
INS.moveForward();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function back():Outcome<Noise, String> {
|
public function back():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.back();
|
var r = cc.Turtle.back();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveBackward();
|
if (r2.isSuccess())
|
||||||
|
INS.moveBackward();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function up():Outcome<Noise, String> {
|
public function up():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.up();
|
var r = cc.Turtle.up();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveUp();
|
if (r2.isSuccess())
|
||||||
|
INS.moveUp();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down():Outcome<Noise, String> {
|
public function down():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.down();
|
var r = cc.Turtle.down();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveDown();
|
if (r2.isSuccess())
|
||||||
|
INS.moveDown();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function turnLeft():Outcome<Noise, String> {
|
public function turnLeft():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.turnLeft();
|
var r = cc.Turtle.turnLeft();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.turnRight();
|
if (r2.isSuccess())
|
||||||
|
INS.turnRight();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function turnRight():Outcome<Noise, String> {
|
public function turnRight():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.turnRight();
|
var r = cc.Turtle.turnRight();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.turnRight();
|
if (r2.isSuccess())
|
||||||
|
INS.turnRight();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,15 +103,15 @@ class BufferedVirtualTermWriter implements VirtualTermWriter extends TermBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override function getCursorBlink():Bool {
|
public override function getCursorBlink():Bool {
|
||||||
if (isEnabled()){
|
if (isEnabled()) {
|
||||||
return target.getCursorBlink();
|
return target.getCursorBlink();
|
||||||
}else{
|
} else {
|
||||||
return super.getCursorBlink();
|
return super.getCursorBlink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function setCursorBlink(blink:Bool) {
|
public override function setCursorBlink(blink:Bool) {
|
||||||
if (isEnabled()){
|
if (isEnabled()) {
|
||||||
target.setCursorBlink(blink);
|
target.setCursorBlink(blink);
|
||||||
}
|
}
|
||||||
super.setCursorBlink(blink);
|
super.setCursorBlink(blink);
|
||||||
|
@ -16,12 +16,12 @@ using tink.CoreApi;
|
|||||||
class StatelessVirtualTermWriter implements VirtualTermWriter {
|
class StatelessVirtualTermWriter implements VirtualTermWriter {
|
||||||
public var onResize(default, null):Signal<Vec2<Int>>;
|
public var onResize(default, null):Signal<Vec2<Int>>;
|
||||||
|
|
||||||
private var onResizeTrigger: SignalTrigger<Vec2<Int>> = Signal.trigger();
|
private var onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
|
||||||
private var target:TermWriteable;
|
private var target:TermWriteable;
|
||||||
private var enabled:Bool = false;
|
private var enabled:Bool = false;
|
||||||
private var renderFunc:Null<Void->Void> = null;
|
private var renderFunc:Null<Void->Void> = null;
|
||||||
private var renderRequested:Bool = false;
|
private var renderRequested:Bool = false;
|
||||||
private var onResizeLink: CallbackLink;
|
private var onResizeLink:CallbackLink;
|
||||||
|
|
||||||
@:allow(kernel.ui)
|
@:allow(kernel.ui)
|
||||||
private function new(?target:TermWriteable) {
|
private function new(?target:TermWriteable) {
|
||||||
@ -29,7 +29,7 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
setTarget(target);
|
setTarget(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRenderFunc(func: (Void->Void)) {
|
public function setRenderFunc(func:(Void->Void)) {
|
||||||
this.renderFunc = func;
|
this.renderFunc = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
target.reset();
|
target.reset();
|
||||||
renderFunc();
|
renderFunc();
|
||||||
renderRequested = false;
|
renderRequested = false;
|
||||||
}else{
|
} else {
|
||||||
renderRequested = true;
|
renderRequested = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
|
||||||
if (renderFunc != null){
|
if (renderFunc != null) {
|
||||||
renderFunc();
|
renderFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,11 +101,13 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
//
|
//
|
||||||
|
|
||||||
public inline function write(text:String) {
|
public inline function write(text:String) {
|
||||||
if (enabled) target.write(text);
|
if (enabled)
|
||||||
|
target.write(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function scroll(y:Int) {
|
public inline function scroll(y:Int) {
|
||||||
if (enabled) target.scroll(y);
|
if (enabled)
|
||||||
|
target.scroll(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getCursorPos():Pos {
|
public inline function getCursorPos():Pos {
|
||||||
@ -113,7 +115,8 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inline function setCursorPos(x:Int, y:Int) {
|
public inline function setCursorPos(x:Int, y:Int) {
|
||||||
if (enabled) target.setCursorPos(x, y);
|
if (enabled)
|
||||||
|
target.setCursorPos(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getCursorBlink():Bool {
|
public inline function getCursorBlink():Bool {
|
||||||
@ -121,7 +124,8 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inline function setCursorBlink(blink:Bool) {
|
public inline function setCursorBlink(blink:Bool) {
|
||||||
if (enabled) target.setCursorBlink(blink);
|
if (enabled)
|
||||||
|
target.setCursorBlink(blink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getSize():Vec2<Int> {
|
public inline function getSize():Vec2<Int> {
|
||||||
@ -129,11 +133,13 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inline function clear() {
|
public inline function clear() {
|
||||||
if (enabled) target.clear();
|
if (enabled)
|
||||||
|
target.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function clearLine() {
|
public inline function clearLine() {
|
||||||
if (enabled) target.clearLine();
|
if (enabled)
|
||||||
|
target.clearLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getTextColor():Color {
|
public inline function getTextColor():Color {
|
||||||
@ -141,7 +147,8 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inline function setTextColor(color:Color) {
|
public inline function setTextColor(color:Color) {
|
||||||
if (enabled) target.setTextColor(color);
|
if (enabled)
|
||||||
|
target.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getBackgroundColor():Color {
|
public inline function getBackgroundColor():Color {
|
||||||
@ -149,7 +156,8 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inline function setBackgroundColor(color:Color) {
|
public inline function setBackgroundColor(color:Color) {
|
||||||
if (enabled) target.setBackgroundColor(color);
|
if (enabled)
|
||||||
|
target.setBackgroundColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function isColor():Bool {
|
public inline function isColor():Bool {
|
||||||
@ -157,6 +165,7 @@ class StatelessVirtualTermWriter implements VirtualTermWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inline function reset() {
|
public inline function reset() {
|
||||||
if (enabled) target.reset();
|
if (enabled)
|
||||||
|
target.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class TermBuffer implements TermWriteable {
|
|||||||
private var cursorPos:Pos = {x: 0, y: 0};
|
private var cursorPos:Pos = {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 cursorBlink: Bool = false;
|
private var cursorBlink:Bool = false;
|
||||||
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 final onResize:Signal<Vec2<Int>>;
|
public final onResize:Signal<Vec2<Int>>;
|
||||||
@ -178,6 +178,6 @@ class TermBuffer implements TermWriteable {
|
|||||||
this.setBackgroundColor(Black);
|
this.setBackgroundColor(Black);
|
||||||
this.setTextColor(White);
|
this.setTextColor(White);
|
||||||
this.clear();
|
this.clear();
|
||||||
this.setCursorPos(0,0);
|
this.setCursorPos(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ interface TermWriteable {
|
|||||||
public function getBackgroundColor():Color;
|
public function getBackgroundColor():Color;
|
||||||
public function setBackgroundColor(color:Color):Void;
|
public function setBackgroundColor(color:Color):Void;
|
||||||
public function isColor():Bool;
|
public function isColor():Bool;
|
||||||
|
|
||||||
// public function setPaletteColor(...);
|
// public function setPaletteColor(...);
|
||||||
// public function getPaletteColor(color);
|
// public function getPaletteColor(color);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ using tink.CoreApi;
|
|||||||
class WindowContext implements TermWriteable {
|
class WindowContext implements TermWriteable {
|
||||||
private final writer:VirtualTermWriter;
|
private final writer:VirtualTermWriter;
|
||||||
|
|
||||||
@:allow(kernel.ui.WindowManager) private var eventDelegate: Null<UIEventDelegate>;
|
@:allow(kernel.ui.WindowManager) private var eventDelegate:Null<UIEventDelegate>;
|
||||||
|
|
||||||
public var onClick(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
public var onClick(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
||||||
public var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>;
|
public var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>;
|
||||||
@ -145,7 +145,7 @@ class WindowContext implements TermWriteable {
|
|||||||
Delegate events to an UIEventDelegate.
|
Delegate events to an UIEventDelegate.
|
||||||
Set to null to stop delegating events.
|
Set to null to stop delegating events.
|
||||||
**/
|
**/
|
||||||
public inline function delegateEvents(delegate: Null<UIEventDelegate>){
|
public inline function delegateEvents(delegate:Null<UIEventDelegate>) {
|
||||||
this.eventDelegate = delegate;
|
this.eventDelegate = delegate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,16 +15,17 @@ class WindowManager {
|
|||||||
Depends on: KernelEvents, Peripheral
|
Depends on: KernelEvents, Peripheral
|
||||||
**/
|
**/
|
||||||
private static var currentMainContext:WindowContext;
|
private static var currentMainContext:WindowContext;
|
||||||
|
|
||||||
private static final outputMap:Map<String, WindowContext> = new Map();
|
private static final outputMap:Map<String, WindowContext> = new Map();
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
KernelEvents.onKey.handle(params -> {
|
KernelEvents.onKey.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onKey != null ? foo.onKey.invoke(params) : null;
|
foo.onKey != null ? foo.onKey.invoke(params) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onKeyTrigger.trigger(params);
|
currentMainContext.onKeyTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,10 +33,10 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.onKeyUp.handle(keyCode -> {
|
KernelEvents.onKeyUp.handle(keyCode -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onKeyUp != null ? foo.onKeyUp.invoke(keyCode) : null;
|
foo.onKeyUp != null ? foo.onKeyUp.invoke(keyCode) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onKeyUpTrigger.trigger(keyCode);
|
currentMainContext.onKeyUpTrigger.trigger(keyCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,10 +44,10 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.onMouseClick.handle(params -> {
|
KernelEvents.onMouseClick.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onClick != null ? foo.onClick.invoke(params) : null;
|
foo.onClick != null ? foo.onClick.invoke(params) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onClickTrigger.trigger(params);
|
currentMainContext.onClickTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,10 +55,10 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.onMouseDrag.handle(params -> {
|
KernelEvents.onMouseDrag.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onMouseDrag != null ? foo.onMouseDrag.invoke(params) : null;
|
foo.onMouseDrag != null ? foo.onMouseDrag.invoke(params) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onMouseDragTrigger.trigger(params);
|
currentMainContext.onMouseDragTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,10 +66,10 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.onMouseScroll.handle(params -> {
|
KernelEvents.onMouseScroll.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onMouseScroll != null ? foo.onMouseScroll.invoke(params) : null;
|
foo.onMouseScroll != null ? foo.onMouseScroll.invoke(params) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onMouseScrollTrigger.trigger(params);
|
currentMainContext.onMouseScrollTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,10 +77,10 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.onMouseUp.handle(params -> {
|
KernelEvents.onMouseUp.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onMouseUp != null ? foo.onMouseUp.invoke(params) : null;
|
foo.onMouseUp != null ? foo.onMouseUp.invoke(params) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onMouseUpTrigger.trigger(params);
|
currentMainContext.onMouseUpTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,10 +88,10 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.onPaste.handle(text -> {
|
KernelEvents.onPaste.handle(text -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onPaste != null ? foo.onPaste.invoke(text) : null;
|
foo.onPaste != null ? foo.onPaste.invoke(text) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onPasteTrigger.trigger(text);
|
currentMainContext.onPasteTrigger.trigger(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,10 +103,10 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.onChar.handle(char -> {
|
KernelEvents.onChar.handle(char -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
if (currentMainContext.eventDelegate != null){
|
if (currentMainContext.eventDelegate != null) {
|
||||||
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
foo.onChar != null ? foo.onChar.invoke(char) : null;
|
foo.onChar != null ? foo.onChar.invoke(char) : null;
|
||||||
}else{
|
} else {
|
||||||
currentMainContext.onCharTrigger.trigger(char);
|
currentMainContext.onCharTrigger.trigger(char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +126,7 @@ class WindowManager {
|
|||||||
return newContext;
|
return newContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createNewStatelessContext():{ctx:WindowContext, setRenderFunc:(() -> Void) -> Void, requestRender:Void->Void} {
|
public static function createNewStatelessContext():{ctx:WindowContext, setRenderFunc:(() -> Void)->Void, requestRender:Void->Void} {
|
||||||
var writer = new StatelessVirtualTermWriter();
|
var writer = new StatelessVirtualTermWriter();
|
||||||
var newContext = new WindowContext(writer);
|
var newContext = new WindowContext(writer);
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ class WindowManager {
|
|||||||
context.enable();
|
context.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getContextByPID(pid: PID): ReadOnlyArray<WindowContext> {
|
public static function getContextByPID(pid:PID):ReadOnlyArray<WindowContext> {
|
||||||
var handle = ProcessManager.getProcess(pid);
|
var handle = ProcessManager.getProcess(pid);
|
||||||
if (handle == null) {
|
if (handle == null) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -9,7 +9,7 @@ class BuildInfo {
|
|||||||
**/
|
**/
|
||||||
public static function getGitCommitHash():String {
|
public static function getGitCommitHash():String {
|
||||||
#if !display
|
#if !display
|
||||||
return CompileTime.buildGitCommitSha();
|
return CompileTime.buildGitCommitSha();
|
||||||
#end
|
#end
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@ import kernel.ps.ProcessHandle;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
abstract class CLIAppBase implements Process {
|
abstract class CLIAppBase implements Process {
|
||||||
private var handle: ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
private final _subcommandsSync: Map<String, (Array<String>) -> Bool> = [];
|
private final _subcommandsSync:Map<String, (Array<String>) -> Bool> = [];
|
||||||
private final _subcommandsAsync: Map<String, (Array<String>) -> Future<Bool>> = [];
|
private final _subcommandsAsync:Map<String, (Array<String>) -> Future<Bool>> = [];
|
||||||
private final _subcommandsSynopsis: Array<String> = [];
|
private final _subcommandsSynopsis:Array<String> = [];
|
||||||
|
|
||||||
public function run(handle: ProcessHandle){
|
public function run(handle:ProcessHandle) {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var subcommand = handle.args[0];
|
var subcommand = handle.args[0];
|
||||||
@ -35,15 +35,14 @@ abstract class CLIAppBase implements Process {
|
|||||||
printHelp();
|
printHelp();
|
||||||
return handle.close(false);
|
return handle.close(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerSyncSubcommand(command: String, callback: (Array<String>) -> Bool, synopsis: String = null) {
|
private function registerSyncSubcommand(command:String, callback:(Array<String>) -> Bool, synopsis:String = null) {
|
||||||
_subcommandsSync.set(command, callback);
|
_subcommandsSync.set(command, callback);
|
||||||
_subcommandsSynopsis.push(command + " " + (synopsis ?? ""));
|
_subcommandsSynopsis.push(command + " " + (synopsis ?? ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerAsyncSubcommand(command: String, callback: (Array<String>) -> Future<Bool>, synopsis: String = null) {
|
private function registerAsyncSubcommand(command:String, callback:(Array<String>) -> Future<Bool>, synopsis:String = null) {
|
||||||
_subcommandsAsync.set(command, callback);
|
_subcommandsAsync.set(command, callback);
|
||||||
_subcommandsSynopsis.push(command + " " + (synopsis ?? ""));
|
_subcommandsSynopsis.push(command + " " + (synopsis ?? ""));
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ enum abstract Color(Int) from cc.Colors.Color to cc.Colors.Color {
|
|||||||
|
|
||||||
@:op(A + B)
|
@:op(A + B)
|
||||||
@:op(A | B)
|
@:op(A | B)
|
||||||
public inline function combine(rhs: Color):BundleMask {
|
public inline function combine(rhs:Color):BundleMask {
|
||||||
return this | rhs;
|
return this | rhs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ class Debug {
|
|||||||
Log.debug("CC/MC version:" + ComputerCraft._HOST);
|
Log.debug("CC/MC version:" + ComputerCraft._HOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function printCanvasToConsole(canvas: Canvas) {
|
public static function printCanvasToConsole(canvas:Canvas) {
|
||||||
var lines: Array<String> = [];
|
var lines:Array<String> = [];
|
||||||
|
|
||||||
for (pos => pixel in canvas){
|
for (pos => pixel in canvas) {
|
||||||
if (lines[pos.y] == null) {
|
if (lines[pos.y] == null) {
|
||||||
lines[pos.y] = "";
|
lines[pos.y] = "";
|
||||||
}
|
}
|
||||||
@ -38,14 +38,14 @@ class Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if Debug
|
#if Debug
|
||||||
public static function printKernelEventsCount(){
|
public static function printKernelEventsCount() {
|
||||||
KernelEvents.printListenerCount();
|
KernelEvents.printListenerCount();
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#if webconsole
|
#if webconsole
|
||||||
public static function printWeb(msg:String) {
|
public static function printWeb(msg:String) {
|
||||||
HTTP.request("http://127.0.0.1:8080/"+Net.networkID,msg);
|
HTTP.request("http://127.0.0.1:8080/" + Net.networkID, msg);
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,13 @@ class HomeContext {
|
|||||||
private var ctx:WindowContext = null;
|
private var ctx:WindowContext = null;
|
||||||
private final workspaces:Map<Int, WindowContext> = [];
|
private final workspaces:Map<Int, WindowContext> = [];
|
||||||
private var currentWorkspace:Int = -1;
|
private var currentWorkspace:Int = -1;
|
||||||
private var requestRender: Void->Void;
|
private var requestRender:Void->Void;
|
||||||
private var renderer:RootElement;
|
private var renderer:RootElement;
|
||||||
|
|
||||||
private var selectedOutput:String = "main";
|
private var selectedOutput:String = "main";
|
||||||
private var selectedOutputIndex:Int = -1;
|
private var selectedOutputIndex:Int = -1;
|
||||||
|
|
||||||
private final listedApps:Array<String> = [
|
private final listedApps:Array<String> = ["terminal", "log", "pfclient"];
|
||||||
"terminal",
|
|
||||||
"log",
|
|
||||||
"pfclient"
|
|
||||||
];
|
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
@ -104,7 +100,7 @@ class HomeContext {
|
|||||||
focusContext(contextId);
|
focusContext(contextId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function spawnPs(binName: String) {
|
private function spawnPs(binName:String) {
|
||||||
var bin = BinStore.getBinByAlias(binName);
|
var bin = BinStore.getBinByAlias(binName);
|
||||||
|
|
||||||
if (bin == null) {
|
if (bin == null) {
|
||||||
@ -112,11 +108,11 @@ class HomeContext {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ps = Type.createInstance(bin.c,[]);
|
var ps = Type.createInstance(bin.c, []);
|
||||||
var pid = ProcessManager.run(ps, {});
|
var pid = ProcessManager.run(ps, {});
|
||||||
var lastContextID = -1;
|
var lastContextID = -1;
|
||||||
|
|
||||||
for ( ctx in WindowManager.getContextByPID(pid)){
|
for (ctx in WindowManager.getContextByPID(pid)) {
|
||||||
lastContextID = addContextNextWorkspace(ctx);
|
lastContextID = addContextNextWorkspace(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +137,7 @@ class HomeContext {
|
|||||||
selectedOutput = "main";
|
selectedOutput = "main";
|
||||||
} else {
|
} else {
|
||||||
selectedOutputIndex++;
|
selectedOutputIndex++;
|
||||||
selectedOutput = screenAddr[selectedOutputIndex];
|
selectedOutput = screenAddr[selectedOutputIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
requestRender();
|
requestRender();
|
||||||
@ -150,21 +146,19 @@ class HomeContext {
|
|||||||
private function render() {
|
private function render() {
|
||||||
ctx.setCursorBlink(false);
|
ctx.setCursorBlink(false);
|
||||||
|
|
||||||
var workspaceIDs:Array<Int> = [for (k=>v in workspaces) k];
|
var workspaceIDs:Array<Int> = [for (k => v in workspaces) k];
|
||||||
workspaceIDs.sort((a, b) -> a - b);
|
workspaceIDs.sort((a, b) -> a - b);
|
||||||
|
|
||||||
var children:Array<UIElement> = [
|
var children:Array<UIElement> = [
|
||||||
for (i in workspaceIDs) new TextElement('Switch to ${i + 1}', {uiEvents: {onClick: this.handleSelectContext.bind(i)}})
|
for (i in workspaceIDs)
|
||||||
|
new TextElement('Switch to ${i + 1}', {uiEvents: {onClick: this.handleSelectContext.bind(i)}})
|
||||||
];
|
];
|
||||||
|
|
||||||
for (i in 0...listedApps.length) {
|
for (i in 0...listedApps.length) {
|
||||||
children.push(new TextElement(
|
children.push(new TextElement('Add ${BinStore.getNameByAlias(listedApps[i])}', {uiEvents: {onClick: this.spawnPs.bind(listedApps[i])}}));
|
||||||
'Add ${BinStore.getNameByAlias(listedApps[i])}',
|
|
||||||
{uiEvents: {onClick: this.spawnPs.bind(listedApps[i])}}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
children.push(new TextElement('Output: ${selectedOutput}',{ uiEvents:{ onClick: this.cycleOutput}}));
|
children.push(new TextElement('Output: ${selectedOutput}', {uiEvents: {onClick: this.cycleOutput}}));
|
||||||
children.push(new TextElement('Exit', {style: {bgColor: Red}, uiEvents: {onClick: KernelEvents.shutdown}}));
|
children.push(new TextElement('Exit', {style: {bgColor: Red}, uiEvents: {onClick: KernelEvents.shutdown}}));
|
||||||
|
|
||||||
renderer.setChildren(children);
|
renderer.setChildren(children);
|
||||||
|
@ -4,8 +4,7 @@ package lib;
|
|||||||
Represents an item in the game.
|
Represents an item in the game.
|
||||||
**/
|
**/
|
||||||
abstract Item(String) to String {
|
abstract Item(String) to String {
|
||||||
|
public inline function new(name:String) {
|
||||||
public inline function new(name: String) {
|
|
||||||
// Check if the name is valid. in the format `mod:item_name` e.g. `minecraft:apple`
|
// Check if the name is valid. in the format `mod:item_name` e.g. `minecraft:apple`
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
// make sure to not use regex
|
// make sure to not use regex
|
||||||
@ -13,11 +12,11 @@ abstract Item(String) to String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:from(String)
|
@:from(String)
|
||||||
public static function fromString(s: String) {
|
public static function fromString(s:String) {
|
||||||
return new Item(s);
|
return new Item(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBase(): String {
|
function getBase():String {
|
||||||
return this.split(":")[0];
|
return this.split(":")[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,16 @@ import haxe.ds.StringMap;
|
|||||||
Key value store with persistence.
|
Key value store with persistence.
|
||||||
**/
|
**/
|
||||||
class KVStore {
|
class KVStore {
|
||||||
private var kvStore: StringMap<Dynamic> = new StringMap();
|
private var kvStore:StringMap<Dynamic> = new StringMap();
|
||||||
|
|
||||||
public final namespace:String;
|
public final namespace:String;
|
||||||
|
|
||||||
public function new(namespace: String) {
|
public function new(namespace:String) {
|
||||||
this.namespace = namespace;
|
this.namespace = namespace;
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function removeNamespace(namespace: String): Void {
|
public static function removeNamespace(namespace:String):Void {
|
||||||
var nsFile = getNamespaceFile(namespace);
|
var nsFile = getNamespaceFile(namespace);
|
||||||
FS.delete(nsFile);
|
FS.delete(nsFile);
|
||||||
}
|
}
|
||||||
@ -27,13 +28,13 @@ class KVStore {
|
|||||||
return new KVStore(className);
|
return new KVStore(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getNamespaceFile(namespace: String): String {
|
private static function getNamespaceFile(namespace:String):String {
|
||||||
return '/var/ns/$namespace';
|
return '/var/ns/$namespace';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load() {
|
public function load() {
|
||||||
var nsFile = getNamespaceFile(this.namespace);
|
var nsFile = getNamespaceFile(this.namespace);
|
||||||
if (FS.exists(nsFile)){
|
if (FS.exists(nsFile)) {
|
||||||
var handle = FS.openRead(nsFile);
|
var handle = FS.openRead(nsFile);
|
||||||
parseFile(handle.readAll());
|
parseFile(handle.readAll());
|
||||||
}
|
}
|
||||||
@ -47,20 +48,20 @@ class KVStore {
|
|||||||
handle.close();
|
handle.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseFile(content: String) {
|
private function parseFile(content:String) {
|
||||||
var unserializer = new Unserializer(content);
|
var unserializer = new Unserializer(content);
|
||||||
this.kvStore = unserializer.unserialize();
|
this.kvStore = unserializer.unserialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function set(key: String, value: Dynamic) {
|
public inline function set(key:String, value:Dynamic) {
|
||||||
this.kvStore.set(key,value);
|
this.kvStore.set(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function get<T>(key: String,?orElse:T = null): Null<T> {
|
public inline function get<T>(key:String, ?orElse:T = null):Null<T> {
|
||||||
return this.kvStore.get(key) ?? orElse;
|
return this.kvStore.get(key) ?? orElse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function exists(key: String): Bool {
|
public inline function exists(key:String):Bool {
|
||||||
return this.kvStore.exists(key);
|
return this.kvStore.exists(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,11 +69,11 @@ class KVStore {
|
|||||||
this.kvStore.clear();
|
this.kvStore.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function remove(key: String): Bool {
|
public inline function remove(key:String):Bool {
|
||||||
return this.kvStore.remove(key);
|
return this.kvStore.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function keys(): Iterator<String> {
|
public inline function keys():Iterator<String> {
|
||||||
return this.kvStore.keys();
|
return this.kvStore.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package lib;
|
package lib;
|
||||||
|
|
||||||
class ObjMerge {
|
class ObjMerge {
|
||||||
public static function merge<T>(obj1:T, obj2:T): T {
|
public static function merge<T>(obj1:T, obj2:T):T {
|
||||||
if (obj1 == null) {
|
if (obj1 == null) {
|
||||||
return obj2;
|
return obj2;
|
||||||
}
|
}
|
||||||
@ -19,6 +19,6 @@ class ObjMerge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (rtn:T);
|
return (rtn : T);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@ import lib.Vec.Vec2;
|
|||||||
Reporesents a Point in a 2D `Int` System.
|
Reporesents a Point in a 2D `Int` System.
|
||||||
Basicly a wrapper for Vec2<Int> with some extra functions.
|
Basicly a wrapper for Vec2<Int> with some extra functions.
|
||||||
**/
|
**/
|
||||||
@:forward(x,y)
|
@:forward(x, y)
|
||||||
abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int> {
|
||||||
inline public function new(i:Vec2<Int>) {
|
inline public function new(i:Vec2<Int>) {
|
||||||
this = i;
|
this = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:op(A + B)
|
@:op(A + B)
|
||||||
public function add(rhs: Vec2<Int>):Pos {
|
public function add(rhs:Vec2<Int>):Pos {
|
||||||
return new Pos({
|
return new Pos({
|
||||||
y: this.y + rhs.y,
|
y: this.y + rhs.y,
|
||||||
x: this.x + rhs.x,
|
x: this.x + rhs.x,
|
||||||
@ -21,7 +21,7 @@ abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:op(A - B)
|
@:op(A - B)
|
||||||
public function sub(rhs: Vec2<Int>):Pos {
|
public function sub(rhs:Vec2<Int>):Pos {
|
||||||
return new Pos({
|
return new Pos({
|
||||||
y: this.y - rhs.y,
|
y: this.y - rhs.y,
|
||||||
x: this.x - rhs.x,
|
x: this.x - rhs.x,
|
||||||
@ -29,7 +29,7 @@ abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:op(A * B)
|
@:op(A * B)
|
||||||
public function multiply(rhs: Vec2<Int>): Pos {
|
public function multiply(rhs:Vec2<Int>):Pos {
|
||||||
return new Pos({
|
return new Pos({
|
||||||
y: this.y * rhs.y,
|
y: this.y * rhs.y,
|
||||||
x: this.x * rhs.x,
|
x: this.x * rhs.x,
|
||||||
@ -37,7 +37,7 @@ abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:op(-A)
|
@:op(-A)
|
||||||
public function negate(): Pos {
|
public function negate():Pos {
|
||||||
return new Pos({
|
return new Pos({
|
||||||
y: -this.y,
|
y: -this.y,
|
||||||
x: -this.x,
|
x: -this.x,
|
||||||
|
@ -7,14 +7,14 @@ import lib.Vec.Vec3;
|
|||||||
Basicly a wrapper for Vec3<Float> with some extra functions.
|
Basicly a wrapper for Vec3<Float> with some extra functions.
|
||||||
`Y` represents the height of the point.
|
`Y` represents the height of the point.
|
||||||
**/
|
**/
|
||||||
@:forward(x,y,z)
|
@:forward(x, y, z)
|
||||||
abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float> {
|
||||||
inline public function new(i:Vec3<Float>) {
|
inline public function new(i:Vec3<Float>) {
|
||||||
this = i;
|
this = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:op(A + B)
|
@:op(A + B)
|
||||||
public function add(rhs: Vec3<Float>):Pos3 {
|
public function add(rhs:Vec3<Float>):Pos3 {
|
||||||
return new Pos3({
|
return new Pos3({
|
||||||
y: this.y + rhs.y,
|
y: this.y + rhs.y,
|
||||||
x: this.x + rhs.x,
|
x: this.x + rhs.x,
|
||||||
@ -23,7 +23,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:op(A - B)
|
@:op(A - B)
|
||||||
public function sub(rhs: Vec3<Float>):Pos3 {
|
public function sub(rhs:Vec3<Float>):Pos3 {
|
||||||
return new Pos3({
|
return new Pos3({
|
||||||
y: this.y - rhs.y,
|
y: this.y - rhs.y,
|
||||||
x: this.x - rhs.x,
|
x: this.x - rhs.x,
|
||||||
@ -32,7 +32,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:op(A * B)
|
@:op(A * B)
|
||||||
public function multiplyScalar(rhs: Float): Pos3 {
|
public function multiplyScalar(rhs:Float):Pos3 {
|
||||||
return new Pos3({
|
return new Pos3({
|
||||||
y: this.y * rhs,
|
y: this.y * rhs,
|
||||||
x: this.x * rhs,
|
x: this.x * rhs,
|
||||||
@ -41,7 +41,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:op(A / B)
|
@:op(A / B)
|
||||||
public function divideScalar(rhs: Float): Pos3 {
|
public function divideScalar(rhs:Float):Pos3 {
|
||||||
return new Pos3({
|
return new Pos3({
|
||||||
y: this.y / rhs,
|
y: this.y / rhs,
|
||||||
x: this.x / rhs,
|
x: this.x / rhs,
|
||||||
@ -50,7 +50,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:op(-A)
|
@:op(-A)
|
||||||
public function negate(): Pos3 {
|
public function negate():Pos3 {
|
||||||
return new Pos3({
|
return new Pos3({
|
||||||
y: -this.y,
|
y: -this.y,
|
||||||
x: -this.x,
|
x: -this.x,
|
||||||
@ -58,11 +58,11 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dot(rhs: Vec3<Float>): Float {
|
public function dot(rhs:Vec3<Float>):Float {
|
||||||
return this.x * rhs.x + this.y * rhs.y + this.z * rhs.z;
|
return this.x * rhs.x + this.y * rhs.y + this.z * rhs.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cross(rhs: Vec3<Float>):Pos3 {
|
public function cross(rhs:Vec3<Float>):Pos3 {
|
||||||
return new Pos3({
|
return new Pos3({
|
||||||
x: this.y * rhs.z - this.z * rhs.y,
|
x: this.y * rhs.z - this.z * rhs.y,
|
||||||
y: this.z * rhs.x - this.x * rhs.z,
|
y: this.z * rhs.x - this.x * rhs.z,
|
||||||
|
@ -1,43 +1,42 @@
|
|||||||
package lib;
|
package lib;
|
||||||
|
|
||||||
class Rect {
|
class Rect {
|
||||||
|
|
||||||
private final tl:Pos;
|
private final tl:Pos;
|
||||||
private final br:Pos;
|
private final br:Pos;
|
||||||
|
|
||||||
public function new(p1: Pos,p2:Pos) {
|
public function new(p1:Pos, p2:Pos) {
|
||||||
this.tl = {
|
this.tl = {
|
||||||
x: MathI.min(p1.x,p2.x),
|
x: MathI.min(p1.x, p2.x),
|
||||||
y: MathI.min(p1.y,p2.y)
|
y: MathI.min(p1.y, p2.y)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.br = {
|
this.br = {
|
||||||
x: MathI.max(p1.x,p2.x),
|
x: MathI.max(p1.x, p2.x),
|
||||||
y: MathI.max(p1.y,p2.y)
|
y: MathI.max(p1.y, p2.y)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSize(): Int {
|
public function getSize():Int {
|
||||||
return getWidth() * getHight();
|
return getWidth() * getHight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isInside(p: Pos): Bool {
|
public function isInside(p:Pos):Bool {
|
||||||
return (p.x >= tl.x && p.x <= br.x) && (p.y >= tl.y && p.y <= br.y);
|
return (p.x >= tl.x && p.x <= br.x) && (p.y >= tl.y && p.y <= br.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isOutside(p: Pos): Bool {
|
public function isOutside(p:Pos):Bool {
|
||||||
return !this.isInside(p);
|
return !this.isInside(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHight(): Int {
|
public function getHight():Int {
|
||||||
return br.y - tl.y;
|
return br.y - tl.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWidth(): Int {
|
public function getWidth():Int {
|
||||||
return br.x - tl.x;
|
return br.x - tl.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offset(pos: Pos) {
|
public function offset(pos:Pos) {
|
||||||
tl.x += pos.x;
|
tl.x += pos.x;
|
||||||
tl.y += pos.y;
|
tl.y += pos.y;
|
||||||
br.x += pos.x;
|
br.x += pos.x;
|
||||||
|
@ -12,73 +12,60 @@ import kernel.net.Package.NetworkID;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class RessourceNames {
|
class RessourceNames {
|
||||||
public static function get(name: String, controllerID: NetworkID = -1): Promise<Null<NetworkID>> {
|
public static function get(name:String, controllerID:NetworkID = -1):Promise<Null<NetworkID>> {
|
||||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
if (controllerID == -1)
|
||||||
|
controllerID = KernelSettings.siteController;
|
||||||
|
|
||||||
var payload: GetRequest = {name: name, type: "get"};
|
var payload:GetRequest = {name: name, type: "get"};
|
||||||
|
|
||||||
return Net.sendAndAwait(
|
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload).map((res) -> {
|
||||||
controllerID,
|
switch (res) {
|
||||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
case Success(pkg):
|
||||||
payload
|
return Success(pkg.data.netID);
|
||||||
).map((res)->{
|
case Failure(error):
|
||||||
switch (res){
|
return Failure(error);
|
||||||
case Success(pkg):
|
}
|
||||||
return Success(pkg.data.netID);
|
});
|
||||||
case Failure(error):
|
}
|
||||||
return Failure(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function register(name: String, netID: NetworkID, controllerID: NetworkID = -1): Promise<Bool> {
|
public static function register(name:String, netID:NetworkID, controllerID:NetworkID = -1):Promise<Bool> {
|
||||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
if (controllerID == -1)
|
||||||
|
controllerID = KernelSettings.siteController;
|
||||||
|
|
||||||
var payload: RegisterRequest = {name: name, netID: netID, type: "register"};
|
var payload:RegisterRequest = {name: name, netID: netID, type: "register"};
|
||||||
|
|
||||||
return Net.sendAndAwait(
|
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload).map((res) -> {
|
||||||
controllerID,
|
switch (res) {
|
||||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
case Success(pkg):
|
||||||
payload
|
return Success(pkg.data.success);
|
||||||
).map((res)->{
|
case Failure(error):
|
||||||
switch (res){
|
return Failure(error);
|
||||||
case Success(pkg):
|
}
|
||||||
return Success(pkg.data.success);
|
});
|
||||||
case Failure(error):
|
}
|
||||||
return Failure(error);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function unregister(name: String, controllerID: NetworkID = -1): Promise<Noise> {
|
public static function unregister(name:String, controllerID:NetworkID = -1):Promise<Noise> {
|
||||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
if (controllerID == -1)
|
||||||
|
controllerID = KernelSettings.siteController;
|
||||||
|
|
||||||
var payload: UnregisterRequest = {name: name, type: "unregister"};
|
var payload:UnregisterRequest = {name: name, type: "unregister"};
|
||||||
|
|
||||||
return Net.sendAndAwait(
|
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload);
|
||||||
controllerID,
|
}
|
||||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
|
||||||
payload
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function list(controllerID: NetworkID = -1): Promise<Array<String>> {
|
public static function list(controllerID:NetworkID = -1):Promise<Array<String>> {
|
||||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
if (controllerID == -1)
|
||||||
|
controllerID = KernelSettings.siteController;
|
||||||
|
|
||||||
var payload: ListRequest = {type: "list"};
|
var payload:ListRequest = {type: "list"};
|
||||||
|
|
||||||
return Net.sendAndAwait(
|
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload).map(res -> {
|
||||||
controllerID,
|
switch (res) {
|
||||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
case Success(pkg):
|
||||||
payload
|
return Success(pkg.data);
|
||||||
).map(res->{
|
case Failure(error):
|
||||||
switch (res){
|
return Failure(error);
|
||||||
case Success(pkg):
|
}
|
||||||
return Success(pkg.data);
|
});
|
||||||
case Failure(error):
|
}
|
||||||
return Failure(error);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -6,41 +6,41 @@ import kernel.log.Log;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Export {
|
class Export {
|
||||||
private final exportConfig: ExportConfig;
|
private final exportConfig:ExportConfig;
|
||||||
private final peripheral: IPeripheral;
|
private final peripheral:IPeripheral;
|
||||||
|
|
||||||
public function new<T: IExportable & IPeripheral>(exportPerph: T) {
|
public function new<T:IExportable & IPeripheral>(exportPerph:T) {
|
||||||
this.peripheral = exportPerph;
|
this.peripheral = exportPerph;
|
||||||
this.exportConfig = exportPerph.export();
|
this.exportConfig = exportPerph.export();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleRequest(req: Request): Response {
|
public function handleRequest(req:Request):Response {
|
||||||
switch (req.operation){
|
switch (req.operation) {
|
||||||
case Get:
|
case Get:
|
||||||
return handleGet(req);
|
return handleGet(req);
|
||||||
case Set(value):
|
case Set(value):
|
||||||
//TODO: implement
|
// TODO: implement
|
||||||
return NotFound;
|
return NotFound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleGet(request: Request): Response {
|
private function handleGet(request:Request):Response {
|
||||||
if (!this.exportConfig.getDelegates.exists(request.field)){
|
if (!this.exportConfig.getDelegates.exists(request.field)) {
|
||||||
Log.warn('Requested get field ${request.field} does not exist in ??');
|
Log.warn('Requested get field ${request.field} does not exist in ??');
|
||||||
return NotFound;
|
return NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
var delegate = this.exportConfig.getDelegates.get(request.field);
|
var delegate = this.exportConfig.getDelegates.get(request.field);
|
||||||
var value = delegate(request.index);
|
var value = delegate(request.index);
|
||||||
|
|
||||||
return Get(value);
|
return Get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getType(): String {
|
public function getType():String {
|
||||||
return this.peripheral.getType();
|
return this.peripheral.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddr(): String {
|
public function getAddr():String {
|
||||||
return this.peripheral.getAddr();
|
return this.peripheral.getAddr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,6 @@ package lib.exporter;
|
|||||||
import lib.exporter.Response;
|
import lib.exporter.Response;
|
||||||
|
|
||||||
typedef ExportConfig = {
|
typedef ExportConfig = {
|
||||||
getDelegates: Map<String, Null<Int>->ValueType>,
|
getDelegates:Map<String, Null<Int>->ValueType>,
|
||||||
// setDelegates: Map<String, (ValueType, Null<Int>)->ValueType>,
|
// setDelegates: Map<String, (ValueType, Null<Int>)->ValueType>,
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package lib.exporter;
|
package lib.exporter;
|
||||||
|
|
||||||
interface IExportable {
|
interface IExportable {
|
||||||
public function export(): ExportConfig;
|
public function export():ExportConfig;
|
||||||
}
|
}
|
||||||
|
@ -6,23 +6,22 @@ import kernel.net.Package.NetworkID;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Import {
|
class Import {
|
||||||
public static function get(ressourceLocator: String): Promise<Response> {
|
public static function get(ressourceLocator:String):Promise<Response> {
|
||||||
var request = Request.fromString(ressourceLocator);
|
var request = Request.fromString(ressourceLocator);
|
||||||
|
|
||||||
return RessourceNames.get(request.id).next((response)->{
|
return RessourceNames.get(request.id).next((response) -> {
|
||||||
return performRequest(response,request);
|
return performRequest(response, request);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function performRequest(netID: NetworkID, request: Request): Promise<Response> {
|
private static function performRequest(netID:NetworkID, request:Request):Promise<Response> {
|
||||||
return Net.sendAndAwait(netID,"res",request).map((response)->{
|
return Net.sendAndAwait(netID, "res", request).map((response) -> {
|
||||||
switch (response){
|
switch (response) {
|
||||||
case Success(data):
|
case Success(data):
|
||||||
return Success(cast (data.data, Response));
|
return Success(cast(data.data, Response));
|
||||||
case Failure(error):
|
case Failure(error):
|
||||||
return Failure(error);
|
return Failure(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package lib.exporter;
|
package lib.exporter;
|
||||||
|
|
||||||
enum Operation {
|
enum Operation {
|
||||||
Get;
|
Get;
|
||||||
Set(value: Dynamic);
|
Set(value:Dynamic);
|
||||||
}
|
}
|
||||||
|
@ -4,48 +4,47 @@ import lua.TableTools;
|
|||||||
import lua.NativeStringTools;
|
import lua.NativeStringTools;
|
||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
public final id:String;
|
public final id:String;
|
||||||
public final field:String;
|
public final field:String;
|
||||||
public final index: Null<Int>;
|
public final index:Null<Int>;
|
||||||
public final operation: Operation;
|
public final operation:Operation;
|
||||||
|
|
||||||
public function new(id:String, field:String, index:Null<Int>, operation:Operation) {
|
public function new(id:String, field:String, index:Null<Int>, operation:Operation) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.field = field;
|
this.field = field;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Example:
|
||||||
|
"myfield[2]@myid"
|
||||||
|
"myfield@myid"
|
||||||
|
**/
|
||||||
|
public static function fromString(locator:String):Request {
|
||||||
|
if (StringTools.contains(locator, "[")) {
|
||||||
|
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)%[([%d]+)%]@(%a+)")());
|
||||||
|
|
||||||
/**
|
var field = f[1];
|
||||||
Example:
|
var index = Std.parseInt(f[2]);
|
||||||
"myfield[2]@myid"
|
var id = f[3];
|
||||||
"myfield@myid"
|
|
||||||
**/
|
|
||||||
public static function fromString(locator: String): Request {
|
|
||||||
if (StringTools.contains(locator,"[")){
|
|
||||||
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)%[([%d]+)%]@(%a+)")());
|
|
||||||
|
|
||||||
var field = f[1];
|
return new Request(id, field, index, Get);
|
||||||
var index = Std.parseInt(f[2]);
|
} else {
|
||||||
var id = f[3];
|
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)@(%a+)")());
|
||||||
|
|
||||||
return new Request(id, field, index, Get);
|
var field = f[1];
|
||||||
}else{
|
var id = f[2];
|
||||||
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)@(%a+)")());
|
|
||||||
|
|
||||||
var field = f[1];
|
return new Request(id, field, null, Get);
|
||||||
var id = f[2];
|
}
|
||||||
|
}
|
||||||
return new Request(id, field, null, Get);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toString() {
|
public function toString() {
|
||||||
if (index == null){
|
if (index == null) {
|
||||||
return field + "@" + id;
|
return field + "@" + id;
|
||||||
}else{
|
} else {
|
||||||
return field + "[" + index + "]@" + id;
|
return field + "[" + index + "]@" + id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package lib.exporter;
|
package lib.exporter;
|
||||||
|
|
||||||
enum Response {
|
enum Response {
|
||||||
NotFound;
|
NotFound;
|
||||||
Set;
|
Set;
|
||||||
NotSet;
|
NotSet;
|
||||||
Get(value: ValueType);
|
Get(value:ValueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ValueType {
|
enum ValueType {
|
||||||
Number(value: Int);
|
Number(value:Int);
|
||||||
String(value: String);
|
String(value:String);
|
||||||
Bool(value: Bool);
|
Bool(value:Bool);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class DummyObservable<T> implements Observable<T> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dummy<T>(value: T): Observable<T> {
|
public static function dummy<T>(value:T):Observable<T> {
|
||||||
return new DummyObservable<T>(value);
|
return new DummyObservable<T>(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package lib.observable;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
interface Observable<T> {
|
interface Observable<T> {
|
||||||
public function set(value:T): Void;
|
public function set(value:T):Void;
|
||||||
public function get():T;
|
public function get():T;
|
||||||
public function subscribe(callback:Callback<T>):CallbackLink;
|
public function subscribe(callback:Callback<T>):CallbackLink;
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
package lib.observable;
|
package lib.observable;
|
||||||
|
|
||||||
class ObservableArray<T> extends ObservableValue<Array<T>> {
|
class ObservableArray<T> extends ObservableValue<Array<T>> {
|
||||||
public function new(value: Array<T>) {
|
public function new(value:Array<T>) {
|
||||||
super(value);
|
super(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert(pos: Int, x: T):Void {
|
public function insert(pos:Int, x:T):Void {
|
||||||
this.value.insert(pos,x);
|
this.value.insert(pos, x);
|
||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pop(): Null<T> {
|
public function pop():Null<T> {
|
||||||
var poped = this.pop();
|
var poped = this.pop();
|
||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
return poped;
|
return poped;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function push(x: T):Int {
|
public function push(x:T):Int {
|
||||||
var i = this.value.push(x);
|
var i = this.value.push(x);
|
||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove(x: T): Bool {
|
public function remove(x:T):Bool {
|
||||||
var b = this.value.remove(x);
|
var b = this.value.remove(x);
|
||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resize(len: Int) {
|
public function resize(len:Int) {
|
||||||
this.value.resize(len);
|
this.value.resize(len);
|
||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ class ObservableArray<T> extends ObservableValue<Array<T>> {
|
|||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shift(): Null<T> {
|
public function shift():Null<T> {
|
||||||
var e = this.value.shift();
|
var e = this.value.shift();
|
||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
return e;
|
return e;
|
||||||
@ -49,7 +49,7 @@ class ObservableArray<T> extends ObservableValue<Array<T>> {
|
|||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unshift(x: T):Void {
|
public function unshift(x:T):Void {
|
||||||
this.value.unshift(x);
|
this.value.unshift(x);
|
||||||
this.callbacks.invoke(this.value);
|
this.callbacks.invoke(this.value);
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,15 @@ import kernel.turtle.Turtle;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class TurtleExecuter {
|
class TurtleExecuter {
|
||||||
|
|
||||||
private var instructions:Array<TurtleInstruction>;
|
private var instructions:Array<TurtleInstruction>;
|
||||||
|
|
||||||
public function new(instructions:Array<TurtleInstruction>) {
|
public function new(instructions:Array<TurtleInstruction>) {
|
||||||
this.instructions = instructions;
|
this.instructions = instructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequiredFuel(): Int {
|
public function getRequiredFuel():Int {
|
||||||
var fuel = 0;
|
var fuel = 0;
|
||||||
for(inst in instructions){
|
for (inst in instructions) {
|
||||||
if (inst == Forward || inst == Back || inst == Up || inst == Down) {
|
if (inst == Forward || inst == Back || inst == Up || inst == Down) {
|
||||||
fuel++;
|
fuel++;
|
||||||
}
|
}
|
||||||
@ -25,9 +24,9 @@ class TurtleExecuter {
|
|||||||
return fuel;
|
return fuel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequiredBlocks(): Int {
|
public function getRequiredBlocks():Int {
|
||||||
var blocks = 0;
|
var blocks = 0;
|
||||||
for(inst in instructions){
|
for (inst in instructions) {
|
||||||
switch inst {
|
switch inst {
|
||||||
case Place(_):
|
case Place(_):
|
||||||
blocks++;
|
blocks++;
|
||||||
@ -42,11 +41,11 @@ class TurtleExecuter {
|
|||||||
Return the offset of the turtle after executing the instructions.
|
Return the offset of the turtle after executing the instructions.
|
||||||
The origin is the starting position of the turtle.
|
The origin is the starting position of the turtle.
|
||||||
**/
|
**/
|
||||||
public function getFinalOffset(): {offset: Pos3, faceing: Pos} {
|
public function getFinalOffset():{offset:Pos3, faceing:Pos} {
|
||||||
var pos: Pos3 = {x:0, y:0, z:0};
|
var pos:Pos3 = {x: 0, y: 0, z: 0};
|
||||||
var forwardVec: Pos3 = {x: 1, y: 0, z: 0};
|
var forwardVec:Pos3 = {x: 1, y: 0, z: 0};
|
||||||
|
|
||||||
for (inst in instructions){
|
for (inst in instructions) {
|
||||||
switch inst {
|
switch inst {
|
||||||
case Forward:
|
case Forward:
|
||||||
pos = pos + forwardVec;
|
pos = pos + forwardVec;
|
||||||
@ -55,21 +54,21 @@ class TurtleExecuter {
|
|||||||
case TurnRight:
|
case TurnRight:
|
||||||
forwardVec = {x: -forwardVec.z, z: forwardVec.x, y: forwardVec.y};
|
forwardVec = {x: -forwardVec.z, z: forwardVec.x, y: forwardVec.y};
|
||||||
case TurnLeft:
|
case TurnLeft:
|
||||||
forwardVec = {x: forwardVec.z, z: -forwardVec.x , y: forwardVec.y};
|
forwardVec = {x: forwardVec.z, z: -forwardVec.x, y: forwardVec.y};
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {offset:pos,faceing: new Pos({x:forwardVec.x, y:forwardVec.z})};
|
return {offset: pos, faceing: new Pos({x: forwardVec.x, y: forwardVec.z})};
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function execute() {
|
||||||
for (inst in instructions){
|
for (inst in instructions) {
|
||||||
executeInst(inst);
|
executeInst(inst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function executeInst(instruction: TurtleInstruction): Outcome<Noise,String> {
|
private function executeInst(instruction:TurtleInstruction):Outcome<Noise, String> {
|
||||||
switch instruction {
|
switch instruction {
|
||||||
case Forward:
|
case Forward:
|
||||||
return Turtle.instance.forward();
|
return Turtle.instance.forward();
|
||||||
|
@ -8,11 +8,11 @@ using tink.CoreApi;
|
|||||||
Extends the Turtle kernel.
|
Extends the Turtle kernel.
|
||||||
**/
|
**/
|
||||||
class TurtleExt {
|
class TurtleExt {
|
||||||
public static function getFreeSlots(t: Turtle): Int {
|
public static function getFreeSlots(t:Turtle):Int {
|
||||||
var ret: Int = 0;
|
var ret:Int = 0;
|
||||||
|
|
||||||
for (i in 0...Turtle.MAX_SLOTS){
|
for (i in 0...Turtle.MAX_SLOTS) {
|
||||||
if (t.getItemCount(i) == 0){
|
if (t.getItemCount(i) == 0) {
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,11 +20,11 @@ class TurtleExt {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canPickup(t: Turtle,item: Item): Bool {
|
public static function canPickup(t:Turtle, item:Item):Bool {
|
||||||
for (i in 0...Turtle.MAX_SLOTS){
|
for (i in 0...Turtle.MAX_SLOTS) {
|
||||||
var slotItem = t.getItemDetail(i).orNull();
|
var slotItem = t.getItemDetail(i).orNull();
|
||||||
if (slotItem != null && slotItem.name == item){
|
if (slotItem != null && slotItem.name == item) {
|
||||||
if (t.getItemSpace(i)>0){
|
if (t.getItemSpace(i) > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,12 +33,12 @@ class TurtleExt {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canPickupCount(t: Turtle,item: Item): Int {
|
public static function canPickupCount(t:Turtle, item:Item):Int {
|
||||||
var ret: Int = 0;
|
var ret:Int = 0;
|
||||||
|
|
||||||
for (i in 0...Turtle.MAX_SLOTS){
|
for (i in 0...Turtle.MAX_SLOTS) {
|
||||||
var slotItem = Turtle.instance.getItemDetail(i).orNull();
|
var slotItem = Turtle.instance.getItemDetail(i).orNull();
|
||||||
if (slotItem != null && slotItem.name == item){
|
if (slotItem != null && slotItem.name == item) {
|
||||||
ret += Turtle.instance.getItemSpace(i);
|
ret += Turtle.instance.getItemSpace(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,12 +46,12 @@ class TurtleExt {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getInventory(t: Turtle): Map<Int,{item: Item, count: Int, free: Int}> {
|
public static function getInventory(t:Turtle):Map<Int, {item:Item, count:Int, free:Int}> {
|
||||||
var rtn: Map<Int,{item: Item, count: Int, free: Int}> = new Map();
|
var rtn:Map<Int, {item:Item, count:Int, free:Int}> = new Map();
|
||||||
|
|
||||||
for (i in 0...Turtle.MAX_SLOTS){
|
for (i in 0...Turtle.MAX_SLOTS) {
|
||||||
var slotItem = t.getItemDetail(i).orNull();
|
var slotItem = t.getItemDetail(i).orNull();
|
||||||
if (slotItem != null){
|
if (slotItem != null) {
|
||||||
rtn.set(i, {item: slotItem.name, count: slotItem.count, free: t.getItemSpace(i)});
|
rtn.set(i, {item: slotItem.name, count: slotItem.count, free: t.getItemSpace(i)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,36 +63,30 @@ class TurtleExt {
|
|||||||
Optimize the turtle inventory.
|
Optimize the turtle inventory.
|
||||||
TODO: does not work 100% yet. Can be optimized more i think. Not that it needs to be optimized.
|
TODO: does not work 100% yet. Can be optimized more i think. Not that it needs to be optimized.
|
||||||
**/
|
**/
|
||||||
public static function tidy(t: Turtle) {
|
public static function tidy(t:Turtle) {
|
||||||
var inv = getInventory(t);
|
var inv = getInventory(t);
|
||||||
// For each item in the inventory
|
// For each item in the inventory
|
||||||
for(k1 => v1 in inv){
|
for (k1 => v1 in inv) {
|
||||||
|
if (v1.free == 0 || v1.count == 0) {
|
||||||
if (v1.free == 0 || v1.count == 0){
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(k2 => v2 in inv){
|
for (k2 => v2 in inv) {
|
||||||
|
if (k2 == k1) {
|
||||||
if (k2 == k1){
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v1.item == v2.item && v2.free > 0){
|
if (v1.item == v2.item && v2.free > 0) {
|
||||||
// We can move an item in there
|
// We can move an item in there
|
||||||
t.transfer(k1,k2,v2.free);
|
t.transfer(k1, k2, v2.free);
|
||||||
|
|
||||||
v1.count -= v2.free;
|
v1.count -= v2.free;
|
||||||
if (v1.count <= 0){
|
if (v1.count <= 0) {
|
||||||
inv.remove(k1);
|
inv.remove(k1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ enum TurtleInstruction {
|
|||||||
Down;
|
Down;
|
||||||
TurnLeft;
|
TurnLeft;
|
||||||
TurnRight;
|
TurnRight;
|
||||||
Dig(dir: InteractDirections);
|
Dig(dir:InteractDirections);
|
||||||
Place(dir: InteractDirections);
|
Place(dir:InteractDirections);
|
||||||
PlacseSign(dir: InteractDirections, text: String);
|
PlacseSign(dir:InteractDirections, text:String);
|
||||||
Select(slot: TurtleSlot);
|
Select(slot:TurtleSlot);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package lib.turtle;
|
|||||||
// Check usage of NativeStringTools
|
// Check usage of NativeStringTools
|
||||||
// here https://api.haxe.org/lua/NativeStringTools.html
|
// here https://api.haxe.org/lua/NativeStringTools.html
|
||||||
// and here http://lua-users.org/wiki/StringLibraryTutorial
|
// and here http://lua-users.org/wiki/StringLibraryTutorial
|
||||||
|
|
||||||
import kernel.turtle.Types.TurtleSlot;
|
import kernel.turtle.Types.TurtleSlot;
|
||||||
import kernel.turtle.Turtle;
|
import kernel.turtle.Turtle;
|
||||||
import lua.NativeStringTools;
|
import lua.NativeStringTools;
|
||||||
@ -14,24 +13,21 @@ using tink.CoreApi;
|
|||||||
Save a set of turtle instructions to a string and execute them.
|
Save a set of turtle instructions to a string and execute them.
|
||||||
**/
|
**/
|
||||||
class TurtleInstructionParser {
|
class TurtleInstructionParser {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
public function new() {
|
public function encode(instructions:Array<TurtleInstruction>):String {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function encode(instructions: Array<TurtleInstruction>): String {
|
|
||||||
var s = "";
|
var s = "";
|
||||||
|
|
||||||
var times = 0;
|
var times = 0;
|
||||||
var lastInstruction: TurtleInstruction = null;
|
var lastInstruction:TurtleInstruction = null;
|
||||||
|
|
||||||
for (inst in instructions){
|
for (inst in instructions) {
|
||||||
if (inst == lastInstruction){
|
if (inst == lastInstruction) {
|
||||||
times++;
|
times++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastInstruction != null){
|
if (lastInstruction != null) {
|
||||||
var encoded = encodeInstruction(lastInstruction);
|
var encoded = encodeInstruction(lastInstruction);
|
||||||
s = s + '${times + 1}$encoded';
|
s = s + '${times + 1}$encoded';
|
||||||
}
|
}
|
||||||
@ -46,9 +42,9 @@ class TurtleInstructionParser {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function encodeInstruction(inst: TurtleInstruction): String {
|
private function encodeInstruction(inst:TurtleInstruction):String {
|
||||||
for (k => v in cmdMap){
|
for (k => v in cmdMap) {
|
||||||
if (v == inst){
|
if (v == inst) {
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,15 +59,15 @@ class TurtleInstructionParser {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private function encodeSlot(slot: TurtleSlot): String {
|
private function encodeSlot(slot:TurtleSlot):String {
|
||||||
return String.fromCharCode(slot + 97);
|
return String.fromCharCode(slot + 97);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parse(instructionsString: String): Array<TurtleInstruction> {
|
public function parse(instructionsString:String):Array<TurtleInstruction> {
|
||||||
var rtn: Array<TurtleInstruction> = [];
|
var rtn:Array<TurtleInstruction> = [];
|
||||||
var mfunc = NativeStringTools.gmatch(instructionsString,"%d+%D+");
|
var mfunc = NativeStringTools.gmatch(instructionsString, "%d+%D+");
|
||||||
|
|
||||||
while(true){
|
while (true) {
|
||||||
var found = mfunc();
|
var found = mfunc();
|
||||||
|
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
@ -82,7 +78,7 @@ class TurtleInstructionParser {
|
|||||||
var command = NativeStringTools.match(found, "%D+");
|
var command = NativeStringTools.match(found, "%D+");
|
||||||
|
|
||||||
var cmd = cmdMap.get(command);
|
var cmd = cmdMap.get(command);
|
||||||
if (cmd != null){
|
if (cmd != null) {
|
||||||
rtn = rtn.concat([for (i in 0...times) cmd]);
|
rtn = rtn.concat([for (i in 0...times) cmd]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +92,7 @@ class TurtleInstructionParser {
|
|||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function parseSlot(slot: String): TurtleSlot {
|
private static function parseSlot(slot:String):TurtleSlot {
|
||||||
var slot = slot.charCodeAt(0) - 97;
|
var slot = slot.charCodeAt(0) - 97;
|
||||||
|
|
||||||
if (slot < 0 || slot > Turtle.MAX_SLOTS) {
|
if (slot < 0 || slot > Turtle.MAX_SLOTS) {
|
||||||
@ -107,19 +103,8 @@ class TurtleInstructionParser {
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
private var cmdMap:Map<String,TurtleInstruction> = [
|
private var cmdMap:Map<String, TurtleInstruction> = [
|
||||||
"a" => Forward,
|
"a" => Forward, "b" => Back, "c" => TurnLeft, "d" => TurnRight, "e" => Up, "f" => Down, "g" => Dig(Front), "h" => Dig(Up), "i" => Dig(Down),
|
||||||
"b" => Back,
|
"j" => Place(Front), "k" => Place(Up), "l" => Place(Down),
|
||||||
"c" => TurnLeft,
|
|
||||||
"d" => TurnRight,
|
|
||||||
"e" => Up,
|
|
||||||
"f" => Down,
|
|
||||||
"g" => Dig(Front),
|
|
||||||
"h" => Dig(Up),
|
|
||||||
"i" => Dig(Down),
|
|
||||||
"j" => Place(Front),
|
|
||||||
"k" => Place(Up),
|
|
||||||
"l" => Place(Down),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import lib.Pos;
|
|||||||
import lib.Rect;
|
import lib.Rect;
|
||||||
import kernel.ui.Pixel;
|
import kernel.ui.Pixel;
|
||||||
|
|
||||||
abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pixel>>{
|
abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pixel>> {
|
||||||
inline public function new() {
|
inline public function new() {
|
||||||
this = [[]];
|
this = [[]];
|
||||||
}
|
}
|
||||||
@ -62,8 +62,8 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBounds(): Rect {
|
public function getBounds():Rect {
|
||||||
return new Rect({x:0,y:0},{
|
return new Rect({x: 0, y: 0}, {
|
||||||
x: maxWidth() - 1,
|
x: maxWidth() - 1,
|
||||||
y: height() - 1
|
y: height() - 1
|
||||||
});
|
});
|
||||||
@ -72,9 +72,9 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
|
|||||||
/**
|
/**
|
||||||
Renders the canvas directly to the context
|
Renders the canvas directly to the context
|
||||||
**/
|
**/
|
||||||
public function renderToContext(ctx: WindowContext){
|
public function renderToContext(ctx:WindowContext) {
|
||||||
var lastBgColor: Color = null;
|
var lastBgColor:Color = null;
|
||||||
var lastTextColor: Color = null;
|
var lastTextColor:Color = null;
|
||||||
|
|
||||||
for (lineIndex => line in this) {
|
for (lineIndex => line in this) {
|
||||||
if (line == null || line.length == 0) {
|
if (line == null || line.length == 0) {
|
||||||
@ -126,7 +126,7 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CanvasKeyValueIterator {
|
class CanvasKeyValueIterator {
|
||||||
private final canvas:Array<Array<Pixel>> ;
|
private final canvas:Array<Array<Pixel>>;
|
||||||
private var index:Null<Pos> = {x: 0, y: 0};
|
private var index:Null<Pos> = {x: 0, y: 0};
|
||||||
private var nextIndex:Null<Pos> = null;
|
private var nextIndex:Null<Pos> = null;
|
||||||
|
|
||||||
@ -134,14 +134,14 @@ class CanvasKeyValueIterator {
|
|||||||
private function new(canvas:Array<Array<Pixel>>) {
|
private function new(canvas:Array<Array<Pixel>>) {
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
|
|
||||||
if (!isValidPos(this.index)){
|
if (!isValidPos(this.index)) {
|
||||||
this.index = nextValidPixel();
|
this.index = nextValidPixel();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nextIndex = nextValidPixel();
|
this.nextIndex = nextValidPixel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isValidPos(pos: Pos): Bool {
|
private function isValidPos(pos:Pos):Bool {
|
||||||
if (this.canvas[pos.y] == null) {
|
if (this.canvas[pos.y] == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -157,19 +157,19 @@ class CanvasKeyValueIterator {
|
|||||||
return this.index != null;
|
return this.index != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function nextValidPixel(): Null<Pos> {
|
private function nextValidPixel():Null<Pos> {
|
||||||
if (this.index == null) {
|
if (this.index == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var startX = this.index.x + 1;
|
var startX = this.index.x + 1;
|
||||||
|
|
||||||
for (y in this.index.y...this.canvas.length){
|
for (y in this.index.y...this.canvas.length) {
|
||||||
if (this.canvas[y] == null) {
|
if (this.canvas[y] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x in startX...(this.canvas[y].length)){
|
for (x in startX...(this.canvas[y].length)) {
|
||||||
if (this.canvas[y][x] == null) {
|
if (this.canvas[y][x] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -191,7 +191,6 @@ class CanvasKeyValueIterator {
|
|||||||
this.index = this.nextIndex;
|
this.index = this.nextIndex;
|
||||||
this.nextIndex = nextValidPixel();
|
this.nextIndex = nextValidPixel();
|
||||||
|
|
||||||
|
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,6 @@ package lib.ui;
|
|||||||
import lib.Color;
|
import lib.Color;
|
||||||
|
|
||||||
typedef Style = {
|
typedef Style = {
|
||||||
public var ?fgColor: Color;
|
public var ?fgColor:Color;
|
||||||
public var ?bgColor: Color;
|
public var ?bgColor:Color;
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,5 @@ import kernel.ui.WindowContext;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
abstract class UIApp {
|
abstract class UIApp {
|
||||||
public abstract function invoke(context: WindowContext): Future<Bool>;
|
public abstract function invoke(context:WindowContext):Future<Bool>;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class RootElement implements UIElement {
|
|||||||
this.children = children;
|
this.children = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render(bounds: Pos):Canvas {
|
public function render(bounds:Pos):Canvas {
|
||||||
var canvas = new Canvas();
|
var canvas = new Canvas();
|
||||||
var offset = new Pos({x: 0, y: 0});
|
var offset = new Pos({x: 0, y: 0});
|
||||||
|
|
||||||
@ -48,11 +48,11 @@ class RootElement implements UIElement {
|
|||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle(title: String) {
|
public function setTitle(title:String) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function hasTitle(): Bool {
|
private inline function hasTitle():Bool {
|
||||||
return title != "";
|
return title != "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class TextElement implements UIElement {
|
|||||||
private final uiEvents:UIEvents;
|
private final uiEvents:UIEvents;
|
||||||
private final style:Style;
|
private final style:Style;
|
||||||
|
|
||||||
public function new(text:String, ?props: {?style:Style, ?uiEvents:UIEvents}) {
|
public function new(text:String, ?props:{?style:Style, ?uiEvents:UIEvents}) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.uiEvents = props?.uiEvents;
|
this.uiEvents = props?.uiEvents;
|
||||||
this.style = props?.style ?? {fgColor: White, bgColor: Black};
|
this.style = props?.style ?? {fgColor: White, bgColor: Black};
|
||||||
@ -26,7 +26,7 @@ class TextElement implements UIElement {
|
|||||||
return uiEvents;
|
return uiEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render(bounds: Pos):Canvas {
|
public function render(bounds:Pos):Canvas {
|
||||||
var canvas = new Canvas();
|
var canvas = new Canvas();
|
||||||
for (i in 0...this.text.length) {
|
for (i in 0...this.text.length) {
|
||||||
var c = this.text.charAt(i);
|
var c = this.text.charAt(i);
|
||||||
|
@ -3,5 +3,5 @@ package lib.ui.elements;
|
|||||||
import lib.ui.rendere.UIEventDelegate;
|
import lib.ui.rendere.UIEventDelegate;
|
||||||
|
|
||||||
interface UIElement extends UIEventDelegate {
|
interface UIElement extends UIEventDelegate {
|
||||||
public function render(bounds: Pos):Canvas;
|
public function render(bounds:Pos):Canvas;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package lib.ui.rendere;
|
package lib.ui.rendere;
|
||||||
|
|
||||||
class List implements UIEventDelegate{
|
class List implements UIEventDelegate {
|
||||||
private final onElementClick: Null<Int->Void>;
|
private final onElementClick:Null<Int->Void>;
|
||||||
|
|
||||||
public function new(?onElementClick: Int->Void) {
|
public function new(?onElementClick:Int->Void) {
|
||||||
this.onElementClick = onElementClick;
|
this.onElementClick = onElementClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render(list:Array<String>): Canvas {
|
public function render(list:Array<String>):Canvas {
|
||||||
var canvas = new Canvas();
|
var canvas = new Canvas();
|
||||||
for (line in 0...list.length) {
|
for (line in 0...list.length) {
|
||||||
for (char in 0...list[line].length) {
|
for (char in 0...list[line].length) {
|
||||||
@ -22,14 +22,14 @@ class List implements UIEventDelegate{
|
|||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEventHandlers(): UIEvents{
|
public function getEventHandlers():UIEvents {
|
||||||
return {
|
return {
|
||||||
onClick: handleClick
|
onClick: handleClick
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handleClick(e: {button:kernel.ButtonType, pos:Pos}): Void{
|
private function handleClick(e:{button:kernel.ButtonType, pos:Pos}):Void {
|
||||||
if (this.onElementClick == null){
|
if (this.onElementClick == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package lib.ui.rendere;
|
package lib.ui.rendere;
|
||||||
|
|
||||||
interface UIEventDelegate {
|
interface UIEventDelegate {
|
||||||
public function getEventHandlers(): UIEvents;
|
public function getEventHandlers():UIEvents;
|
||||||
}
|
}
|
||||||
|
@ -2,44 +2,43 @@ package macros;
|
|||||||
|
|
||||||
import haxe.macro.Context;
|
import haxe.macro.Context;
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
|
|
||||||
using Lambda;
|
using Lambda;
|
||||||
|
|
||||||
|
|
||||||
class DCEHack {
|
class DCEHack {
|
||||||
|
public static final classes:Array<haxe.macro.Type> = [];
|
||||||
|
|
||||||
public static final classes: Array<haxe.macro.Type> = [];
|
macro static public function dceInclude():Array<Field> {
|
||||||
|
#if !display
|
||||||
macro static public function dceInclude(): Array<Field> {
|
var localClass = Context.getLocalClass();
|
||||||
#if !display
|
|
||||||
var localClass = Context.getLocalClass();
|
|
||||||
|
|
||||||
if (localClass == null){
|
if (localClass == null) {
|
||||||
return Context.getBuildFields();
|
return Context.getBuildFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore abstract classes
|
// Ignore abstract classes
|
||||||
if (localClass.get().isAbstract){
|
if (localClass.get().isAbstract) {
|
||||||
return Context.getBuildFields();
|
return Context.getBuildFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
classes.push(Context.getLocalType());
|
classes.push(Context.getLocalType());
|
||||||
#end
|
#end
|
||||||
return Context.getBuildFields();
|
return Context.getBuildFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
macro static public function dceGenerateCreate(){
|
macro static public function dceGenerateCreate() {
|
||||||
var exprs = [];
|
var exprs = [];
|
||||||
|
|
||||||
for (c in classes){
|
for (c in classes) {
|
||||||
switch (c){
|
switch (c) {
|
||||||
case TInst(_.get() => t, _):
|
case TInst(_.get() => t, _):
|
||||||
var path: TypePath = {pack: t.pack, name: t.name};
|
var path:TypePath = {pack: t.pack, name: t.name};
|
||||||
exprs.push(macro new $path());
|
exprs.push(macro new $path());
|
||||||
default:
|
default:
|
||||||
Context.error("Unknown type: " + c, Context.currentPos());
|
Context.error("Unknown type: " + c, Context.currentPos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return macro return $a{exprs};
|
return macro return $a{exprs};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user