DynaHex - Dynamic object based palette generator

Started by hugeblank, Dec 25, 2018, 09:47 AM

Previous topic - Next topic

hugeblank

DynaHex

Note: I made this a while ago and am slapping together this post just so that it actually has a place to get attention. If there's an error or something that I didn't pick up on in either this post or the code itself PM me via here or discord and I will fix it.

What:
DynaHex is a small dynamic object based palette allocation utility. This means that you can have several objects that can have different hexadecimal values, and instead of calling colors by their name 'colors.black' and the like, you can call them on an object basis assuming you input the correct table, eg: 'megaman.skin'. The real selling point of this tool is that if two objects get loaded (more on loading later) that use the same hex colors, they will refer to the same location on the palette.

Install:
wget https://gist.githubusercontent.com/hugeblank/6af21537e0b867157fcfaec273ddded6/raw/dynahex.luaTo use it, simply 'require' it. Stop using os.loadAPI, it harms the trees.

Usage:
The API is fairly simple to use, consisting of only 2 functions:

dynahex.load - Loads an objects provided colors into the palette
Input:
  • Table - object containing either one or more keys with either a number or table value. If the value is a table, it should consist of 3 RGB numbers between 0 and 1 inclusive.
Output:
> If Successful
  • Table - object with all valid color key/value pairs converted to palette references.
> If Unsuccessful
  • Boolean - false if the object passed in fails some minor tests.
  • String - three character error code designated to each possible mistake to be made
  • String - element that caused the error, if any can be provided

dynahex.unload - Unloads the given object from the palette
Input:
  • Table - dynahex loaded object, given from dynahex.load
Output:
> If Successful
  • Boolean - true, it succeeded
> If Unsuccessful
  • Boolean - false if the object passed in fails some minor tests.
  • String - three character error code designated to each possible mistake to be made
  • String - element that caused the error, if any can be provided

Example
Here's an object template you could totally pass into dynahex.load:
{
skin = 0xe1c27f, -- Skin-ish color
body = 0x50abff, -- Light blue
boots = {0, .317, 1} -- Darker blue
}

If any of the above did not make sense which I do not blame you for not understanding, please feel free to check the code itself. I heavily comment line-for-line what each step does, and take pride in doing so for the sake of the end user.
"inspirational quote"
- Motivational Speaker

Also the first user to set the theme to "Curve2" as their default.