Improve config loading and other fixes

This commit is contained in:
stujones11 2019-03-20 19:25:00 +00:00
parent cb922eaafd
commit cf6122ca0c
5 changed files with 36 additions and 17 deletions

View file

@ -103,6 +103,7 @@ API Documentation
### Methods ### Methods
* `shooter.register_weapon(name, definition)`: Register a shooting weapon. -- See "Weapon Definition" * `shooter.register_weapon(name, definition)`: Register a shooting weapon. -- See "Weapon Definition"
* `shooter.get_configuration(config)`: Loads matching config settings into a table ref `config`
* `shooter.spawn_particles(pos, particles)`: Adds particles at the specified position * `shooter.spawn_particles(pos, particles)`: Adds particles at the specified position
* `particles` is an optional table of overrides for `shooter.default_particles` * `particles` is an optional table of overrides for `shooter.default_particles`
* `shooter.play_node_sound(node, pos)`: Plays the registered 'dug' sound for the node at `pos` * `shooter.play_node_sound(node, pos)`: Plays the registered 'dug' sound for the node at `pos`

View file

@ -79,7 +79,7 @@ shooter.register_weapon = function(name, def)
inventory_image = def.inventory_image, inventory_image = def.inventory_image,
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if type(def.on_use) == "function" then if type(def.on_use) == "function" then
itemstack = def.on_use, pointed_thing) itemstack = def.on_use(itemstack, user, pointed_thing)
end end
local spec = table.copy(def.spec) local spec = table.copy(def.spec)
if shooter.fire_weapon(user, itemstack, spec) then if shooter.fire_weapon(user, itemstack, spec) then
@ -115,6 +115,21 @@ shooter.register_weapon = function(name, def)
}) })
end end
shooter.get_configuration = function(conf)
for k, v in pairs(conf) do
local setting = minetest.settings:get("shooter_"..k)
if type(v) == "number" then
setting = tonumber(setting)
elseif type(v) == "boolean" then
setting = minetest.settings:get_bool("shooter_"..k)
end
if setting ~= nil then
conf[k] = setting
end
end
return conf
end
shooter.spawn_particles = function(pos, particles) shooter.spawn_particles = function(pos, particles)
particles = particles or {} particles = particles or {}
if not config.enable_particle_fx == true or particles.amount == 0 then if not config.enable_particle_fx == true or particles.amount == 0 then

View file

@ -50,17 +50,7 @@ end
-- Load Configuration -- Load Configuration
for name, config in pairs(shooter.config) do shooter.config = shooter.get_configuration(shooter.config)
local setting = minetest.settings:get("shooter_"..name)
if type(config) == "number" then
setting = tonumber(setting)
elseif type(config) == "boolean" then
setting = minetest.settings:get_bool("shooter_"..name)
end
if setting ~= nil then
shooter.config[name] = setting
end
end
shooter.default_particles.texture = shooter.config.explosion_texture shooter.default_particles.texture = shooter.config.explosion_texture
-- Legacy Entity Support -- Legacy Entity Support

View file

@ -5,6 +5,18 @@ Depends: shooter, wool, dye
Adds a crossbow with colored arrows. Adds a crossbow with colored arrows.
Configuration
=============
Override the following default settings by adding them to your minetest.conf file
* `shooter_crossbow_uses = 50`: Number of crossbow uses
* `shooter_arrow_lifetime = 180`: Arrow exipiry time in seconds
* `shooter_arrow_fleshy = 2`: Arrow 'fleshy' damage level
* `shooter_arrow_object_attach = false`: Attach arrows to objects when hit
* Experimental, currently does not work well with oversized selection boxes!
Crafting Crafting
======== ========

View file

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
local config = { local config = {
crossbow_uses = 50, crossbow_uses = 50,
arrow_lifetime = 180, arrow_lifetime = 180,
arrow_fleshy = 2,
arrow_object_attach = false, arrow_object_attach = false,
} }
@ -30,13 +31,13 @@ for name, _ in pairs(config) do
if minetest.global_exists(global) then if minetest.global_exists(global) then
config[name] = _G[global] config[name] = _G[global]
end end
local setting = minetest.settings:get("shooter_"..name)
if type(setting) == "string" then
config[name] = tonumber(setting)
end
end end
local arrow_tool_caps = {damage_groups={fleshy=2}} -- Load configuration
config = shooter.get_configuration(config)
local arrow_tool_caps = {damage_groups={fleshy=config.arrow_fleshy}}
if minetest.global_exists("SHOOTER_ARROW_TOOL_CAPS") then if minetest.global_exists("SHOOTER_ARROW_TOOL_CAPS") then
arrow_tool_caps = table.copy(SHOOTER_ARROW_TOOL_CAPS) arrow_tool_caps = table.copy(SHOOTER_ARROW_TOOL_CAPS)
end end