BIG FORMATING COMMIT
This commit is contained in:
@@ -9,7 +9,7 @@ class BuildInfo {
|
||||
**/
|
||||
public static function getGitCommitHash():String {
|
||||
#if !display
|
||||
return CompileTime.buildGitCommitSha();
|
||||
return CompileTime.buildGitCommitSha();
|
||||
#end
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import kernel.ps.ProcessHandle;
|
||||
using tink.CoreApi;
|
||||
|
||||
abstract class CLIAppBase implements Process {
|
||||
private var handle: ProcessHandle;
|
||||
private var handle:ProcessHandle;
|
||||
|
||||
private final _subcommandsSync: Map<String, (Array<String>) -> Bool> = [];
|
||||
private final _subcommandsAsync: Map<String, (Array<String>) -> Future<Bool>> = [];
|
||||
private final _subcommandsSynopsis: Array<String> = [];
|
||||
private final _subcommandsSync:Map<String, (Array<String>) -> Bool> = [];
|
||||
private final _subcommandsAsync:Map<String, (Array<String>) -> Future<Bool>> = [];
|
||||
private final _subcommandsSynopsis:Array<String> = [];
|
||||
|
||||
public function run(handle: ProcessHandle){
|
||||
public function run(handle:ProcessHandle) {
|
||||
this.handle = handle;
|
||||
|
||||
var subcommand = handle.args[0];
|
||||
@@ -35,15 +35,14 @@ abstract class CLIAppBase implements Process {
|
||||
printHelp();
|
||||
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);
|
||||
_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);
|
||||
_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)
|
||||
public inline function combine(rhs: Color):BundleMask {
|
||||
public inline function combine(rhs:Color):BundleMask {
|
||||
return this | rhs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ class Debug {
|
||||
Log.debug("CC/MC version:" + ComputerCraft._HOST);
|
||||
}
|
||||
|
||||
public static function printCanvasToConsole(canvas: Canvas) {
|
||||
var lines: Array<String> = [];
|
||||
public static function printCanvasToConsole(canvas:Canvas) {
|
||||
var lines:Array<String> = [];
|
||||
|
||||
for (pos => pixel in canvas){
|
||||
for (pos => pixel in canvas) {
|
||||
if (lines[pos.y] == null) {
|
||||
lines[pos.y] = "";
|
||||
}
|
||||
@@ -38,14 +38,14 @@ class Debug {
|
||||
}
|
||||
|
||||
#if Debug
|
||||
public static function printKernelEventsCount(){
|
||||
public static function printKernelEventsCount() {
|
||||
KernelEvents.printListenerCount();
|
||||
}
|
||||
#end
|
||||
|
||||
#if webconsole
|
||||
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
|
||||
}
|
||||
|
||||
@@ -25,17 +25,13 @@ class HomeContext {
|
||||
private var ctx:WindowContext = null;
|
||||
private final workspaces:Map<Int, WindowContext> = [];
|
||||
private var currentWorkspace:Int = -1;
|
||||
private var requestRender: Void->Void;
|
||||
private var requestRender:Void->Void;
|
||||
private var renderer:RootElement;
|
||||
|
||||
|
||||
private var selectedOutput:String = "main";
|
||||
private var selectedOutputIndex:Int = -1;
|
||||
|
||||
private final listedApps:Array<String> = [
|
||||
"terminal",
|
||||
"log",
|
||||
"pfclient"
|
||||
];
|
||||
private final listedApps:Array<String> = ["terminal", "log", "pfclient"];
|
||||
|
||||
public function new() {}
|
||||
|
||||
@@ -104,7 +100,7 @@ class HomeContext {
|
||||
focusContext(contextId);
|
||||
}
|
||||
|
||||
private function spawnPs(binName: String) {
|
||||
private function spawnPs(binName:String) {
|
||||
var bin = BinStore.getBinByAlias(binName);
|
||||
|
||||
if (bin == null) {
|
||||
@@ -112,11 +108,11 @@ class HomeContext {
|
||||
return;
|
||||
}
|
||||
|
||||
var ps = Type.createInstance(bin.c,[]);
|
||||
var ps = Type.createInstance(bin.c, []);
|
||||
var pid = ProcessManager.run(ps, {});
|
||||
var lastContextID = -1;
|
||||
|
||||
for ( ctx in WindowManager.getContextByPID(pid)){
|
||||
for (ctx in WindowManager.getContextByPID(pid)) {
|
||||
lastContextID = addContextNextWorkspace(ctx);
|
||||
}
|
||||
|
||||
@@ -141,7 +137,7 @@ class HomeContext {
|
||||
selectedOutput = "main";
|
||||
} else {
|
||||
selectedOutputIndex++;
|
||||
selectedOutput = screenAddr[selectedOutputIndex];
|
||||
selectedOutput = screenAddr[selectedOutputIndex];
|
||||
}
|
||||
|
||||
requestRender();
|
||||
@@ -150,21 +146,19 @@ class HomeContext {
|
||||
private function render() {
|
||||
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);
|
||||
|
||||
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) {
|
||||
children.push(new TextElement(
|
||||
'Add ${BinStore.getNameByAlias(listedApps[i])}',
|
||||
{uiEvents: {onClick: this.spawnPs.bind(listedApps[i])}}
|
||||
));
|
||||
children.push(new TextElement('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}}));
|
||||
|
||||
renderer.setChildren(children);
|
||||
|
||||
@@ -4,8 +4,7 @@ package lib;
|
||||
Represents an item in the game.
|
||||
**/
|
||||
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`
|
||||
// TODO: implement
|
||||
// make sure to not use regex
|
||||
@@ -13,11 +12,11 @@ abstract Item(String) to String {
|
||||
}
|
||||
|
||||
@:from(String)
|
||||
public static function fromString(s: String) {
|
||||
public static function fromString(s:String) {
|
||||
return new Item(s);
|
||||
}
|
||||
|
||||
function getBase(): String {
|
||||
function getBase():String {
|
||||
return this.split(":")[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,16 @@ import haxe.ds.StringMap;
|
||||
Key value store with persistence.
|
||||
**/
|
||||
class KVStore {
|
||||
private var kvStore: StringMap<Dynamic> = new StringMap();
|
||||
private var kvStore:StringMap<Dynamic> = new StringMap();
|
||||
|
||||
public final namespace:String;
|
||||
|
||||
public function new(namespace: String) {
|
||||
public function new(namespace:String) {
|
||||
this.namespace = namespace;
|
||||
this.load();
|
||||
}
|
||||
|
||||
public static function removeNamespace(namespace: String): Void {
|
||||
public static function removeNamespace(namespace:String):Void {
|
||||
var nsFile = getNamespaceFile(namespace);
|
||||
FS.delete(nsFile);
|
||||
}
|
||||
@@ -27,13 +28,13 @@ class KVStore {
|
||||
return new KVStore(className);
|
||||
}
|
||||
|
||||
private static function getNamespaceFile(namespace: String): String {
|
||||
private static function getNamespaceFile(namespace:String):String {
|
||||
return '/var/ns/$namespace';
|
||||
}
|
||||
|
||||
public function load() {
|
||||
var nsFile = getNamespaceFile(this.namespace);
|
||||
if (FS.exists(nsFile)){
|
||||
if (FS.exists(nsFile)) {
|
||||
var handle = FS.openRead(nsFile);
|
||||
parseFile(handle.readAll());
|
||||
}
|
||||
@@ -47,20 +48,20 @@ class KVStore {
|
||||
handle.close();
|
||||
}
|
||||
|
||||
private function parseFile(content: String) {
|
||||
private function parseFile(content:String) {
|
||||
var unserializer = new Unserializer(content);
|
||||
this.kvStore = unserializer.unserialize();
|
||||
}
|
||||
|
||||
public inline function set(key: String, value: Dynamic) {
|
||||
this.kvStore.set(key,value);
|
||||
public inline function set(key:String, value:Dynamic) {
|
||||
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;
|
||||
}
|
||||
|
||||
public inline function exists(key: String): Bool {
|
||||
public inline function exists(key:String):Bool {
|
||||
return this.kvStore.exists(key);
|
||||
}
|
||||
|
||||
@@ -68,11 +69,11 @@ class KVStore {
|
||||
this.kvStore.clear();
|
||||
}
|
||||
|
||||
public inline function remove(key: String): Bool {
|
||||
public inline function remove(key:String):Bool {
|
||||
return this.kvStore.remove(key);
|
||||
}
|
||||
|
||||
public inline function keys(): Iterator<String> {
|
||||
public inline function keys():Iterator<String> {
|
||||
return this.kvStore.keys();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package lib;
|
||||
|
||||
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) {
|
||||
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.
|
||||
Basicly a wrapper for Vec2<Int> with some extra functions.
|
||||
**/
|
||||
@:forward(x,y)
|
||||
abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
||||
@:forward(x, y)
|
||||
abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int> {
|
||||
inline public function new(i:Vec2<Int>) {
|
||||
this = i;
|
||||
}
|
||||
|
||||
@:op(A + B)
|
||||
public function add(rhs: Vec2<Int>):Pos {
|
||||
public function add(rhs:Vec2<Int>):Pos {
|
||||
return new Pos({
|
||||
y: this.y + rhs.y,
|
||||
x: this.x + rhs.x,
|
||||
@@ -21,7 +21,7 @@ abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
||||
}
|
||||
|
||||
@:op(A - B)
|
||||
public function sub(rhs: Vec2<Int>):Pos {
|
||||
public function sub(rhs:Vec2<Int>):Pos {
|
||||
return new Pos({
|
||||
y: this.y - rhs.y,
|
||||
x: this.x - rhs.x,
|
||||
@@ -29,7 +29,7 @@ abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
||||
}
|
||||
|
||||
@:op(A * B)
|
||||
public function multiply(rhs: Vec2<Int>): Pos {
|
||||
public function multiply(rhs:Vec2<Int>):Pos {
|
||||
return new Pos({
|
||||
y: this.y * rhs.y,
|
||||
x: this.x * rhs.x,
|
||||
@@ -37,7 +37,7 @@ abstract Pos(Vec2<Int>) from Vec2<Int> to Vec2<Int>{
|
||||
}
|
||||
|
||||
@:op(-A)
|
||||
public function negate(): Pos {
|
||||
public function negate():Pos {
|
||||
return new Pos({
|
||||
y: -this.y,
|
||||
x: -this.x,
|
||||
|
||||
@@ -7,14 +7,14 @@ import lib.Vec.Vec3;
|
||||
Basicly a wrapper for Vec3<Float> with some extra functions.
|
||||
`Y` represents the height of the point.
|
||||
**/
|
||||
@:forward(x,y,z)
|
||||
abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
||||
@:forward(x, y, z)
|
||||
abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float> {
|
||||
inline public function new(i:Vec3<Float>) {
|
||||
this = i;
|
||||
}
|
||||
|
||||
@:op(A + B)
|
||||
public function add(rhs: Vec3<Float>):Pos3 {
|
||||
public function add(rhs:Vec3<Float>):Pos3 {
|
||||
return new Pos3({
|
||||
y: this.y + rhs.y,
|
||||
x: this.x + rhs.x,
|
||||
@@ -23,7 +23,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
||||
}
|
||||
|
||||
@:op(A - B)
|
||||
public function sub(rhs: Vec3<Float>):Pos3 {
|
||||
public function sub(rhs:Vec3<Float>):Pos3 {
|
||||
return new Pos3({
|
||||
y: this.y - rhs.y,
|
||||
x: this.x - rhs.x,
|
||||
@@ -32,7 +32,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
||||
}
|
||||
|
||||
@:op(A * B)
|
||||
public function multiplyScalar(rhs: Float): Pos3 {
|
||||
public function multiplyScalar(rhs:Float):Pos3 {
|
||||
return new Pos3({
|
||||
y: this.y * rhs,
|
||||
x: this.x * rhs,
|
||||
@@ -41,7 +41,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
||||
}
|
||||
|
||||
@:op(A / B)
|
||||
public function divideScalar(rhs: Float): Pos3 {
|
||||
public function divideScalar(rhs:Float):Pos3 {
|
||||
return new Pos3({
|
||||
y: this.y / rhs,
|
||||
x: this.x / rhs,
|
||||
@@ -50,7 +50,7 @@ abstract Pos3(Vec3<Float>) from Vec3<Float> to Vec3<Float>{
|
||||
}
|
||||
|
||||
@:op(-A)
|
||||
public function negate(): Pos3 {
|
||||
public function negate():Pos3 {
|
||||
return new Pos3({
|
||||
y: -this.y,
|
||||
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;
|
||||
}
|
||||
|
||||
public function cross(rhs: Vec3<Float>):Pos3 {
|
||||
public function cross(rhs:Vec3<Float>):Pos3 {
|
||||
return new Pos3({
|
||||
x: this.y * rhs.z - this.z * rhs.y,
|
||||
y: this.z * rhs.x - this.x * rhs.z,
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
package lib;
|
||||
|
||||
class Rect {
|
||||
|
||||
private final tl:Pos;
|
||||
private final br:Pos;
|
||||
|
||||
public function new(p1: Pos,p2:Pos) {
|
||||
public function new(p1:Pos, p2:Pos) {
|
||||
this.tl = {
|
||||
x: MathI.min(p1.x,p2.x),
|
||||
y: MathI.min(p1.y,p2.y)
|
||||
x: MathI.min(p1.x, p2.x),
|
||||
y: MathI.min(p1.y, p2.y)
|
||||
};
|
||||
|
||||
this.br = {
|
||||
x: MathI.max(p1.x,p2.x),
|
||||
y: MathI.max(p1.y,p2.y)
|
||||
x: MathI.max(p1.x, p2.x),
|
||||
y: MathI.max(p1.y, p2.y)
|
||||
};
|
||||
}
|
||||
|
||||
public function getSize(): Int {
|
||||
public function getSize():Int {
|
||||
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);
|
||||
}
|
||||
|
||||
public function isOutside(p: Pos): Bool {
|
||||
public function isOutside(p:Pos):Bool {
|
||||
return !this.isInside(p);
|
||||
}
|
||||
|
||||
public function getHight(): Int {
|
||||
public function getHight():Int {
|
||||
return br.y - tl.y;
|
||||
}
|
||||
|
||||
public function getWidth(): Int {
|
||||
public function getWidth():Int {
|
||||
return br.x - tl.x;
|
||||
}
|
||||
|
||||
public function offset(pos: Pos) {
|
||||
public function offset(pos:Pos) {
|
||||
tl.x += pos.x;
|
||||
tl.y += pos.y;
|
||||
br.x += pos.x;
|
||||
|
||||
@@ -12,73 +12,60 @@ import kernel.net.Package.NetworkID;
|
||||
using tink.CoreApi;
|
||||
|
||||
class RessourceNames {
|
||||
public static function get(name: String, controllerID: NetworkID = -1): Promise<Null<NetworkID>> {
|
||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
||||
public static function get(name:String, controllerID:NetworkID = -1):Promise<Null<NetworkID>> {
|
||||
if (controllerID == -1)
|
||||
controllerID = KernelSettings.siteController;
|
||||
|
||||
var payload: GetRequest = {name: name, type: "get"};
|
||||
var payload:GetRequest = {name: name, type: "get"};
|
||||
|
||||
return Net.sendAndAwait(
|
||||
controllerID,
|
||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
||||
payload
|
||||
).map((res)->{
|
||||
switch (res){
|
||||
case Success(pkg):
|
||||
return Success(pkg.data.netID);
|
||||
case Failure(error):
|
||||
return Failure(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload).map((res) -> {
|
||||
switch (res) {
|
||||
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> {
|
||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
||||
public static function register(name:String, netID:NetworkID, controllerID:NetworkID = -1):Promise<Bool> {
|
||||
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(
|
||||
controllerID,
|
||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
||||
payload
|
||||
).map((res)->{
|
||||
switch (res){
|
||||
case Success(pkg):
|
||||
return Success(pkg.data.success);
|
||||
case Failure(error):
|
||||
return Failure(error);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload).map((res) -> {
|
||||
switch (res) {
|
||||
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> {
|
||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
||||
public static function unregister(name:String, controllerID:NetworkID = -1):Promise<Noise> {
|
||||
if (controllerID == -1)
|
||||
controllerID = KernelSettings.siteController;
|
||||
|
||||
var payload: UnregisterRequest = {name: name, type: "unregister"};
|
||||
var payload:UnregisterRequest = {name: name, type: "unregister"};
|
||||
|
||||
return Net.sendAndAwait(
|
||||
controllerID,
|
||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
||||
payload
|
||||
);
|
||||
}
|
||||
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload);
|
||||
}
|
||||
|
||||
public static function list(controllerID: NetworkID = -1): Promise<Array<String>> {
|
||||
if (controllerID == -1) controllerID = KernelSettings.siteController;
|
||||
public static function list(controllerID:NetworkID = -1):Promise<Array<String>> {
|
||||
if (controllerID == -1)
|
||||
controllerID = KernelSettings.siteController;
|
||||
|
||||
var payload: ListRequest = {type: "list"};
|
||||
var payload:ListRequest = {type: "list"};
|
||||
|
||||
return Net.sendAndAwait(
|
||||
controllerID,
|
||||
SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO,
|
||||
payload
|
||||
).map(res->{
|
||||
switch (res){
|
||||
case Success(pkg):
|
||||
return Success(pkg.data);
|
||||
case Failure(error):
|
||||
return Failure(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return Net.sendAndAwait(controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload).map(res -> {
|
||||
switch (res) {
|
||||
case Success(pkg):
|
||||
return Success(pkg.data);
|
||||
case Failure(error):
|
||||
return Failure(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,41 +6,41 @@ import kernel.log.Log;
|
||||
using tink.CoreApi;
|
||||
|
||||
class Export {
|
||||
private final exportConfig: ExportConfig;
|
||||
private final peripheral: IPeripheral;
|
||||
private final exportConfig:ExportConfig;
|
||||
private final peripheral:IPeripheral;
|
||||
|
||||
public function new<T: IExportable & IPeripheral>(exportPerph: T) {
|
||||
this.peripheral = exportPerph;
|
||||
this.exportConfig = exportPerph.export();
|
||||
}
|
||||
public function new<T:IExportable & IPeripheral>(exportPerph:T) {
|
||||
this.peripheral = exportPerph;
|
||||
this.exportConfig = exportPerph.export();
|
||||
}
|
||||
|
||||
public function handleRequest(req: Request): Response {
|
||||
switch (req.operation){
|
||||
case Get:
|
||||
return handleGet(req);
|
||||
case Set(value):
|
||||
//TODO: implement
|
||||
return NotFound;
|
||||
}
|
||||
}
|
||||
public function handleRequest(req:Request):Response {
|
||||
switch (req.operation) {
|
||||
case Get:
|
||||
return handleGet(req);
|
||||
case Set(value):
|
||||
// TODO: implement
|
||||
return NotFound;
|
||||
}
|
||||
}
|
||||
|
||||
private function handleGet(request: Request): Response {
|
||||
if (!this.exportConfig.getDelegates.exists(request.field)){
|
||||
Log.warn('Requested get field ${request.field} does not exist in ??');
|
||||
return NotFound;
|
||||
}
|
||||
private function handleGet(request:Request):Response {
|
||||
if (!this.exportConfig.getDelegates.exists(request.field)) {
|
||||
Log.warn('Requested get field ${request.field} does not exist in ??');
|
||||
return NotFound;
|
||||
}
|
||||
|
||||
var delegate = this.exportConfig.getDelegates.get(request.field);
|
||||
var value = delegate(request.index);
|
||||
var delegate = this.exportConfig.getDelegates.get(request.field);
|
||||
var value = delegate(request.index);
|
||||
|
||||
return Get(value);
|
||||
}
|
||||
return Get(value);
|
||||
}
|
||||
|
||||
public function getType(): String {
|
||||
return this.peripheral.getType();
|
||||
}
|
||||
public function getType():String {
|
||||
return this.peripheral.getType();
|
||||
}
|
||||
|
||||
public function getAddr(): String {
|
||||
return this.peripheral.getAddr();
|
||||
}
|
||||
public function getAddr():String {
|
||||
return this.peripheral.getAddr();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package lib.exporter;
|
||||
import lib.exporter.Response;
|
||||
|
||||
typedef ExportConfig = {
|
||||
getDelegates: Map<String, Null<Int>->ValueType>,
|
||||
// setDelegates: Map<String, (ValueType, Null<Int>)->ValueType>,
|
||||
getDelegates:Map<String, Null<Int>->ValueType>,
|
||||
// setDelegates: Map<String, (ValueType, Null<Int>)->ValueType>,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package lib.exporter;
|
||||
|
||||
interface IExportable {
|
||||
public function export(): ExportConfig;
|
||||
public function export():ExportConfig;
|
||||
}
|
||||
|
||||
@@ -6,23 +6,22 @@ import kernel.net.Package.NetworkID;
|
||||
using tink.CoreApi;
|
||||
|
||||
class Import {
|
||||
public static function get(ressourceLocator: String): Promise<Response> {
|
||||
var request = Request.fromString(ressourceLocator);
|
||||
public static function get(ressourceLocator:String):Promise<Response> {
|
||||
var request = Request.fromString(ressourceLocator);
|
||||
|
||||
return RessourceNames.get(request.id).next((response)->{
|
||||
return performRequest(response,request);
|
||||
});
|
||||
}
|
||||
return RessourceNames.get(request.id).next((response) -> {
|
||||
return performRequest(response, request);
|
||||
});
|
||||
}
|
||||
|
||||
private static function performRequest(netID: NetworkID, request: Request): Promise<Response> {
|
||||
return Net.sendAndAwait(netID,"res",request).map((response)->{
|
||||
switch (response){
|
||||
case Success(data):
|
||||
return Success(cast (data.data, Response));
|
||||
case Failure(error):
|
||||
return Failure(error);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
private static function performRequest(netID:NetworkID, request:Request):Promise<Response> {
|
||||
return Net.sendAndAwait(netID, "res", request).map((response) -> {
|
||||
switch (response) {
|
||||
case Success(data):
|
||||
return Success(cast(data.data, Response));
|
||||
case Failure(error):
|
||||
return Failure(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package lib.exporter;
|
||||
|
||||
enum Operation {
|
||||
Get;
|
||||
Set(value: Dynamic);
|
||||
Get;
|
||||
Set(value:Dynamic);
|
||||
}
|
||||
|
||||
@@ -4,48 +4,47 @@ import lua.TableTools;
|
||||
import lua.NativeStringTools;
|
||||
|
||||
class Request {
|
||||
public final id:String;
|
||||
public final field:String;
|
||||
public final index: Null<Int>;
|
||||
public final operation: Operation;
|
||||
public final id:String;
|
||||
public final field:String;
|
||||
public final index:Null<Int>;
|
||||
public final operation:Operation;
|
||||
|
||||
public function new(id:String, field:String, index:Null<Int>, operation:Operation) {
|
||||
this.id = id;
|
||||
this.field = field;
|
||||
this.index = index;
|
||||
this.operation = operation;
|
||||
}
|
||||
public function new(id:String, field:String, index:Null<Int>, operation:Operation) {
|
||||
this.id = id;
|
||||
this.field = field;
|
||||
this.index = index;
|
||||
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+)")());
|
||||
|
||||
/**
|
||||
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];
|
||||
var index = Std.parseInt(f[2]);
|
||||
var id = f[3];
|
||||
|
||||
var field = f[1];
|
||||
var index = Std.parseInt(f[2]);
|
||||
var id = f[3];
|
||||
return new Request(id, field, index, Get);
|
||||
} else {
|
||||
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)@(%a+)")());
|
||||
|
||||
return new Request(id, field, index, Get);
|
||||
}else{
|
||||
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)@(%a+)")());
|
||||
var field = f[1];
|
||||
var id = f[2];
|
||||
|
||||
var field = f[1];
|
||||
var id = f[2];
|
||||
|
||||
return new Request(id, field, null, Get);
|
||||
}
|
||||
}
|
||||
return new Request(id, field, null, Get);
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() {
|
||||
if (index == null){
|
||||
return field + "@" + id;
|
||||
}else{
|
||||
return field + "[" + index + "]@" + id;
|
||||
}
|
||||
}
|
||||
public function toString() {
|
||||
if (index == null) {
|
||||
return field + "@" + id;
|
||||
} else {
|
||||
return field + "[" + index + "]@" + id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package lib.exporter;
|
||||
|
||||
enum Response {
|
||||
NotFound;
|
||||
Set;
|
||||
NotSet;
|
||||
Get(value: ValueType);
|
||||
NotFound;
|
||||
Set;
|
||||
NotSet;
|
||||
Get(value:ValueType);
|
||||
}
|
||||
|
||||
enum ValueType {
|
||||
Number(value: Int);
|
||||
String(value: String);
|
||||
Bool(value: Bool);
|
||||
Number(value:Int);
|
||||
String(value:String);
|
||||
Bool(value:Bool);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class DummyObservable<T> implements Observable<T> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package lib.observable;
|
||||
using tink.CoreApi;
|
||||
|
||||
interface Observable<T> {
|
||||
public function set(value:T): Void;
|
||||
public function set(value:T):Void;
|
||||
public function get():T;
|
||||
public function subscribe(callback:Callback<T>):CallbackLink;
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
package lib.observable;
|
||||
|
||||
class ObservableArray<T> extends ObservableValue<Array<T>> {
|
||||
public function new(value: Array<T>) {
|
||||
public function new(value:Array<T>) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
public function insert(pos: Int, x: T):Void {
|
||||
this.value.insert(pos,x);
|
||||
public function insert(pos:Int, x:T):Void {
|
||||
this.value.insert(pos, x);
|
||||
this.callbacks.invoke(this.value);
|
||||
}
|
||||
|
||||
public function pop(): Null<T> {
|
||||
public function pop():Null<T> {
|
||||
var poped = this.pop();
|
||||
this.callbacks.invoke(this.value);
|
||||
return poped;
|
||||
}
|
||||
|
||||
public function push(x: T):Int {
|
||||
public function push(x:T):Int {
|
||||
var i = this.value.push(x);
|
||||
this.callbacks.invoke(this.value);
|
||||
return i;
|
||||
}
|
||||
|
||||
public function remove(x: T): Bool {
|
||||
public function remove(x:T):Bool {
|
||||
var b = this.value.remove(x);
|
||||
this.callbacks.invoke(this.value);
|
||||
return b;
|
||||
}
|
||||
|
||||
public function resize(len: Int) {
|
||||
public function resize(len:Int) {
|
||||
this.value.resize(len);
|
||||
this.callbacks.invoke(this.value);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class ObservableArray<T> extends ObservableValue<Array<T>> {
|
||||
this.callbacks.invoke(this.value);
|
||||
}
|
||||
|
||||
public function shift(): Null<T> {
|
||||
public function shift():Null<T> {
|
||||
var e = this.value.shift();
|
||||
this.callbacks.invoke(this.value);
|
||||
return e;
|
||||
@@ -49,7 +49,7 @@ class ObservableArray<T> extends ObservableValue<Array<T>> {
|
||||
this.callbacks.invoke(this.value);
|
||||
}
|
||||
|
||||
public function unshift(x: T):Void {
|
||||
public function unshift(x:T):Void {
|
||||
this.value.unshift(x);
|
||||
this.callbacks.invoke(this.value);
|
||||
}
|
||||
|
||||
@@ -7,16 +7,15 @@ import kernel.turtle.Turtle;
|
||||
using tink.CoreApi;
|
||||
|
||||
class TurtleExecuter {
|
||||
|
||||
private var instructions:Array<TurtleInstruction>;
|
||||
|
||||
public function new(instructions:Array<TurtleInstruction>) {
|
||||
this.instructions = instructions;
|
||||
}
|
||||
|
||||
public function getRequiredFuel(): Int {
|
||||
public function getRequiredFuel():Int {
|
||||
var fuel = 0;
|
||||
for(inst in instructions){
|
||||
for (inst in instructions) {
|
||||
if (inst == Forward || inst == Back || inst == Up || inst == Down) {
|
||||
fuel++;
|
||||
}
|
||||
@@ -25,9 +24,9 @@ class TurtleExecuter {
|
||||
return fuel;
|
||||
}
|
||||
|
||||
public function getRequiredBlocks(): Int {
|
||||
public function getRequiredBlocks():Int {
|
||||
var blocks = 0;
|
||||
for(inst in instructions){
|
||||
for (inst in instructions) {
|
||||
switch inst {
|
||||
case Place(_):
|
||||
blocks++;
|
||||
@@ -42,11 +41,11 @@ class TurtleExecuter {
|
||||
Return the offset of the turtle after executing the instructions.
|
||||
The origin is the starting position of the turtle.
|
||||
**/
|
||||
public function getFinalOffset(): {offset: Pos3, faceing: Pos} {
|
||||
var pos: Pos3 = {x:0, y:0, z:0};
|
||||
var forwardVec: Pos3 = {x: 1, y: 0, z: 0};
|
||||
public function getFinalOffset():{offset:Pos3, faceing:Pos} {
|
||||
var pos:Pos3 = {x: 0, y: 0, z: 0};
|
||||
var forwardVec:Pos3 = {x: 1, y: 0, z: 0};
|
||||
|
||||
for (inst in instructions){
|
||||
for (inst in instructions) {
|
||||
switch inst {
|
||||
case Forward:
|
||||
pos = pos + forwardVec;
|
||||
@@ -55,21 +54,21 @@ class TurtleExecuter {
|
||||
case TurnRight:
|
||||
forwardVec = {x: -forwardVec.z, z: forwardVec.x, y: forwardVec.y};
|
||||
case TurnLeft:
|
||||
forwardVec = {x: forwardVec.z, z: -forwardVec.x , y: forwardVec.y};
|
||||
forwardVec = {x: forwardVec.z, z: -forwardVec.x, y: forwardVec.y};
|
||||
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() {
|
||||
for (inst in instructions){
|
||||
for (inst in instructions) {
|
||||
executeInst(inst);
|
||||
}
|
||||
}
|
||||
|
||||
private function executeInst(instruction: TurtleInstruction): Outcome<Noise,String> {
|
||||
private function executeInst(instruction:TurtleInstruction):Outcome<Noise, String> {
|
||||
switch instruction {
|
||||
case Forward:
|
||||
return Turtle.instance.forward();
|
||||
|
||||
@@ -8,11 +8,11 @@ using tink.CoreApi;
|
||||
Extends the Turtle kernel.
|
||||
**/
|
||||
class TurtleExt {
|
||||
public static function getFreeSlots(t: Turtle): Int {
|
||||
var ret: Int = 0;
|
||||
public static function getFreeSlots(t:Turtle):Int {
|
||||
var ret:Int = 0;
|
||||
|
||||
for (i in 0...Turtle.MAX_SLOTS){
|
||||
if (t.getItemCount(i) == 0){
|
||||
for (i in 0...Turtle.MAX_SLOTS) {
|
||||
if (t.getItemCount(i) == 0) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ class TurtleExt {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static function canPickup(t: Turtle,item: Item): Bool {
|
||||
for (i in 0...Turtle.MAX_SLOTS){
|
||||
public static function canPickup(t:Turtle, item:Item):Bool {
|
||||
for (i in 0...Turtle.MAX_SLOTS) {
|
||||
var slotItem = t.getItemDetail(i).orNull();
|
||||
if (slotItem != null && slotItem.name == item){
|
||||
if (t.getItemSpace(i)>0){
|
||||
if (slotItem != null && slotItem.name == item) {
|
||||
if (t.getItemSpace(i) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -33,12 +33,12 @@ class TurtleExt {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canPickupCount(t: Turtle,item: Item): Int {
|
||||
var ret: Int = 0;
|
||||
public static function canPickupCount(t:Turtle, item:Item):Int {
|
||||
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();
|
||||
if (slotItem != null && slotItem.name == item){
|
||||
if (slotItem != null && slotItem.name == item) {
|
||||
ret += Turtle.instance.getItemSpace(i);
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,12 @@ class TurtleExt {
|
||||
return ret;
|
||||
}
|
||||
|
||||
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();
|
||||
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();
|
||||
|
||||
for (i in 0...Turtle.MAX_SLOTS){
|
||||
for (i in 0...Turtle.MAX_SLOTS) {
|
||||
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)});
|
||||
}
|
||||
}
|
||||
@@ -63,36 +63,30 @@ class TurtleExt {
|
||||
Optimize the turtle inventory.
|
||||
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);
|
||||
// For each item in the inventory
|
||||
for(k1 => v1 in inv){
|
||||
|
||||
if (v1.free == 0 || v1.count == 0){
|
||||
for (k1 => v1 in inv) {
|
||||
if (v1.free == 0 || v1.count == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for(k2 => v2 in inv){
|
||||
|
||||
if (k2 == k1){
|
||||
for (k2 => v2 in inv) {
|
||||
if (k2 == k1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (v1.item == v2.item && v2.free > 0){
|
||||
if (v1.item == v2.item && v2.free > 0) {
|
||||
// We can move an item in there
|
||||
t.transfer(k1,k2,v2.free);
|
||||
t.transfer(k1, k2, v2.free);
|
||||
|
||||
v1.count -= v2.free;
|
||||
if (v1.count <= 0){
|
||||
if (v1.count <= 0) {
|
||||
inv.remove(k1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ enum TurtleInstruction {
|
||||
Down;
|
||||
TurnLeft;
|
||||
TurnRight;
|
||||
Dig(dir: InteractDirections);
|
||||
Place(dir: InteractDirections);
|
||||
PlacseSign(dir: InteractDirections, text: String);
|
||||
Select(slot: TurtleSlot);
|
||||
Dig(dir:InteractDirections);
|
||||
Place(dir:InteractDirections);
|
||||
PlacseSign(dir:InteractDirections, text:String);
|
||||
Select(slot:TurtleSlot);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package lib.turtle;
|
||||
// Check usage of NativeStringTools
|
||||
// here https://api.haxe.org/lua/NativeStringTools.html
|
||||
// and here http://lua-users.org/wiki/StringLibraryTutorial
|
||||
|
||||
import kernel.turtle.Types.TurtleSlot;
|
||||
import kernel.turtle.Turtle;
|
||||
import lua.NativeStringTools;
|
||||
@@ -14,24 +13,21 @@ using tink.CoreApi;
|
||||
Save a set of turtle instructions to a string and execute them.
|
||||
**/
|
||||
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 times = 0;
|
||||
var lastInstruction: TurtleInstruction = null;
|
||||
var lastInstruction:TurtleInstruction = null;
|
||||
|
||||
for (inst in instructions){
|
||||
if (inst == lastInstruction){
|
||||
for (inst in instructions) {
|
||||
if (inst == lastInstruction) {
|
||||
times++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lastInstruction != null){
|
||||
if (lastInstruction != null) {
|
||||
var encoded = encodeInstruction(lastInstruction);
|
||||
s = s + '${times + 1}$encoded';
|
||||
}
|
||||
@@ -46,9 +42,9 @@ class TurtleInstructionParser {
|
||||
return s;
|
||||
}
|
||||
|
||||
private function encodeInstruction(inst: TurtleInstruction): String {
|
||||
for (k => v in cmdMap){
|
||||
if (v == inst){
|
||||
private function encodeInstruction(inst:TurtleInstruction):String {
|
||||
for (k => v in cmdMap) {
|
||||
if (v == inst) {
|
||||
return k;
|
||||
}
|
||||
}
|
||||
@@ -63,15 +59,15 @@ class TurtleInstructionParser {
|
||||
return "";
|
||||
}
|
||||
|
||||
private function encodeSlot(slot: TurtleSlot): String {
|
||||
private function encodeSlot(slot:TurtleSlot):String {
|
||||
return String.fromCharCode(slot + 97);
|
||||
}
|
||||
|
||||
public function parse(instructionsString: String): Array<TurtleInstruction> {
|
||||
var rtn: Array<TurtleInstruction> = [];
|
||||
var mfunc = NativeStringTools.gmatch(instructionsString,"%d+%D+");
|
||||
public function parse(instructionsString:String):Array<TurtleInstruction> {
|
||||
var rtn:Array<TurtleInstruction> = [];
|
||||
var mfunc = NativeStringTools.gmatch(instructionsString, "%d+%D+");
|
||||
|
||||
while(true){
|
||||
while (true) {
|
||||
var found = mfunc();
|
||||
|
||||
if (found == null) {
|
||||
@@ -82,7 +78,7 @@ class TurtleInstructionParser {
|
||||
var command = NativeStringTools.match(found, "%D+");
|
||||
|
||||
var cmd = cmdMap.get(command);
|
||||
if (cmd != null){
|
||||
if (cmd != null) {
|
||||
rtn = rtn.concat([for (i in 0...times) cmd]);
|
||||
}
|
||||
|
||||
@@ -96,7 +92,7 @@ class TurtleInstructionParser {
|
||||
return rtn;
|
||||
}
|
||||
|
||||
private static function parseSlot(slot: String): TurtleSlot {
|
||||
private static function parseSlot(slot:String):TurtleSlot {
|
||||
var slot = slot.charCodeAt(0) - 97;
|
||||
|
||||
if (slot < 0 || slot > Turtle.MAX_SLOTS) {
|
||||
@@ -107,19 +103,8 @@ class TurtleInstructionParser {
|
||||
return slot;
|
||||
}
|
||||
|
||||
private var cmdMap:Map<String,TurtleInstruction> = [
|
||||
"a" => Forward,
|
||||
"b" => Back,
|
||||
"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),
|
||||
private var cmdMap:Map<String, TurtleInstruction> = [
|
||||
"a" => Forward, "b" => Back, "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 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() {
|
||||
this = [[]];
|
||||
}
|
||||
@@ -62,8 +62,8 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
|
||||
return max;
|
||||
}
|
||||
|
||||
public function getBounds(): Rect {
|
||||
return new Rect({x:0,y:0},{
|
||||
public function getBounds():Rect {
|
||||
return new Rect({x: 0, y: 0}, {
|
||||
x: maxWidth() - 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
|
||||
**/
|
||||
public function renderToContext(ctx: WindowContext){
|
||||
var lastBgColor: Color = null;
|
||||
var lastTextColor: Color = null;
|
||||
public function renderToContext(ctx:WindowContext) {
|
||||
var lastBgColor:Color = null;
|
||||
var lastTextColor:Color = null;
|
||||
|
||||
for (lineIndex => line in this) {
|
||||
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 {
|
||||
private final canvas:Array<Array<Pixel>> ;
|
||||
private final canvas:Array<Array<Pixel>>;
|
||||
private var index:Null<Pos> = {x: 0, y: 0};
|
||||
private var nextIndex:Null<Pos> = null;
|
||||
|
||||
@@ -134,14 +134,14 @@ class CanvasKeyValueIterator {
|
||||
private function new(canvas:Array<Array<Pixel>>) {
|
||||
this.canvas = canvas;
|
||||
|
||||
if (!isValidPos(this.index)){
|
||||
if (!isValidPos(this.index)) {
|
||||
this.index = nextValidPixel();
|
||||
}
|
||||
|
||||
this.nextIndex = nextValidPixel();
|
||||
}
|
||||
|
||||
private function isValidPos(pos: Pos): Bool {
|
||||
private function isValidPos(pos:Pos):Bool {
|
||||
if (this.canvas[pos.y] == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -157,19 +157,19 @@ class CanvasKeyValueIterator {
|
||||
return this.index != null;
|
||||
}
|
||||
|
||||
private function nextValidPixel(): Null<Pos> {
|
||||
private function nextValidPixel():Null<Pos> {
|
||||
if (this.index == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (x in startX...(this.canvas[y].length)){
|
||||
for (x in startX...(this.canvas[y].length)) {
|
||||
if (this.canvas[y][x] == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -191,7 +191,6 @@ class CanvasKeyValueIterator {
|
||||
this.index = this.nextIndex;
|
||||
this.nextIndex = nextValidPixel();
|
||||
|
||||
|
||||
return rtn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package lib.ui;
|
||||
import lib.Color;
|
||||
|
||||
typedef Style = {
|
||||
public var ?fgColor: Color;
|
||||
public var ?bgColor: Color;
|
||||
public var ?fgColor:Color;
|
||||
public var ?bgColor:Color;
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ import kernel.ui.WindowContext;
|
||||
using tink.CoreApi;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function render(bounds: Pos):Canvas {
|
||||
public function render(bounds:Pos):Canvas {
|
||||
var canvas = new Canvas();
|
||||
var offset = new Pos({x: 0, y: 0});
|
||||
|
||||
@@ -48,11 +48,11 @@ class RootElement implements UIElement {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
public function setTitle(title: String) {
|
||||
public function setTitle(title:String) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
private inline function hasTitle(): Bool {
|
||||
return title != "";
|
||||
private inline function hasTitle():Bool {
|
||||
return title != "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class TextElement implements UIElement {
|
||||
private final uiEvents:UIEvents;
|
||||
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.uiEvents = props?.uiEvents;
|
||||
this.style = props?.style ?? {fgColor: White, bgColor: Black};
|
||||
@@ -26,7 +26,7 @@ class TextElement implements UIElement {
|
||||
return uiEvents;
|
||||
}
|
||||
|
||||
public function render(bounds: Pos):Canvas {
|
||||
public function render(bounds:Pos):Canvas {
|
||||
var canvas = new Canvas();
|
||||
for (i in 0...this.text.length) {
|
||||
var c = this.text.charAt(i);
|
||||
|
||||
@@ -3,5 +3,5 @@ package lib.ui.elements;
|
||||
import lib.ui.rendere.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;
|
||||
|
||||
class List implements UIEventDelegate{
|
||||
private final onElementClick: Null<Int->Void>;
|
||||
class List implements UIEventDelegate {
|
||||
private final onElementClick:Null<Int->Void>;
|
||||
|
||||
public function new(?onElementClick: Int->Void) {
|
||||
public function new(?onElementClick:Int->Void) {
|
||||
this.onElementClick = onElementClick;
|
||||
}
|
||||
|
||||
public function render(list:Array<String>): Canvas {
|
||||
public function render(list:Array<String>):Canvas {
|
||||
var canvas = new Canvas();
|
||||
for (line in 0...list.length) {
|
||||
for (char in 0...list[line].length) {
|
||||
@@ -22,14 +22,14 @@ class List implements UIEventDelegate{
|
||||
return canvas;
|
||||
}
|
||||
|
||||
public function getEventHandlers(): UIEvents{
|
||||
public function getEventHandlers():UIEvents {
|
||||
return {
|
||||
onClick: handleClick
|
||||
};
|
||||
}
|
||||
|
||||
private function handleClick(e: {button:kernel.ButtonType, pos:Pos}): Void{
|
||||
if (this.onElementClick == null){
|
||||
private function handleClick(e:{button:kernel.ButtonType, pos:Pos}):Void {
|
||||
if (this.onElementClick == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package lib.ui.rendere;
|
||||
|
||||
interface UIEventDelegate {
|
||||
public function getEventHandlers(): UIEvents;
|
||||
public function getEventHandlers():UIEvents;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user