Updates to antum core mod

master
Jordan Irwin 2021-05-25 01:01:06 -07:00
parent 4b3bdb3b3e
commit 2d2d8efd82
6 changed files with 67 additions and 119 deletions

View File

@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)
Copyright © 2017 Jordan Irwin (AntumDeluge)
Copyright © 2017-2021 Jordan Irwin (AntumDeluge)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View File

@ -1,49 +1,39 @@
--[[ LICENSE HEADER
MIT License
The MIT License (MIT)
Copyright © 2017 Jordan Irwin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright © 2017-2021 Jordan Irwin (AntumDeluge)
See: LICENSE.txt
--]]
-- Displays a message in the log
function antum.log(level, msg)
local prefix = "[" .. core.get_current_modname() .. "] "
if msg == nil then
core.log(prefix .. level)
function antum.log(lvl, msg)
if not msg then
msg = lvl
lvl = nil
end
msg = "[" .. core.get_current_modname() .. "] " msg
if not lvl then
core.log(msg)
else
core.log(level, prefix .. msg)
core.log(lvl, msg)
end
end
function antum.logAction(msg)
antum.log("warning" "\antum.logAction\" deprecated, use \"antum.log\"")
antum.log("action", msg)
end
function antum.logWarn(msg)
antum.log("warning" "\antum.logWarn\" deprecated, use \"antum.log\"")
antum.log("warning", msg)
end
function antum.logError(msg)
antum.log("warning" "\antum.logError\" deprecated, use \"antum.log\"")
antum.log("error", msg)
end
@ -52,10 +42,9 @@ end
function antum.fileExists(file_path)
local fexists = io.open(file_path, "r")
if fexists == nil then
return false
end
if not fexists then return false end
io.close(fexists)
return true
end
@ -66,20 +55,14 @@ function antum.getCurrentModPath()
end
--[[ Loads a mod sub-script.
@param script_name
Name or base name of the script file
@param lua_ext
type: bool
default: true
description: If 'true', appends '.lua' extension to script filename
]]
--- Loads a mod sub-script.
--
-- @function antum.loadScript
-- @param script_name Name or base name of the script file.
-- @tparam bool lua_ext If `true`, appends ".lua" extension to script filename (default: `true`).
function antum.loadScript(script_name, lua_ext)
-- Default 'true'
if lua_ext == nil then
lua_ext = true
end
lua_ext = lua_ext ~= false
local script = antum.getCurrentModPath() .. "/" .. script_name
if lua_ext then
@ -89,15 +72,15 @@ function antum.loadScript(script_name, lua_ext)
if antum.fileExists(script) then
dofile(script)
else
antum.logError("Could not load, script does not exists: " .. script)
antum.log("error", "Could not load, script does not exists: " .. script)
end
end
-- Loads multiple mod sub-scripts
function antum.loadScripts(script_list)
for I in pairs(script_list) do
antum.loadScript(script_list[I])
for _, s in ipairs(script_list) do
antum.loadScript(s)
end
end
@ -105,7 +88,7 @@ end
-- Registers a craft & displays a log message
function antum.registerCraft(def)
if antum.verbose then
antum.logAction("Registering craft recipe for \"" .. def.output .. "\"")
antum.log("action", "Registering craft recipe for \"" .. def.output .. "\"")
end
core.register_craft(def)
@ -115,7 +98,7 @@ end
-- De-registers a craft by output
function antum.clearCraftOutput(output)
if antum.verbose then
antum.logAction("Clearing craft by output: " .. output)
antum.log("action", "Clearing craft by output: " .. output)
end
core.clear_craft({
@ -137,7 +120,7 @@ function antum.clearCraftRecipe(recipe)
recipe_string = recipe_string .. " {" .. table.concat(recipe[I], " + ") .. "}"
end
antum.logAction(" Clearing craft by recipe: " .. recipe_string)
antum.log("action", "Clearing craft by recipe: " .. recipe_string)
end
core.clear_craft({
@ -162,7 +145,7 @@ end
-- Checks if dependencies are satisfied
function antum.dependsSatisfied(depends)
for index, dep in ipairs(depends) do
for _, dep in ipairs(depends) do
if not core.get_modpath(dep) then
return false
end
@ -172,32 +155,22 @@ function antum.dependsSatisfied(depends)
end
--[[
Retrieves an item from registered items using name string.
@param item_name
Item name string to search for
@return
Item object with name matching 'item_name' parameter
]]
--- Retrieves an item from registered items using name string.
--
-- @function antum.getItem
-- @tparam string item_name Item name to search for.
-- @treturn ItemRef Item with name matching `item_name` parameter.
function antum.getItem(item_name)
for index in pairs(core.registered_items) do
if core.registered_items[index].name == item_name then
return core.registered_items[index]
end
end
return core.registered_items[item_name]
end
--[[ Retrieves a list of items containing a string.
@param substring
String to match within item names
@param case_sensitive
If 'true', 'substring' case must match that of item name
@return
List of item names matching 'substring'
]]
--- Retrieves a list of items containing a string.
--
-- @function antum.getItemNames
-- @tparam string substring String to match within item names.
-- @tparam bool case_sensitive If `true`, `substring` case must match that of item name.
-- @treturn table List of item names matching `substring`.
function antum.getItemNames(substring, case_sensitive)
antum.logAction("Checking registered items for \"" .. substring .. "\" in item name ...")
@ -224,27 +197,23 @@ function antum.getItemNames(substring, case_sensitive)
end
--[[ Un-registers an item & converts its name to an alias.
@param item_name
Name of the item to override
@param alias_of
Name of the item to be aliased
]]
--- Un-registers an item & converts its name to an alias.
--
-- @function antum.convertItemToAlias
-- @tparam string item_name Name of the item to override.
-- @tparam string alias_of Name of the item to be aliased.
function antum.convertItemToAlias(item_name, alias_of)
antum.logAction("Overridding \"" .. item_name .. "\" with \"" .. alias_of .. "\"")
antum.log("action", "Overridding \"" .. item_name .. "\" with \"" .. alias_of .. "\"")
core.unregister_item(item_name)
core.register_alias(item_name, alias_of)
end
--[[ Changes object description.
@param item_name
Name of item to be altered
@param description
New string description value
]]
--- Changes object description.
--
-- @function antum.overrideItemDescription
-- @tparam string item_name Name of item to be altered.
-- @tparam string description New description.
function antum.overrideItemDescription(item_name, description)
-- Original item definition
local item = antum.getItem(item_name)
@ -253,19 +222,16 @@ function antum.overrideItemDescription(item_name, description)
-- Unregister original item
core.unregister_item(item.name)
core.register_craftitem(":" .. item.name, item)
end
--[[ Registers a new item under "antum" namespace
@param name
Base name of new item
@param def
Item definition
]]
--- Registers a new item under "antum" namespace.
--
-- @function antum.registerItem
-- @tparam string name Base name of new item.
-- @tparam table def Item definition.
function antum.registerItem(name, def)
name = ":" .. antum.namespace .. ":" .. name
name = antum.modname .. ":" .. name
core.register_craftitem(name, def)
end

View File

@ -1,34 +1,16 @@
--[[ LICENSE HEADER
MIT License
The MIT License (MIT)
Copyright © 2017 Jordan Irwin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright © 2017-2021 Jordan Irwin (AntumDeluge)
See: LICENSE.txt
--]]
antum = {}
antum.modname = core.get_current_modname()
antum.modpath = core.get_modpath(antum.modname)
antum.namespace = "antum"
antum.verbose = false
if core.settings:get_bool("log_mods") then
@ -36,5 +18,5 @@ if core.settings:get_bool("log_mods") then
end
-- Load API functions first
-- Load API functions
dofile(antum.modpath .. "/api.lua")

View File

@ -1 +0,0 @@
Mods designed specifically for the Antum game.

View File

@ -0,0 +1 @@
Mods created specifically for the Antum game.