From d1e0220d54cd48b0d17faf21715d7da02062bf3d Mon Sep 17 00:00:00 2001 From: Erlend <49862976+Erb3@users.noreply.github.com> Date: Sun, 29 May 2022 13:28:06 +0200 Subject: [PATCH] Home Category --- docs/_sidebar.md | 6 ++-- docs/home/gettingStarted.md | 69 +++++++++++++++++++++++++++++++++++ docs/home/installer.md | 72 +++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 docs/home/gettingStarted.md create mode 100644 docs/home/installer.md diff --git a/docs/_sidebar.md b/docs/_sidebar.md index ab30970..c1ec61c 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -1,2 +1,4 @@ -- [Home](/) -- [Getting Started](/gettingStarted) \ No newline at end of file +- Home + - [Home](/) + - [Getting Started](/home/gettingStarted) + - [Installer](/home/installer) \ No newline at end of file diff --git a/docs/home/gettingStarted.md b/docs/home/gettingStarted.md new file mode 100644 index 0000000..9e9b220 --- /dev/null +++ b/docs/home/gettingStarted.md @@ -0,0 +1,69 @@ +Basalt aims to be a relatively small, easy to use framework. + +Accordingly, we have provided an installation script. + + +Just use the following command in any CC:Tweaked shell: + +`wget https://github.com/Pyroxenium/Basalt/raw/master/basalt.lua basalt.lua` + +This will download `basalt.lua` to your local directory. + +To load the framework, make use of the following snippet: +````lua +--> For those who are unfamiliar with lua, dofile executes the code in the referenced file +local basalt = dofile("basalt.lua") +```` + + +Here is a fully functioning example of Basalt code: + +````lua +local basalt = dofile("basalt.lua") --> Load the Basalt framework + +--> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events +--> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE +--> If the supplied UID is ambiguous, Basalt#createFrame returns a nil value +local mainFrame = basalt.createFrame("mainFrame") + +--> Show the frame to the user +mainFrame:show() + +local button = mainFrame:addButton("clickableButton") --> Add a button to the mainFrame (With a unique identifier) + +--> Set the position of the button, Button#setPosition follows an x, y pattern. +--> The x value is how far right the object should be from its anchor (negative values from an anchor will travel left) +--> The y value is how far down the object should be from its anchor (negative values from an anchor will travel up) +button:setPosition(4, 4) + +button:setText("Click me!") --> Set the text of our button + +local function buttonClick() --> This function serves as our click logic + basalt.debug("I got clicked!") +end + +--> Remember! You cannot supply buttonClick(), that will only supply the result of the function +--> Make sure the button knows which function to call when it's clicked +button:onClick(buttonClick) + +button:show() --> Make the button visible, so the user can click it + +basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect user input +```` +If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above: +````lua +local basalt = dofile("basalt.lua") + +local mainFrame = basalt.createFrame("mainFrame"):show() +local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining" + :addButton("clickableButton") --> This is an example of call chaining + :setPosition(4,4) + :setText("Click me!") + :onClick( + function() + basalt.debug("I got clicked!") + end) + :show() + +basalt.autoUpdate() +```` diff --git a/docs/home/installer.md b/docs/home/installer.md new file mode 100644 index 0000000..41e4959 --- /dev/null +++ b/docs/home/installer.md @@ -0,0 +1,72 @@ +This is just a script which helps you to install basalt.lua, if it's not already on the computer. Means, you create your program (which requires basalt) and add this on the top of your program. Now, everytime you execute your program it checks if basalt.lua exists or not. + +## Visual Installer +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("pastebin run ESs1mg7P") -- this is an alternative to the wget command + _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 +```` + +## Basic Installer +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://github.com/Pyroxenium/Basalt/raw/master/basalt.lua basalt.lua") +end +local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt + +```` \ No newline at end of file