From 33c9e3ab6c9345e247d496f9a1aef47eefa4d506 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Fri, 4 Mar 2022 13:28:59 +0100 Subject: [PATCH] startup update --- src/Startup.hx | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/Startup.hx b/src/Startup.hx index b392d5d..712522d 100644 --- a/src/Startup.hx +++ b/src/Startup.hx @@ -1,3 +1,9 @@ +import util.Observable; +import lib.ui.reactive.TextElement; +import lib.ui.reactive.ReactiveUI; +import kernel.ui.WindowManager; +import kernel.net.Net; +import kernel.KernelEvents; import kernel.Log; import kernel.Init; @@ -6,6 +12,51 @@ using util.Extender.LambdaExtender; class Startup { public static function main() { Init.initKernel(); + 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); + } + }); + } + }); } }