Skip to content

Commit

Permalink
Update to 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwerOxotnik committed Sep 7, 2023
1 parent aa3a9f3 commit 66526bb
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 408 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trim_trailing_whitespace = true
indent_style = tab
insert_final_newline = true

[*.{txt,yml}]
[*.{txt,yml,json}]
indent_style = space
indent_size = 2
insert_final_newline = false
Expand All @@ -24,7 +24,7 @@ indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = false

[*.{json,md}]
[*.md]
indent_style = tab
indent_size = 2
insert_final_newline = false
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ What it can do
--------------

* Filter parameters of commands
* Add switchable commands via map settings
* Add switchable, customizable commands via map settings
* Double check of commands
* Use built-in error handling of commands
* Use modular structure
* Remotely and safely disable your mod
* Auto adds remote access for rcon and for other mods/scenarios
* Auto publishing on [mods.portal.com](https://mods.factorio.com/) and on your GitHub repository

What it enables you to do
-------------------------

* Handle sounds by a [script](.scripts/handle_sounds.sh)
* Make switchable, simpler and safer [commands](models/BetterCommands/README.md)
* Make switchable, simpler and safer [commands](https://github.com/ZwerOxotnik/factorio-BetterCommands)
* Make "isolated" modules
* Expand your modules
* More possibilities to control logic
Expand Down Expand Up @@ -120,7 +121,6 @@ How to start?
* **Change or delete** .github/ISSUE_TEMPLATE/*
* **Change or delete** .github/workflows/* (please read [this](https://github.com/shanemadden/factorio-mod-portal-publish))
* Handle files in [control.lua](control.lua)
* Change settings in [models/BetterCommands/control.lua](models/BetterCommands/control.lua) if you want

Notes
-----
Expand Down Expand Up @@ -159,7 +159,7 @@ sudo apt install p7zip-full jq git -y
Optional Dependencies
---------------------

* <a href="github.com/ZwerOxotnik/zk-lib" target="_blank"><code>zk-lib</code></a> - for localization of [BetterCommands](models/BetterCommands/control.lua) and [event handler](/control.lua), currently
* <a href="github.com/ZwerOxotnik/zk-lib" target="_blank"><code>zk-lib</code></a> - for localization of [event handler](/control.lua), currently

‼️ Important Links (Translations, Discord Support)
---------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---------------------------------------------------------------------------------------------------
Version: 0.6.0
Date: 2023-09-07
Changes:
- Auto adds remote access for rcon and for other mods/scenarios
- Improved commands greatly
---------------------------------------------------------------------------------------------------
Version: 0.5.1
Date: 2022-01-07
Changes:
Expand Down
41 changes: 26 additions & 15 deletions const-commands.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
-- Recommended to know about https://lua-api.factorio.com/latest/LuaCommandProcessor.html#LuaCommandProcessor.add_command

--[[
--[[ Uses https://github.com/ZwerOxotnik/factorio-BetterCommands
Returns tables of commands without functions as command "settings". All parameters are optional!
Contains:
name :: string: The name of your /command. (default: key of the table)
description :: string or LocalisedString: The description of your command. (default: nil)
is_allowed_empty_args :: boolean: Ignores empty parameters in commands, otherwise stops the command. (default: true)
input_type :: string: filter for parameters by type of input. (default: nil)
possible variants:
"player" - Stops execution if can't find a player by parameter
"team" - Stops execution if can't find a team (force) by parameter
allow_for_server :: boolean: Allow execution of a command from a server (default: false)
only_for_admin :: boolean: The command can be executed only by admins (default: false)
Contains:
name :: string: The name of your /command. (default: key of the table)
description :: string or LocalisedString: The description of your command. (default: nil)
is_allowed_empty_args :: boolean: Ignores empty parameters in commands, otherwise stops the command. (default: true)
input_type :: string: Filter for parameters by type of input. (default: nil)
possible variants:
"player" - Stops execution if can't find a player by parameter
"team" - Stops execution if can't find a team (force) by parameter
allow_for_server :: boolean: Allow execution of a command from a server (default: false)
only_for_admin :: boolean: The command can be executed only by admins (default: false)
allow_for_players :: string[]: Allows to use the command for players with specified names (default: nil)
max_input_length :: uint: Max amount of characters for command (default: 500)
is_logged :: boolean: Logs the command into .log file (default: false)
alternative_names :: string[]: Alternative names for the command (all commands should be added) (default: nil)
is_one_time_use :: boolean: Disables the command after using it (default: false)
is_one_time_use_for_player :: boolean: Disables for a player after using it (default: false)
is_one_time_use_for_force :: boolean: Disables for a force after using it (default: false)
global_cooldown :: uint: The command can be used each N seconds (default: nil)
player_cooldown :: uint: The command can be used each N seconds for players (default: nil)
force_cooldown :: uint: The command can be used each N seconds for forces (default: nil)
disable_cooldown_for_admins :: boolean: Disables cooldown for admins (default: false)
disable_cooldown_for_server :: boolean: Disables cooldown for server (default: true)
]]--
---@type table<string, table>
return {}
---@type table<string, BetterCommand>
return {
}
33 changes: 31 additions & 2 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ require("defines")

---@type table<string, module>
local modules = {}
modules.better_commands = require("models/BetterCommands/control")
modules.example_module = require("models/example-module")
modules.data_consistency_example = require("models/data-consistency-example")
-- modules.empty_module = require("models.empty-module")


--- Adds https://github.com/ZwerOxotnik/factorio-BetterCommands if exists
if script.active_mods["BetterCommands"] then
local is_ok, better_commands = pcall(require, "__BetterCommands__/BetterCommands/control")
if is_ok then
better_commands.COMMAND_PREFIX = MOD_SHORT_NAME
modules.better_commands = better_commands
end
end


-- Safe disabling of this mod remotely on init stage
-- Useful for other map developers and in some rare cases for mod devs
if remote.interfaces["disable-" .. script.mod_name] then
Expand All @@ -29,7 +38,14 @@ if remote.interfaces["disable-" .. script.mod_name] then
module.on_init = update_global_data_on_disabling
end
else
modules.better_commands:handle_custom_commands(modules.example_module) -- adds commands
if modules.better_commands then
if modules.better_commands.handle_custom_commands then
modules.better_commands.handle_custom_commands(modules.example_module) -- adds commands
end
if modules.better_commands.expose_global_data then
modules.better_commands.expose_global_data()
end
end
end


Expand All @@ -45,6 +61,19 @@ event_handler = event_handler or require("event_handler")
event_handler.add_libraries(modules)


-- Auto adds remote access for rcon and for other mods/scenarios via zk-lib
if script.active_mods["zk-lib"] then
local is_ok, remote_interface_util = pcall(require, "__zk-lib__/static-libs/lualibs/control_stage/remote-interface-util")
if is_ok and remote_interface_util.expose_global_data then
remote_interface_util.expose_global_data()
end
local is_ok, rcon_util = pcall(require, "__zk-lib__/static-libs/lualibs/control_stage/rcon-util")
if is_ok and rcon_util.expose_global_data then
rcon_util.expose_global_data()
end
end


-- This is a part of "gvv", "Lua API global Variable Viewer" mod. https://mods.factorio.com/mod/gvv
-- It makes possible gvv mod to read sandboxed variables in the map or other mod if following code is inserted at the end of empty line of "control.lua" of each.
if script.active_mods["gvv"] then require("__gvv__.gvv")() end
8 changes: 5 additions & 3 deletions defines.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Change everything in this file in your mod!
-- Change data in this file in your mod!
local _data = {
MOD_NAME = "example-mod",
MOD_PATH = "__example-mod__",
Expand All @@ -8,8 +8,10 @@ local _data = {
AUTHOR = "ZwerOxotnik"
}

if not MAKE_DEFINE_GLOBAL or (not IS_DATA_STAGE and script and script.active_mods) then
return _data
if (not IS_DATA_STAGE and script and script.active_mods) then
if not MAKE_DEFINE_GLOBAL then
return _data
end
end

--- Make content of _data global
Expand Down
25 changes: 13 additions & 12 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "example-mod",
"version": "0.5.2",
"factorio_version": "1.1",
"title": "Example mod",
"author": "Put your nickname",
"contact": "Put your contacts",
"homepage": "Put a link",
"description": "See locale/en ",
"dependencies": [
"? zk-lib >= 0.10.0",
"(?) gvv"
]
"name": "example-mod",
"version": "0.6.0",
"factorio_version": "1.1",
"title": "Example mod",
"author": "Put your nickname",
"contact": "Put your contacts",
"homepage": "Put a link",
"description": "Put description here",
"dependencies": [
"? zk-lib >= 0.10.0",
"? BetterCommands",
"(?) gvv"
]
}
19 changes: 0 additions & 19 deletions models/BetterCommands/README.md

This file was deleted.

Loading

0 comments on commit 66526bb

Please sign in to comment.