Configuration now with overriding mechanism

master
Ben Deutsch 2015-11-01 22:40:05 +01:00
parent fbc1d62c5f
commit 72014ec938
4 changed files with 252 additions and 212 deletions

View File

@ -1,105 +1,64 @@
--[[
Configuration for Thirsty.
Configuration from default, moddir and worlddir, in that order.
See init.lua for license.
]]
--[[
-- change these for other mods
local M = thirsty
local modname = 'thirsty'
local fileroot = modname
Default values
-- make sure config exists; keep constant reference to it
local C = M.config or {}
M.config = C
]]
thirsty.config = {
stash_filename = 'thirsty.dat',
tick_time = 0.5,
-- Tier 0
thirst_per_second = 1.0 / 20.0,
damage_per_second = 1.0 / 10.0, -- when out of hydration
stand_still_for_drink = 1.0,
stand_still_for_afk = 120.0, -- 2 Minutes
regen_from_node = {
-- value: hydration regen per second
['default:water_source'] = 0.5,
['default:water_flowing'] = 0.5,
['default:river_water_source'] = 0.5,
['default:river_water_flowing'] = 0.5,
},
-- which nodes can we drink from (given containers)
node_drinkable = {
['default:water_source'] = true,
['default:water_flowing'] = true,
['default:river_water_source'] = true,
['default:river_water_flowing'] = true,
['thirsty:drinking_fountain'] = true,
},
drink_from_container = {
-- value: max hydration when drinking with item
['thirsty:wooden_bowl'] = 25,
['thirsty:steel_canteen'] = 25,
['thirsty:bronze_canteen'] = 25,
},
container_capacity = {
-- value: hydro capacity in item
['thirsty:steel_canteen'] = 40,
['thirsty:bronze_canteen'] = 60,
},
drink_from_node = {
-- value: max hydration when drinking from node
['thirsty:drinking_fountain'] = 30,
},
-- fountains are marked with 'f', water with 'w'
-- to determine the fountain level
fountain_type = {
['thirsty:water_fountain'] = 'f',
['thirsty:water_extender'] = 'f',
['default:water_source'] = 'w',
['default:water_flowing'] = 'w',
['default:river_water_source'] = 'w',
['default:river_water_flowing'] = 'w',
},
regen_from_fountain = 0.5, -- compare regen_from_node
fountain_height = 4,
fountain_max_level = 20,
fountain_distance_per_level = 5,
extraction_for_item = {
['thirsty:extractor']= 0.6,
},
injection_for_item = {
['thirsty:injector'] = 0.5,
},
register_vessels = true,
register_bowl = true,
register_canteens = true,
register_drinking_fountain = true,
register_fountains = true,
register_amulets = true,
}
-- read more configuration from thirsty.conf
local filename = minetest.get_modpath('thirsty') .. "/thirsty.conf"
local file, err = io.open(filename, 'r')
if file then
file:close() -- was just for checking existance
local confcode, err = loadfile(filename)
if confcode then
confcode()
else
minetest.log("error", "Could not load thirsty.conf: " .. err)
local function try_config_file(filename)
--print("Config from "..filename)
local file, err = io.open(filename, 'r')
if file then
file:close() -- was just for checking existance
local confcode, err = loadfile(filename)
if confcode then
confcode()
if C ~= M.config then
-- M.config was overriden, merge
for key, value in pairs(M.config) do
if type(value) == 'table' and type(C[key]) == 'table' and not value.CLEAR then
for k, v in pairs(value) do
C[key][k] = value[k]
end
else
-- copy (not a table, or asked to clear)
C[key] = value
end
end
else
-- no override? Empty, or file knows what it is doing.
end
else
minetest.log("error", "Could not load " .. filename .. ": " .. err)
end
end
end
-- read starting configuration from <modname>.default.conf
try_config_file(minetest.get_modpath(modname) .. "/" .. fileroot .. ".default.conf")
-- next, install-specific copy in modpath
try_config_file(minetest.get_modpath(modname) .. "/" .. fileroot .. ".conf")
-- last, world-specific copy in worldpath
try_config_file(minetest.get_worldpath() .. "/" .. fileroot .. ".conf")
-- remove any special keys from tables
for key, value in pairs(C) do
if type(value) == 'table' then
value.CLEAR = nil
end
end
-- write back
M.config = C

View File

@ -40,7 +40,7 @@ thirsty = {
-- Configuration variables
config = {
-- see configuration.lua
-- configuration in thirsty.default.conf
},
-- the players' values
@ -70,10 +70,13 @@ thirsty = {
-- general settings
time_next_tick = 0.0,
}
dofile(minetest.get_modpath('thirsty')..'/persistent_player_attributes.lua')
local M = thirsty
dofile(minetest.get_modpath('thirsty')..'/configuration.lua')
local C = M.config
dofile(minetest.get_modpath('thirsty')..'/persistent_player_attributes.lua')
local PPA = M.persistent_player_attributes
thirsty.time_next_tick = thirsty.config.tick_time
@ -86,9 +89,3 @@ minetest.register_globalstep(thirsty.main_loop)
dofile(minetest.get_modpath('thirsty')..'/components.lua')
-- read on startup
--thirsty.read_stash()
-- write on shutdown
--minetest.register_on_shutdown(thirsty.write_stash)

View File

@ -1,109 +0,0 @@
--[[
Configuration file for Thirsty.
Copy this file to "thirsty.conf" and place it in the mod's directory.
Modify to suit your needs; it will not get overwritten if you update
Thirsty.
The following values are the default values; you can safely remove
or comment out any line you're not interested in. Commented lines
start with '--'
]]
-- Main loop tick time, in seconds
-- Increasing this value will make Thirsty less accurate, but will
-- generally behave the same.
thirsty.config.tick_time = 0.5
-- Thirst per second (full hydration is 20 hydro points)
thirsty.config.thirst_per_second = 1.0 / 20.0
-- Damage per second if completely thirsty / out of hydration
thirsty.config.damage_per_second = 1.0 / 10.0
-- How long in seconds you have to remain still to drink from standing
-- in water
thirsty.config.stand_still_for_drink = 1.0
-- How long in seconds of not moving before a player is deemed AFK
-- (away from keyboard), such players no longer get thirsty or damaged
thirsty.config.stand_still_for_afk = 120.0 -- 2 Minutes
-- regen_from_node is a table defining, for each node type, the
-- amount of hydro per second a player drinks by standing in it.
-- Assign 'nil' to stop a player from drinking from this node type.
thirsty.config.regen_from_node['default:water_source'] = 0.5
thirsty.config.regen_from_node['default:water_flowing'] = 0.5
thirsty.config.regen_from_node['default:river_water_source'] = 0.5
thirsty.config.regen_from_node['default:river_water_flowing'] = 0.5
-- node_drinkable: which nodes can we drink from, given a
-- container (a cup, a bowl etc.)
thirsty.config.node_drinkable['default:water_source'] = true
thirsty.config.node_drinkable['default:water_flowing'] = true
thirsty.config.node_drinkable['default:river_water_source'] = true
thirsty.config.node_drinkable['default:river_water_flowing'] = true
thirsty.config.node_drinkable['thirsty:drinking_fountain'] = true
-- drink_from_container: the hydration you drink to when
-- using each container. Remember that "full hydration" is
-- 20 points; these should be more to reward using them.
thirsty.config.drink_from_container['thirsty:wooden_bowl'] = 25
thirsty.config.drink_from_container['thirsty:steel_canteen'] = 25
thirsty.config.drink_from_container['thirsty:bronze_canteen'] = 25
-- container_capacity: how much hydration each container (canteens)
-- can hold. Remember that "full hydration" is 20 points
thirsty.config.container_capacity['thirsty:steel_canteen'] = 40
thirsty.config.container_capacity['thirsty:bronze_canteen'] = 60
-- drink_from_node: if you use one of these nodes (i.e. fountains),
-- even without cups or bowls, how full will you get?
thirsty.config.drink_from_node['thirsty:drinking_fountain'] = 30
-- fountain_type: when scanning the surroundings of fountains,
-- which nodes are "fountains" and which are "water"? You need
-- at least one "fountain" and one "water" per fountain level.
thirsty.config.fountain_type['thirsty:water_fountain'] = 'f'
thirsty.config.fountain_type['thirsty:water_extender'] = 'f'
thirsty.config.fountain_type['default:water_source'] = 'w'
thirsty.config.fountain_type['default:water_flowing'] = 'w'
thirsty.config.fountain_type['default:river_water_source'] = 'w'
thirsty.config.fountain_type['default:river_water_flowing'] = 'w'
-- Regeneration from being within a fountain's radius; see also
-- regen_from_node (it's as if you're standing in water)
thirsty.config.regen_from_fountain = 0.5
-- How far should the fountain scanning pyramid go?
thirsty.config.fountain_height = 4
-- The max level of a fountain
thirsty.config.fountain_max_level = 20
-- How many nodes away can you still benefit from a fountain,
-- per fountain level
thirsty.config.fountain_distance_per_level = 5
-- How much hydration does a given item *extract* (pull out of the air)
thirsty.config.extraction_for_item['thirsty:extractor'] = 0.6
-- How much hydration does a given item *inject* (fill you up with)
thirsty.config.injection_for_item['thirsty:injector'] = 0.5
-- Registration of individual components
-- These flags enable or disable the predefined components included
-- in this mod. They do *not* enable or disable the functionality.
-- Should we augment the vessels from the "vessels" mod?
thirsty.config.register_vessels = true
-- Add the wooden bowl and crafting recipe?
thirsty.config.register_bowl = true
-- Add the canteens and crafting recipes?
thirsty.config.register_canteens = true
-- Add the drinking fountain and crafting recipes?
thirsty.config.register_drinking_fountain = true
-- Add the fountain and extenders and crafting recipes?
thirsty.config.register_fountains = true
-- Add the amulets (extractor / injector) and crafting recipes?
thirsty.config.register_amulets = true

193
thirsty.default.conf Normal file
View File

@ -0,0 +1,193 @@
--[[
Thirsty configuration
-----------------------------
To modify the configuration without fear of it being overwritten
by an update of this mod, copy this file to
thirsty.conf
in the mod directory or the directory of a specific world, and
modify away. The mod will read configuration first from the
default file, then from the mod directory copy, and finally from
the world directory copy.
The settings from these locations will be merged together in an
intelligent fashion. Normal entries in the config table will get
overwritten. Table entries (those with {} at the left of the =)
will get merged together, unless the special table entry 'CLEAR'
is given, with a true value. This merging does not go deeper than
one level, but this should be sufficient.
]]
thirsty.config = {
--[[ The period, in seconds, in which this mod updates values.
Changing this will not directly affect other values, but
may change computation load or accuracy.
]]
tick_time = 0.5,
-------------------------------------------
-- Tier 0: basics, and standing in water --
-------------------------------------------
-- Thirst per second (full hydration is 20 hydro points)
thirst_per_second = 1.0 / 20.0,
-- Damage per second if completely thirsty / out of hydration
damage_per_second = 1.0 / 10.0,
--[[ How long in seconds you have to remain still to drink
from standing in water
]]
stand_still_for_drink = 1.0,
--[[ How long in seconds of not moving before a player is deemed
AFK (away from keyboard), such players no longer get thirsty
or damaged
]]
stand_still_for_afk = 120.0, -- 2 Minutes
--[[ regen_from_node is a table defining, for each node type, the
amount of hydro per second a player drinks by standing in it.
Assign 0 to stop a player from drinking from this node type.
]]
regen_from_node = {
['default:water_source'] = 0.5,
['default:water_flowing'] = 0.5,
['default:river_water_source'] = 0.5,
['default:river_water_flowing'] = 0.5,
},
---------------------------------
-- Tier 1: drinking with bowls --
---------------------------------
--[[ node_drinkable: which nodes can we drink from, given a
container (a cup, a bowl etc.)
]]
node_drinkable = {
['default:water_source'] = true,
['default:water_flowing'] = true,
['default:river_water_source'] = true,
['default:river_water_flowing'] = true,
['thirsty:drinking_fountain'] = true,
},
--[[ drink_from_container: the hydration you drink to when
using each container. Remember that "full hydration" is
20 points; these should be more to reward using them.
]]
drink_from_container = {
['thirsty:wooden_bowl'] = 25,
['thirsty:steel_canteen'] = 25,
['thirsty:bronze_canteen'] = 25,
},
----------------------
-- Tier 2: canteens --
----------------------
--[[ container_capacity: how much hydration each container
(canteens) can hold. Remember that "full hydration" is
20 points
]]
container_capacity = {
['thirsty:steel_canteen'] = 40,
['thirsty:bronze_canteen'] = 60,
},
--------------------------------
-- Tier 3: drinking fountains --
--------------------------------
--[[ drink_from_node: if you use one of these node
(i.e. fountains), even without cups or bowls, how full
will you get?
]]
drink_from_node = {
['thirsty:drinking_fountain'] = 30,
},
-------------------------------------
-- Tier 4: free-standing fountains --
-------------------------------------
--[[ fountain_type: when scanning the surroundings of fountains,
which nodes are "fountains" and which are "water"? You need
at least one "fountain" and one "water" per fountain level.
]]
fountain_type = {
['thirsty:water_fountain'] = 'f',
['thirsty:water_extender'] = 'f',
['default:water_source'] = 'w',
['default:water_flowing'] = 'w',
['default:river_water_source'] = 'w',
['default:river_water_flowing'] = 'w',
},
--[[ Regeneration from being within a fountain's radius; see also
regen_from_node (it's as if you're standing in water)
]]
regen_from_fountain = 0.5,
-- How far should the fountain scanning pyramid go?
fountain_height = 4,
-- The max level of a fountain
fountain_max_level = 20,
--[[ How many nodes away can you still benefit from a fountain,
per fountain level
]]
fountain_distance_per_level = 5,
---------------------
-- Tier 5: amulets --
---------------------
--[[ How much hydration does a given item *extract*
(pull out of the air)
]]
extraction_for_item = {
['thirsty:extractor']= 0.6,
},
--[[ How much hydration does a given item *inject*
(fill you up with)
]]
injection_for_item = {
['thirsty:injector'] = 0.5,
},
---------------------------------------
-- Toggle node and craft definitions --
---------------------------------------
--[[ These flags enable or disable the predefined components
included in this mod. They do *not* enable or disable
the functionality.
]]
-- Should we augment the vessels from the "vessels" mod?
register_vessels = true,
-- Add the wooden bowl and crafting recipe?
register_bowl = true,
-- Add the canteens and crafting recipes?
register_canteens = true,
-- Add the drinking fountain and crafting recipes?
register_drinking_fountain = true,
-- Add the fountain and extenders and crafting recipes?
register_fountains = true,
-- Add the amulets (extractor / injector) and crafting recipes?
register_amulets = true,
}