fixes :3
All checks were successful
Error Check / luacheck_errcheck (pull_request) Successful in 32s
Unit Tests / busted_unit_test (pull_request) Successful in 45s

This commit is contained in:
Mrrp 2024-12-10 17:03:00 -08:00
parent 224e58577f
commit 19fab12455
5 changed files with 37 additions and 40 deletions

View file

@ -5,5 +5,8 @@
"modname",
"modpath",
"Voxelis"
],
"Lua.diagnostics.globals": [
"vox_colors"
]
}

View file

@ -11,9 +11,3 @@
-- with this program; if not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
core.register_node("vox:grass", {
description = "Grass",
tiles = {"vox_grass.png"},
groups = {cracky = 3}
})
core.register_alias("grass", "vox:grass")

View file

@ -11,8 +11,6 @@
-- with this program; if not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
vox_colors_bg_brightness = 0.8;
vox_colors = {
WHITE = "#FFFFFF",
LIGHTGREY = "#D3D3D3",
@ -46,53 +44,57 @@ vox_colors = {
FLAMINGO = "#FC8EAC",
}
function vox_colors.bg(color) {
return vox_colors_multiplier(color, vox_colors_bg_brightness);
}
vox_colors.bg_brightness = 0.8;
function vox_colors.bg(color)
return vox_colors.multiplier(color, vox_colors.bg_brightness);
end
-- Validate that the provided color string is a valid hex color
function vox_colors.validate(color) {
if (color == nil) {
function vox_colors.validate(color)
if color == nil then
return false;
}
end
-- Hex colors should always be a length of 7 (1 pound, 6 hex)
if (string.len(color) != 7) {
if string.len(color) ~= 7 then
return false;
}
end
-- Ensure first character is a pound
if (string.sub(color, 1, 1) != "#") {
if string.sub(color, 1, 1) ~= "#" then
return false;
}
end
-- Ensure that RR, GG, and BB are valid hex fields
if (string.match(string.sub(color, 2, 3), "[0-9A-Fa-f]") == nil) {
if (string.match(string.sub(color, 2, 3), "[0-9A-Fa-f]") == nil) then
return false;
}
end
return true;
}
end
-- Extract color information from the color and return a { red: Number, green: Number, blue: Number } table
function vox_colors.extract_channels(color) {
return {
red: tonumber(string.sub(color, 2, 3), 16),
green: tonumber(string.sub(color, 4, 5), 16),
blue: tonumber(string.sub(color, 6, 7), 16)
};
}
-- Extract color information from the color and return a [ Number, Number, Number ] array
function vox_colors.extract_channels(color)
local result = {};
function vox_colors.from_channels(red, green, blue) {
result[0] = tonumber(string.sub(color, 2, 3), 16);
result[1] = tonumber(string.sub(color, 4, 5), 16);
result[2] = tonumber(string.sub(color, 6, 7), 16);
return result;
end
function vox_colors.from_channels(red, green, blue)
return "#" .. string.format("%02X", red) .. string.format("%02X", green) .. string.format("%02X", blue);
}
end
-- Multiply the color by a percentage
function vox_colors.multiplier(color, percentage) {
local channels = vox_colors_extract_channels(color);
return vox_colors_from_channels(
function vox_colors.multiplier(color, percentage)
local channels = vox_colors.extract_channels(color);
return vox_colors.from_channels(
math.floor(channels.red * percentage),
math.floor(channels.green * percentage),
math.floor(channels.blue * percentage)
);
}
end

View file

@ -15,7 +15,7 @@
core.register_node("vox_main:grass", {
description = "Grass",
tiles = {"vox_main_grass.png"},
tiles = {"vox_grass.png"},
groups = {cracky = 3}
})
core.register_alias("grass", "vox_main:grass")

View file

@ -11,8 +11,6 @@
-- with this program; if not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
vox_inventory {}
-- Includes
dofile(core.get_modpath(core.get_current_modname()) .. "/survival.lua")
@ -26,7 +24,7 @@ function core.creative_enabled_for(name)
if player then
return player:get_meta():get_string("gamemode") == "creative"
end
core.log(["warning"], "core.creative_enabled_for: player not found: " .. name)
core.log("warning", "core.creative_enabled_for: player not found: " .. name)
return false
end
@ -36,6 +34,6 @@ function core.survival_enabled_for(name)
if player then
return player:get_meta():get_string("gamemode") == "survival"
end
core.log(["warning"], "core.survival_enabled_for: player not found: " .. name)
core.log("warning", "core.survival_enabled_for: player not found: " .. name)
return false
end