From c8f1cd828639211a780292b276acf4fd5f1e4abb Mon Sep 17 00:00:00 2001 From: OgelGames Date: Mon, 1 Nov 2021 16:58:44 +1100 Subject: [PATCH] code and comment tidy --- api.lua | 26 ++++++++++++-------------- chatcommands.lua | 4 ++-- effects.lua | 44 ++++++++++++++++++++++---------------------- effects/fly.lua | 4 ++-- formspec.lua | 2 +- functions.lua | 24 ++++++++++++------------ init.lua | 6 +++--- register.lua | 18 +++++++++--------- 8 files changed, 63 insertions(+), 65 deletions(-) diff --git a/api.lua b/api.lua index 774b6c0..c8d5cd7 100644 --- a/api.lua +++ b/api.lua @@ -89,9 +89,9 @@ function beacon.register_color(name, colorstring, coloring_item) return end - beacon.colors[id] = { desc = name, color = colorstring } + beacon.colors[id] = {desc = name, color = colorstring} - -- beam + -- Beam minetest.register_node("beacon:"..id.."beam", { description = name.." Beacon Beam", tiles = {"beacon_beam.png^[multiply:"..colorstring}, @@ -106,12 +106,12 @@ function beacon.register_color(name, colorstring, coloring_item) walkable = false, diggable = false, climbable = beacon.config.beam_climbable, - selection_box = { type = "fixed", fixed = {0.125, 0.5, 0.125, -0.125, -0.5, -0.125} }, + selection_box = {type = "fixed", fixed = {0.125, 0.5, 0.125, -0.125, -0.5, -0.125}}, on_place = beacon.on_place, - on_rotate = false, -- no rotation with screwdriver + on_rotate = false, -- No rotation with screwdriver }) - -- beam base + -- Beam base minetest.register_node("beacon:"..id.."base", { description = name.." Beacon Beam Base", tiles = {"beacon_beambase.png^[multiply:"..colorstring}, @@ -126,12 +126,12 @@ function beacon.register_color(name, colorstring, coloring_item) walkable = false, diggable = false, climbable = beacon.config.beam_climbable, - selection_box = { type = "fixed", fixed = {0.125, 0.5, 0.125, -0.125, -0.5, -0.125} }, + selection_box = {type = "fixed", fixed = {0.125, 0.5, 0.125, -0.125, -0.5, -0.125}}, on_place = beacon.on_place, - on_rotate = false, -- no rotation with screwdriver + on_rotate = false, -- No rotation with screwdriver }) - -- beacon node + -- Beacon node minetest.register_node("beacon:"..id, { description = name.." Beacon", tiles = {"(beacon_baseglow.png^[multiply:"..colorstring..")^beacon_base.png"}, @@ -188,7 +188,7 @@ function beacon.register_color(name, colorstring, coloring_item) end, after_dig_node = function(pos, oldnode, oldmetadata, digger) if oldmetadata.inventory and oldmetadata.inventory.beacon_upgrades then - for _,item in ipairs(oldmetadata.inventory.beacon_upgrades) do + for _,item in pairs(oldmetadata.inventory.beacon_upgrades) do local stack = ItemStack(item) if not stack:is_empty() then minetest.add_item(pos, stack) @@ -198,9 +198,7 @@ function beacon.register_color(name, colorstring, coloring_item) end, on_movenode = function(from_pos, to_pos) beacon.check_beacon(to_pos) - minetest.after(1, function() - beacon.mark_inactive(from_pos) - end) + minetest.after(1, beacon.mark_inactive, from_pos) end, digiline = { receptor = {}, @@ -210,12 +208,12 @@ function beacon.register_color(name, colorstring, coloring_item) }, }) - -- coloring recipe + -- Coloring recipe if type(coloring_item) == "string" and coloring_item ~= "" and minetest.registered_items[coloring_item] then minetest.register_craft({ type = "shapeless", output = "beacon:"..id, - recipe = { "group:beacon", coloring_item }, + recipe = {"group:beacon", coloring_item}, }) end end diff --git a/chatcommands.lua b/chatcommands.lua index 7b0adc8..f5d1a1e 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -6,7 +6,7 @@ minetest.register_chatcommand("beacon_effects", { param = param:trim() local name = (param ~= "" and param or caller) if not minetest.get_player_by_name(name) or not beacon.players[name] then - return false, "Player " .. name .. " does not exist or is not online." + return false, "Player "..name.." does not exist or is not online." end local output = name == caller and {"Your active effects:"} or {name.."'s active effects:"} for _,id in ipairs(beacon.sorted_effect_ids) do @@ -25,7 +25,7 @@ minetest.register_chatcommand("beacon_nearby", { param = param:trim() local name = (param ~= "" and param or caller) if not minetest.get_player_by_name(name) or not beacon.players[name] then - return false, "Player " .. name .. " does not exist or is not online." + return false, "Player "..name.." does not exist or is not online." end local output = name == caller and {"Beacons near you:"} or {"Beacons near "..name..":"} for spos,info in pairs(beacon.players[name].beacons) do diff --git a/effects.lua b/effects.lua index 1c672f6..74db1c8 100644 --- a/effects.lua +++ b/effects.lua @@ -5,19 +5,19 @@ local forget_time = beacon.config.cache_time local function get_beacon_info(pos) local meta = minetest.get_meta(pos) if meta:get_string("active") ~= "true" then - return -- not active + return -- Not active end local range = meta:get_int("range") if range < 1 then - return -- zero range + return -- Zero range end local effect = meta:get_string("effect") if not beacon.effects[effect] then - return -- no effect + return -- No effect end return { effect = effect, - range = range + 0.5, -- 0.5 to reach node edge + range = range + 0.5, -- 0.5 to reach node edge owner = meta:get_string("owner"), pos = pos, timer = 0, @@ -25,17 +25,17 @@ local function get_beacon_info(pos) end function beacon.mark_active(pos) - local spos = pos.x..","..pos.y..",".. pos.z + local spos = pos.x..","..pos.y..","..pos.z active_beacons[spos] = get_beacon_info(pos) end function beacon.mark_inactive(pos) - local spos = pos.x..","..pos.y..",".. pos.z + local spos = pos.x..","..pos.y..","..pos.z active_beacons[spos] = nil end function beacon.check_beacon(pos) - local spos = pos.x..","..pos.y..",".. pos.z + local spos = pos.x..","..pos.y..","..pos.z local info = get_beacon_info(pos) if info then active_beacons[spos] = info @@ -55,12 +55,12 @@ local function within_range(a, b, range) end local function update_beacons(players) - -- get player positions + -- Get player positions local player_positions = {} for _,player in pairs(players) do player_positions[player:get_player_name()] = player:get_pos() end - -- clear old beacons + -- Clear old beacons for name in pairs(player_positions) do if not beacon.players[name] then beacon.players[name] = {beacons = {}, effects = {}} @@ -68,19 +68,19 @@ local function update_beacons(players) beacon.players[name].beacons = {} end end - -- check active beacons + -- Check active beacons for spos,info in pairs(active_beacons) do local loaded = minetest.get_node_or_nil(info.pos) local in_range = false if info.timer >= 5 and loaded then - -- loaded but not updated by node timer, check it + -- Loaded but not updated by node timer, check it info = get_beacon_info(info.pos) active_beacons[spos] = info else info.timer = info.timer + 1 end if info then - -- add to player beacons + -- Add to player beacons for name,player_pos in pairs(player_positions) do if within_range(info.pos, player_pos, info.range) then beacon.players[name].beacons[spos] = { @@ -94,7 +94,7 @@ local function update_beacons(players) if not loaded and in_range then info.timer = 0 elseif info.timer > forget_time then - -- unloaded and out of range too long, remove it + -- Unloaded and out of range too long, remove it active_beacons[spos] = nil end end @@ -103,7 +103,7 @@ end local function get_useable_effects(name, pos) local effects = {} - -- check each of the nearby beacons + -- Check each of the nearby beacons for _,info in pairs(beacon.players[name].beacons) do if not effects[info.effect] then if info.owner == "" or beacon.can_effect(pos, info.owner) then @@ -111,7 +111,7 @@ local function get_useable_effects(name, pos) end end end - -- clear any overridden effects + -- Clear any overridden effects for effect in pairs(effects) do if beacon.effects[effect].overrides then for _,override in pairs(beacon.effects[effect].overrides) do @@ -136,32 +136,32 @@ end local timer = 0 minetest.register_globalstep(function(dtime) - -- update the timer + -- Update the timer timer = timer + dtime if timer < 1 then return end timer = 0 - -- update effects for all players + -- Update effects for all players local players = minetest.get_connected_players() update_beacons(players) for _,player in pairs(players) do local name = player:get_player_name() local useable = get_useable_effects(name, player:get_pos()) local active = beacon.players[name].effects - -- check the player's effects + -- Check the player's effects for id in pairs(get_all_effect_ids(active, useable)) do - -- remove effect + -- Remove effect if active[id] and not useable[id] then active[id] = nil if beacon.effects[id].on_remove then beacon.effects[id].on_remove(player, name) end - -- add effect + -- Add effect elseif useable[id] and not active[id] then active[id] = true if beacon.effects[id].on_apply then beacon.effects[id].on_apply(player, name) end - -- update effect + -- Update effect else if beacon.effects[id].on_step then beacon.effects[id].on_step(player, name) @@ -180,7 +180,7 @@ minetest.register_on_leaveplayer(function(player) local name = player:get_player_name() if not beacon.players[name] then return end for id in pairs(beacon.players[name].effects) do - -- remove all effects before leaving + -- Remove all effects before leaving if beacon.effects[id].on_remove then beacon.effects[id].on_remove(player, name) end diff --git a/effects/fly.lua b/effects/fly.lua index 4edcab0..4102f68 100644 --- a/effects/fly.lua +++ b/effects/fly.lua @@ -7,7 +7,7 @@ beacon.register_effect("fly", { info = "Temporarily grants the \"fly\" privilage", on_apply = function(player, name) local privs = minetest.get_player_privs(name) - if privs.privs then return end -- don't effect admins + if privs.privs then return end -- Don't effect admins if beacon.has_player_monoids then player_monoids.fly:add_change(player, true, "beacon_fly") @@ -18,7 +18,7 @@ beacon.register_effect("fly", { end, on_remove = function(player, name) local privs = minetest.get_player_privs(name) - if privs.privs then return end -- don't effect admins + if privs.privs then return end -- Don't effect admins if beacon.has_player_monoids then player_monoids.fly:del_change(player, "beacon_fly") diff --git a/formspec.lua b/formspec.lua index f6fe21d..8447746 100644 --- a/formspec.lua +++ b/formspec.lua @@ -4,7 +4,7 @@ local base_formspec = "" local function get_base_formspec() if base_formspec == "" then base_formspec = - "size[8,8]" .. + "size[8,8]".. "label[0,0;Beacon Effect]".. "label[4,0;Upgrades]".. "list[context;beacon_upgrades;4,0.5;4,1;]".. diff --git a/functions.lua b/functions.lua index 14b9e3e..33115f7 100644 --- a/functions.lua +++ b/functions.lua @@ -1,10 +1,10 @@ function beacon.on_place(itemstack, placer, pointed_thing) - -- check for correct pointed_thing + -- Check for correct pointed_thing if not pointed_thing or not pointed_thing.above or not pointed_thing.under or pointed_thing.type ~= "node" then return itemstack, false end - -- calculate param2 direction from pointed_thing + -- Calculate param2 direction from pointed_thing local param2 = 0 local pointed_dir = vector.subtract(pointed_thing.above, pointed_thing.under) if pointed_dir.x ~= 0 then @@ -14,7 +14,7 @@ function beacon.on_place(itemstack, placer, pointed_thing) elseif pointed_dir.z ~= 0 then param2 = pointed_dir.z > 0 and 4 or 8 end - -- place beacon + -- Place beacon return minetest.item_place(itemstack, placer, pointed_thing, param2) end @@ -23,32 +23,32 @@ function beacon.place_beam(pos, player_name, dir) local offset = beacon.dir_to_vector[dir] local param2 = beacon.dir_to_param2[dir] local can_break_nodes = beacon.config.beam_break_nodes - -- place base + -- Place base pos = vector.add(pos, offset) - minetest.add_node(pos, { name = node_name.."base", param2 = param2 }) - -- place beam + minetest.add_node(pos, {name = node_name.."base", param2 = param2}) + -- Place beam for _=1, beacon.config.beam_length - 1 do pos = vector.add(pos, offset) if minetest.is_protected(pos, player_name) then return end if not can_break_nodes then if not beacon.is_airlike_node(pos) then return end end - minetest.add_node(pos, { name = node_name.."beam", param2 = param2 }) + minetest.add_node(pos, {name = node_name.."beam", param2 = param2}) end end function beacon.remove_beam(pos) local dir = minetest.get_meta(pos):get_string("beam_dir") if not dir or not beacon.dir_to_vector[dir] then - return -- invalid meta + return -- Invalid meta end local offset = beacon.dir_to_vector[dir] - -- remove beam (no need to remove beam base seperately) + -- Remove beam (no need to remove beam base seperately) for _=1, beacon.config.beam_length do pos = vector.add(pos, offset) local node = beacon.get_node(pos) if minetest.get_item_group(node.name, "beacon_beam") ~= 1 or beacon.param2_to_dir[node.param2] ~= dir then - return -- end of beam + return -- End of beam end minetest.set_node(pos, {name = "air"}) end @@ -90,9 +90,9 @@ end function beacon.update(pos) if not beacon.check_beacon(pos) then - return true -- no particles when not granting any effect + return true -- No particles when not granting any effect end - -- spawn active beacon particles + -- Spawn active beacon particles local dir = minetest.get_meta(pos):get_string("beam_dir") local colordef = beacon.colors[string.gsub(beacon.get_node(pos).name, "beacon:", "")] if dir and beacon.dir_to_vector[dir] and colordef and colordef.color then diff --git a/init.lua b/init.lua index 4a3021f..254b224 100644 --- a/init.lua +++ b/init.lua @@ -89,15 +89,15 @@ dofile(beacon.modpath.."/chatcommands.lua") dofile(beacon.modpath.."/effects/init.lua") minetest.after(0, function() - -- check if upgrade item is registered + -- Check if upgrade item is registered if not minetest.registered_items[beacon.config.upgrade_item] then beacon.config.upgrade_item = "default:diamondblock" end - -- check if default effect is registered + -- Check if default effect is registered if not beacon.effects[beacon.config.default_effect] then beacon.config.default_effect = "none" end - -- sort effect ids + -- Sort effect ids for id in pairs(beacon.effects) do table.insert(beacon.sorted_effect_ids, id) end diff --git a/register.lua b/register.lua index ec4aef6..69819b9 100644 --- a/register.lua +++ b/register.lua @@ -1,5 +1,5 @@ --- default beacon colors +-- Default beacon colors beacon.register_color("White", "#ffffffff", "dye:white") beacon.register_color("Black", "#0f0f0fff", "dye:black") beacon.register_color("Blue", "#0000ffff", "dye:blue") @@ -11,7 +11,7 @@ beacon.register_color("Red", "#ff0000ff", "dye:red") beacon.register_color("Violet", "#8f00ffff", "dye:violet") beacon.register_color("Yellow", "#ffff00ff", "dye:yellow") --- base beacon recipe +-- Base beacon recipe minetest.register_craft({ output = "beacon:white", recipe = { @@ -21,7 +21,7 @@ minetest.register_craft({ } }) --- floating beam cleanup +-- Floating beam cleanup minetest.register_lbm({ label = "Floating beacon beam cleanup", name = "beacon:beam_cleanup", @@ -30,12 +30,12 @@ minetest.register_lbm({ action = function(pos, node) local under_pos = vector.add(pos, beacon.param2_to_under[node.param2]) if beacon.is_airlike_node(under_pos) then - minetest.set_node(pos, { name = "air" }) + minetest.set_node(pos, {name = "air"}) end end, }) --- conversion for beacons from the original mod +-- Conversion for beacons from the original mod minetest.register_lbm({ label = "Old beacon conversion", name = "beacon:old_conversion", @@ -44,13 +44,13 @@ minetest.register_lbm({ action = function(pos, node) local meta = minetest.get_meta(pos) if meta:get_string("effect") ~= "" then - return -- already converted + return -- Already converted end beacon.set_default_meta(pos, "") meta:set_string("beam_dir", "+Y") meta:set_string("active", "true") minetest.get_node_timer(pos):start(3) - -- old beacon effects + -- Old beacon effects if node.name == "beacon:green" then meta:set_string("effect", "fly") meta:set_int("range", 30) @@ -62,10 +62,10 @@ minetest.register_lbm({ end }) --- purple is named violet now +-- Purple is named violet now minetest.register_alias("beacon:purplebeam", "beacon:violetbeam") minetest.register_alias("beacon:purplebase", "beacon:violetbase") minetest.register_alias("beacon:purple", "beacon:violet") --- no empty/unactivated beacon +-- No empty/unactivated beacon minetest.register_alias("beacon:empty", "beacon:white")