feat: update rect, text, color, and hooks #1075
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains changes that bring my code up-to-date with my current standards and skills, adding in some new features and hopefully (slightly) less memory usage.
rect
,color
,text
, andhook
have been separated into their own files, all loaded together throughexternal.script.lua-tools.init
.rect
,color
, andtext
now have their own shared metatables instead of making a new one for each instance.text:create
andtext:new
are nowtext.create
andtext.new
.color:new
,color:fromHex
are nowcolor.new
andcolor.fromHex
.rect:create
is nowrect.create
.rect:update(t)
now checks the keycolor
, which will update it'sr
,g
,b
,src
, anddst
values.color:toHex
is shorter, usingstring.format
.New functions for hooks:
hook.on(list, callback)
: adds a callback to a hook list without a name.hook.removeOn(list, callback)
: removes a callback from the recurring list, named or not.hook.once(list, callback)
: adds a callback to a hook list which only runs once.hook.removeOnce(list, callback)
: removes a one-time callback. Probably only useful if one mod's trying to cut another off.One time callbacks are run before recurring ones.
New functions for colors:
color.fromHSL(h, s, l, src, dst)
: Creates a color using the HSL format.Color:toHSL()
: Returnsh
,s
,l
,src
, anddst
values.Another file has been made to store extra functions that extend existing parts of Lua, currently only including
table.getKey(tbl, value)
.