Skip to content
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

third nene refactor (v0.3.0) #17

Merged
merged 18 commits into from
Feb 19, 2022
Merged

third nene refactor (v0.3.0) #17

merged 18 commits into from
Feb 19, 2022

Conversation

Andre-LA
Copy link
Owner

@Andre-LA Andre-LA commented Feb 6, 2022

The main changes are the usage of the newer module system, no more
globals, and the usage of Nene.instance() instead of passing nene by
argument.

The math library also got split in different modules, but a Math wrapper
is still provided.

The core module is just nene.init.nelua file, not nene.core.nelua
anymore, this means that local Nene = require 'nene' doesn't require
all modules at once anymore, just the core.

To require all nene at once, you should use require 'nene.all' module,
however this isn't implemented for now.

Another change is that checking or asserting ok status is now a
requirement, this means that instead of local tex = Texture.load'something.png', where the ok status is the second returned
value, now you must do local ok, tex = Texture.load'something.png', note that the ok status is now the first returned value; This is true for other modules, not only Texture.

Finally, any SDL data is considered a "raw data", which should always be got using the get_raw() method, this method checks if the value isn't nilptr.

Please check the examples to see how nene should be used.

This is WIP, and still need to be reviewed.

The main changes are the usage of the newer module system, no more
globals, and the usage of `Nene.instance()` instead of passing nene by
argument.

The math library also got split in different modules, but a Math wrapper
is still provided.

The core module is just `nene.init.nelua` file, not `nene.core.nelua`
anymore, this means that `local Nene = require 'nene'` doesn't require
all modules at once anymore, just the core.

To require all nene at once, you should use `require 'nene.all'` module,
however this isn't implemented for now.

Another change is that checking or asserting ok status is now a
requirement, this means that instead of `local tex =
Texture.load'something.png'`, where the ok status is the second returned
value, now you must do `local ok, tex = Texture.load'something.png'`.

Please check the examples to see how nene should be used.
@Andre-LA Andre-LA added this to the v0.3.0 milestone Feb 6, 2022
Note: however, it uses 'solid' instead of 'blended' by default
methods added:

* get_glyph_metrics, from TTF_GlyphMetrics
* get_height, from TTF_FontHeight
* get_ascent, from TTF_FontAscent
* get_descent, from TTF_FontDescent
* get_line_skip, from TTF_FontLineSkip
* get_text_dimensions, from TTF_SizeUTF8
* is_monospaced, from TTF_FontFaceIsFixedWidth

Proper testing it's still to be added
Now both Rect and Vec2 are generics that accepts any arithmetic type,
for example, now you can make a 2D vector using bytes like this:

```lua
local Vec2n = require 'nene.math.vec2n'
local Vec2i8 = Vec2n(int8)
```

For both `integer` and `number`, two aliases modules are provided
for both rects and 2D vectors:

* `nene.math.rect` for `RectN(integer)`
* `nene.math.rectf` for `RectN(number)`
* `nene.math.vec2` for `Vec2n(number)`
* `nene.math.vec2i` for `Vec2n(integer)`

So you can require them like that:

```lua
local Vec2 = require 'nene.math.vec2'
```

If you prefer the Math module, you can still use it, since it's not
removed and there is not much reason to remove it:

```lua
local Math = require 'nene.math'

local function x(v: Math.Vec2): Math.Rect
  -- ... impl ...
end
```
The Audio module still exists though, now it's a init that wrap both
modules
@Andre-LA
Copy link
Owner Author

Seems that everything is setup and ready 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant