Improve config loading and other fixes
This commit is contained in:
parent
cb922eaafd
commit
cf6122ca0c
5 changed files with 36 additions and 17 deletions
|
@ -103,6 +103,7 @@ API Documentation
|
|||
### Methods
|
||||
|
||||
* `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
|
||||
* `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`
|
||||
|
|
|
@ -79,7 +79,7 @@ shooter.register_weapon = function(name, def)
|
|||
inventory_image = def.inventory_image,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if type(def.on_use) == "function" then
|
||||
itemstack = def.on_use, pointed_thing)
|
||||
itemstack = def.on_use(itemstack, user, pointed_thing)
|
||||
end
|
||||
local spec = table.copy(def.spec)
|
||||
if shooter.fire_weapon(user, itemstack, spec) then
|
||||
|
@ -115,6 +115,21 @@ shooter.register_weapon = function(name, def)
|
|||
})
|
||||
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)
|
||||
particles = particles or {}
|
||||
if not config.enable_particle_fx == true or particles.amount == 0 then
|
||||
|
|
|
@ -50,17 +50,7 @@ end
|
|||
|
||||
-- Load Configuration
|
||||
|
||||
for name, config in pairs(shooter.config) do
|
||||
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.config = shooter.get_configuration(shooter.config)
|
||||
shooter.default_particles.texture = shooter.config.explosion_texture
|
||||
|
||||
-- Legacy Entity Support
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue