noita-mapcap/files/libraries/noita-api
David Vogel 931c4df18a Refactoring, fixes and cleanup
- Move utils into Noita API wrapper
- Always overwrite require, with a fallback to the original
- Add library directory of mod to package.path, instead of the files directory
- Add Noita data/scripts/lib to package.path
- Fix dofile error handling
- Fix require not working right when module returns false
- Add init.lua to Noita API wrapper, that contains a table of all modules
- Fix Utils.GetSpecialDirectory
- Update README.md
2022-07-23 20:43:04 +02:00
..
annotations.lua Fix some more stuff 2022-07-23 17:45:06 +02:00
camera.lua Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
compatibility.lua Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
component.lua Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
debug.lua Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
entity.lua Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
init.lua Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
json.lua Remove not needed class annotations 2022-07-23 17:57:44 +02:00
README.md Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
utils.lua Refactoring, fixes and cleanup 2022-07-23 20:43:04 +02:00
vec2.lua Cleanup, Refactoring and Fixes 2022-07-23 17:36:21 +02:00

Noita API wrapper

This wraps the Noita API and exposes it in a more dev friendly way. Entities and components are returned as objects. All entity and component related functions are now methods of the respective objects.

The library also comes with EmmyLua annotations, so code completion, type information and other hints will work in any IDE or editor that supports this. (Only tested with VSCode for now)

State

Working but incomplete. If something is missing, you need to add it!

It would be nice to have code generation to generate this library from the official files, but meh. But this would be too complex, as there are a lot of edge cases and stuff that has to be handled in a specific way.

Usage

  1. Copy this into your mod so you get the following file path: mods/your-mod/files/libraries/noita-api/README.md.

  2. Add the following at the beginning of your mod's init.lua:

    -- Emulate and override some functions and tables to make everything conform more to standard lua.
    -- This will make `require` work, even in sandboxes with restricted Noita API.
    local libPath = "mods/noita-mapcap/files/libraries/"
    dofile(libPath .. "noita-api/compatibility.lua")(libPath)
    

    You need to adjust libPath to point into your mod's library directory. The trailing / is needed!

After that you can import and use the library like this:

local EntityAPI = require("noita-api.entity")

local x, y, radius = 10, 10, 100

local entities = EntityAPI.GetInRadius(x, y, radius)
for _, entity in ipairs(entities) do
    print(entity:GetName())

    local components = entity:GetComponents("VelocityComponent")
    for _, component in ipairs(components) do
        entity:SetComponentsEnabled(component, false)
    end
end

To include the whole set of API commands, use:

local NoitaAPI = require("noita-api")