-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update rect, text, color, and hooks #1075
base: develop
Are you sure you want to change the base?
Conversation
It looks very good and can be merged once stable version 0.99.0 is published. However, please keep in mind that a major Lua refactoring is currently in progress. Therefore, the changes made to the current scripts and the old file structure will not be kept once that branch is merged. For this reason, I am not encouraging people to work with the current scripts and instead wait for the refactoring to be finished. But of course I will implement expanded functionality and improvements from this PR in the refactored code. The general approach is similar to yours but scope of object-oriented changes affects most of the code and unified commenting allows for proper integration with VSC and IntelliJ IDE. Currently, the scripts have been separated into 41 classes and subclasses with inheritance, each in a different file, and more will be added. Here is an example of your old color functions following the style and commenting that the Lua refactored code strictly follows: https://gist.github.com/K4thos/6893e5b458cbfa1358f318988199a242 |
I think I remember hearing something about the refactoring a while ago but I didn't know whether it was being worked on or if it was public. The code and comments look nice, and I look forward to seeing and working with the rest of it. |
That last return can be most likely skipped but not using local for this is intentional. Without global either VSC or IntelliJ extension that this type of commenting is aimed at wasn't able to provide all hints, suggest types, code completion or following functions between files, if I remember correctly, but I don't remember the details right now. Once the refactoring is done I hope that you will help me to improve it since you're really good with Lua. |
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)
.