This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
H4X0RZ's profile picture

[Tutorial] How to use a skin file (my way)

Started by H4X0RZ, 03 May 2013 - 09:52 AM
H4X0RZ #1
Posted 03 May 2013 - 11:52 AM
Hello all,
today I want to show you, how you can create a simple skin file ^^

So, you need three files (or more) :

Skin (contains your skins)
Curr_Skin (contains the ID of your current skin)
Program <---- Name of the "real" file

First of all, think about what you need in your skin.
For example:

BgCol
TxtCol
HeaderCol
HeaderTxt

Now we go into the Skin file. Actually it looks like this:



So, nothing is in it. That we want to edit.
First create a table like this :

Skins = { --name of the skin table
["skin1"] = { --name of the skin
BgCol = colors.lightGray,
TxtCol = colors.black,
HeaderCol = colors.black,
HeaderTxt = colors.lightGray
} 
}

Yea! You've finished creating a table!

Description:
You have a table at the top that contains another table that contains the skin colors. Do you understand me?

So, now we need a function "getSkin()".

The function looks like this:

--our Skins table is here

function getSkin()
local curr_skin = fs.open("Curr_Skin", "r")
local skin_name = curr_skin.readAll()
return Skins[skin_name]
end

Description:
The function opens the "Curr_Skin" file.
Then it reads the content of the file, and returns the content of the right Skin. Do you understand me?

Now the Skin file is complete!

Right, now we edit the Program file.

There you load the Skin file as an API:

os.loadAPI("Skin")

Now you can create new table:

Skin = Skin.getSkin() --it's the function in your skin file

Ok, only one thing left, the Curr_Skin file.
In that file you add the name of your skin.
In my case:

skin1

So, we're finished!

Here comes an example usage:

--A simple header
os.loadAPI("Skin")
local skin = Skin.getSkin()

function header(start, space, ...)
local params = {...}
term.setCursorPos(1,1)
term.setBackgroundColor(skin.HeaderColor)
term.setTextColor(skin.HeaderTxt)
term.clearLine()
term.setCursorPos(start, 1)
for i = 1, #params do
term.write("["..params[i]"]")
for i = 1, space do
term.write(" ")
end
end

term.setBackgroundColor(skin.BgColor)
term.clear()
header(7,3, "This", "Is", "A", "Header")

Please reply feedback, questions and suggestions!

Thx for reading

-Freack100-
superaxander #2
Posted 03 May 2013 - 12:37 PM
So you can make themes cool!