cc-haxe/src/Startup.hx

63 lines
1.3 KiB
Haxe
Raw Normal View History

2022-03-04 12:28:59 +00:00
import util.Observable;
import lib.ui.reactive.TextElement;
import lib.ui.reactive.ReactiveUI;
import kernel.ui.WindowManager;
import kernel.net.Net;
import kernel.KernelEvents;
2022-02-24 18:47:27 +00:00
import kernel.Log;
2022-02-21 00:50:19 +00:00
import kernel.Init;
2021-12-20 00:55:30 +00:00
using util.Extender.LambdaExtender;
class Startup {
2022-02-21 00:50:19 +00:00
public static function main() {
Init.initKernel();
2022-03-04 12:28:59 +00:00
uiTest();
}
private static function uiTest() {
var context = WindowManager.instance.createNewContext();
var text1 = new Observable("My text");
var text2 = new Observable("Another one");
var ui = new ReactiveUI(context,[
new TextElement(text1,Orange,White,{
onClick: (p) ->{
text1.set("Click");
}
}),
new TextElement(text2,Black,White,{
onClick: (p)->{
text2.set("Click");
}
})
]);
ui.render();
WindowManager.instance.focusContextToOutput(context,"main");
}
private static function sendTest() {
Net.instance.registerProto("ping",(pack)->{
Log.debug("Message: " + pack.data);
pack.respond("Hello from: "+Net.instance.networkID);
});
KernelEvents.instance.onChar.handle((char)->{
if (char == "s"){
Log.debug("Sending to 4");
Net.instance.sendAndAwait(4,"ping","Hello world").handle((result)->{
switch (result){
case Success(pack):
Log.debug("Response: "+pack.data);
case Failure(err):
Log.error(err);
}
});
}
});
2021-12-20 00:55:30 +00:00
}
}