From 3c18061ae29082cbe2e2f543efacdf17e3890ad3 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Tue, 3 May 2022 19:21:09 +0200 Subject: [PATCH] Updated Basalt (markdown) --- Basalt.md | 129 ++++++++++-------------------------------------------- 1 file changed, 22 insertions(+), 107 deletions(-) diff --git a/Basalt.md b/Basalt.md index cf6ae7e..375177c 100644 --- a/Basalt.md +++ b/Basalt.md @@ -13,16 +13,16 @@ create a frame without a parent ````lua local mainFrame = basalt.createFrame("myFirstFrame"):show() ```` -**args:** the id as string
-**returns:** frame object
+**parameters:** string name
+**returns:** new frame object
## basalt.removeFrame -removes the frame +removes a frame (only possible for non-parent frames) ````lua local mainFrame = basalt.createFrame("myFirstFrame"):show() basalt.removeFrame("myFirstFrame") ```` -**args:** the id as string
+**parameters:** string name
**returns:**-
## basalt.getFrame @@ -31,7 +31,7 @@ With that function you can get frames, but only frames without a parent! basalt.createFrame("myFirstFrame") basalt.getFrame("myFirstFrame"):show() ```` -**args:** id of the frame
+**parameters:** string name
**returns:** frame object
## basalt.getActiveFrame @@ -40,16 +40,25 @@ returns the currently active (without a parent) frame basalt.createFrame("myFirstFrame"):show() basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame ```` -**args:** -
+**parameters:** -
**returns:** frame object
-## basalt.startUpdate -starts the logic, draw and event handler +## basalt.autoUpdate +starts the logic, draw and event handler until you use basalt.stopUpdate ````lua local mainFrame = basalt.createFrame("myFirstFrame"):show() -basalt.startUpdate() +basalt.autoUpdate() ```` -**args:** -
+**parameters:** -
+**returns:**-
+ +## basalt.update +calls the basalt.update method once +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +basalt.autoUpdate() +```` +**parameters:** string event, ... (you can use some paramters here. you dont have to pass any paramters )
**returns:**-
## basalt.stopUpdate @@ -57,107 +66,13 @@ stops the logic, draw and event handler ````lua basalt.stopUpdate() ```` -**args:** -
+**parameters:** -
**returns:**-
## basalt.debug -Something you just need as a developer, why shouldn't i publish it? This creates a label on the bottom left of your active frame, if you click on that label it will -create a fully sized frame with a list, where it logs all your debug messages +creates a label with some information on the main frame on the bottom left, if you click on that label it will open a log view for you see it as the new print for debugging ````lua basalt.debug("Hi i am cute") ```` -**args:** ... (multiple args are possible, like print does)
+**parameters:** ... (multiple parameters are possible, like print does)
**returns:**-
- -# Tipps -If you are new to such things, you want to create your own logic (lets say for example a redstone or rednet handler) while using the basalt Framework, you just have to create something like this: - -````lua -local basalt = dofile("basalt.lua") - -local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality -mainFrame:addButton("aButton"):onClick(function() end):show() - -local function yourCustomHandler() - while true do - -- add your logic here - os.sleep(1) -- you need something which calls coroutine.yield(), yes os.sleep does that os.pullEvent() aswell - end -end - -parallel.waitForAll(basalt.startUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalts handlers at the time -```` -You can read [here](http://www.computercraft.info/wiki/Parallel_(API)) what exactly parallel.waitForAll() does - -# Installer -Here is a premade installer you can add into your script if you want: - -This is a visual version, it asks the user if he wants to install basalt.lua (if not found)
-![](https://i.imgur.com/b4Ys7FB.png) -````lua ---Basalt configurated installer -local filePath = "basalt.lua" --here you can change the file path default: basalt.lua -if not(fs.exists(filePath))then - local w,h = term.getSize() - term.clear() - local _installerWindow = window.create(term.current(),w/2-8,h/2-3,18,6) - _installerWindow.setBackgroundColor(colors.gray) - _installerWindow.setTextColor(colors.black) - _installerWindow.write(" Basalt Installer ") - _installerWindow.setBackgroundColor(colors.lightGray) - for line=2,6,1 do - _installerWindow.setCursorPos(1,line) - if(line==3)then - _installerWindow.write(" No Basalt found! ") - elseif(line==4)then - _installerWindow.write(" Install it? ") - elseif(line==6)then - _installerWindow.setTextColor(colors.black) - _installerWindow.setBackgroundColor(colors.gray) - _installerWindow.write("Install") - _installerWindow.setBackgroundColor(colors.lightGray) - _installerWindow.write(string.rep(" ",5)) - _installerWindow.setBackgroundColor(colors.red) - _installerWindow.write("Cancel") - else - _installerWindow.write(string.rep(" ",18)) - end - end - _installerWindow.setVisible(true) - _installerWindow.redraw() - while(not(fs.exists(filePath))) do - local event, p1,p2,p3,p4 = os.pullEvent() - if(event=="mouse_click")then - if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then - shell.run("wget https://raw.githubusercontent.com/NoryiE/Basalt/master/basalt.lua "..filePath) - _installerWindow.setVisible(false) - term.clear() - break - end - if(p3==h/2+2)and(p2<=w/2+9)and(p2>=w/2+4)then - _installerWindow.clear() - _installerWindow.setVisible(false) - term.setCursorPos(1,1) - term.clear() - return - end - end - end - term.setCursorPos(1,1) - term.clear() -end - -local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt ------------------------------- -```` - -Here is a very basic one which just installs basalt.lua if don't exist: -````lua ---Basalt configurated installer -local filePath = "basalt.lua" --here you can change the file path default: basalt.lua -if not(fs.exists(filePath))then -shell.run("wget https://raw.githubusercontent.com/NoryiE/Basalt/master/basalt.lua "..filePath) -end -local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt - -```` \ No newline at end of file