Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
factorio.moon-logic: add wire renaming options
  • Loading branch information
mk-fg committed Sep 2, 2020
1 parent d9d5153 commit dec7baf
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 23 deletions.
6 changes: 6 additions & 0 deletions factorio/Moon_Logic/changelog.txt
@@ -1,3 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 0.0.4
Date: 2020-09-02
Features:
- Add startup mod options to change red/green lua env vars and gui labels. Useful with other mods that change colors.

---------------------------------------------------------------------------------------------------
Version: 0.0.3
Date: 2020-09-02
Expand Down
25 changes: 25 additions & 0 deletions factorio/Moon_Logic/config.lua
@@ -0,0 +1,25 @@
local conf = {}

-- Configurable wire/network names for players that have these changed
-- in the game (e.g. via colorblind modes) or just don't like default names in lua env.
-- This changes descriptions in the guis as well.
conf.red_wire_name = 'red'
conf.green_wire_name = 'green'

-- Interval between raising global alerts on lua errors, in ticks
conf.logic_alert_interval = 10 * 60

-- Function to use for debug=true logging and game.log() calls in lua env
conf.debug_print = print


function conf.update_from_settings()
local k_conf
for _, k in ipairs{'red-wire-name', 'green-wire-name'} do
k_conf = k:gsub('%-', '_')
if conf[k_conf] == nil then error(('BUG - config key typo: %s'):format(k)) end
conf[k_conf] = settings.startup[k].value
end
end

return conf
21 changes: 11 additions & 10 deletions factorio/Moon_Logic/control.lua
@@ -1,4 +1,7 @@
gui_manager, comb_gui = table.unpack(require('gui'))
local gui_manager, comb_gui = table.unpack(require('gui'))

local conf = require('config')
conf.update_from_settings()


-- Stores code and built environments as {code=..., ro=..., vars=...}
Expand All @@ -7,11 +10,6 @@ local Combinators = {}
local CombinatorEnv = {} -- to avoid self-recursive tables


local conf = {}
conf.logic_alert_interval = 10 * 60 -- raising global alerts on lua errors
conf.debug_print = print


local function tt(s, value)
-- Helper to make padded table from other table keys or a string of keys
local t = {}
Expand Down Expand Up @@ -172,14 +170,16 @@ local function mlc_init(e)
local env_wire_green = tc(env_wire_red)
env_wire_green._wire = 'green'

local env_ro = setmetatable({ -- sandbox_env_base + mlc_env proxies
local env_ro = { -- sandbox_env_base + mlc_env proxies
uid = mlc_env._uid,
out = setmetatable(mlc_env._out, {__index=cn_output_table_value}),
red = setmetatable(env_wire_red, {
__index=cn_input_signal_get, __newindex=cn_input_signal_set }),
green = setmetatable(env_wire_green, {
__index=cn_input_signal_get, __newindex=cn_input_signal_set }),
}, {__index=sandbox_env_base})
__index=cn_input_signal_get, __newindex=cn_input_signal_set }) }
env_ro[conf.red_wire_name] = env_ro.red
env_ro[conf.green_wire_name] = env_ro.green
setmetatable(env_ro, {__index=sandbox_env_base})

if not mlc.vars.var then mlc.vars.var = {} end
local env = setmetatable(mlc.vars, { -- env_ro + mlc.vars
Expand Down Expand Up @@ -274,7 +274,8 @@ local function update_signals_in_guis()
if gui_flow then gui_flow.clear() end
for k, color in pairs{red={r=1,g=0.3,b=0.3}, green={r=0.3,g=1,b=0.3}} do
for sig, v in pairs(cn_wire_signals(e, defines.wire_type[k])) do
cap = gui_flow.add{type='label', name=k..'_'..sig, caption=sig..'= '..v}
cap = gui_flow.add{ type='label', name=k..'_'..sig,
caption=('[%s] %s = %s'):format(conf[k..'_wire_name'], sig, v) }
cap.style.font_color = color
end end
cap = format_mlc_err_msg(global.combinators[uid]) or ''
Expand Down
Binary file removed factorio/Moon_Logic/graphics/bug.png
Binary file not shown.
13 changes: 9 additions & 4 deletions factorio/Moon_Logic/gui.lua
@@ -1,3 +1,5 @@
local conf = require('config')

local gui_manager = {}
local comb_gui_class = {}

Expand Down Expand Up @@ -39,8 +41,10 @@ local function help_window_toggle(pn)
local lines = {
'Special variables available/handled in Lua environment:',
' uid (int) -- globally-unique number of this combinator.',
' red {signal-name=value, ...} -- signals in the red network (read only).',
' green {signal-name=value, ...} -- same for the green network.',
(' %s {signal-name=value, ...} -- signals in the %s network (read only).')
:format(conf.red_wire_name, conf.red_wire_name),
(' %s {signal-name=value, ...} -- same for the %s network.')
:format(conf.green_wire_name, conf.green_wire_name),
' out {signal-name=value, ...} -- a table with all signals sent to networks.',
' They are permanent, so to remove a signal you need to set its entry',
' to nil or 0, or flush all signals by entering "out = {}" (creates a fresh table).',
Expand Down Expand Up @@ -115,8 +119,9 @@ function gui_manager:create_gui(player, entity)
name='mlc_gui_'..eid, caption='', direction='vertical' }
gui.location = {100, 150}
this_gui_data.gui = gui
gui.caption = ( 'Moon Logic [%s] -'..
' red {}, green {}, out {}, var {}, delay (int)' ):format(eid)
gui.caption =
('Moon Logic [%s] - %s {}, %s {}, out {}, var {}, delay (int)')
:format(eid, conf.red_wire_name, conf.green_wire_name)
gui.style.top_padding = 1
gui.style.right_padding = 4
gui.style.bottom_padding = 4
Expand Down
2 changes: 1 addition & 1 deletion factorio/Moon_Logic/info.json
@@ -1,6 +1,6 @@
{
"name": "Moon_Logic",
"version": "0.0.3",
"version": "0.0.4",
"factorio_version": "1.0",
"dependencies": ["base >= 1.0"],
"title": "Moon Logic",
Expand Down
Expand Up @@ -19,3 +19,11 @@ mlc=Moon Logic Combinator
[virtual-signal-name]
mlc_error=MoonLogicCombinator Error
[mod-setting-name]
red-wire-name=Red Wire Label
green-wire-name=Green Wire Label
[mod-setting-description]
red-wire-name=Lua environment name for in-game "red" circuit network values.\nChanges all labels in the GUIs as well.
green-wire-name=Lua environment name for in-game "green" circuit network values.\nChanges all labels in the GUIs as well.
8 changes: 0 additions & 8 deletions factorio/Moon_Logic/prototypes/sprites.lua
@@ -1,13 +1,5 @@
data:extend{

{ type = 'sprite',
name = 'mlc_bug',
filename = '__Moon_Logic__/graphics/bug.png',
priority = 'extra-high-no-scale',
width = 32,
height = 32,
flags = {'no-crop', 'icon'},
scale = 0.2 },
{ type = 'sprite',
name = 'mlc_forward',
filename = '__Moon_Logic__/graphics/forward.png',
Expand Down
14 changes: 14 additions & 0 deletions factorio/Moon_Logic/settings.lua
@@ -0,0 +1,14 @@
local conf = require('config')

data:extend{
{ order = '01',
setting_type = 'startup',
name = 'red-wire-name',
type = 'string-setting',
default_value = conf.red_wire_name },
{ order = '02',
setting_type = 'startup',
name = 'green-wire-name',
type = 'string-setting',
default_value = conf.green_wire_name },
}

0 comments on commit dec7baf

Please sign in to comment.