Merge pull request 'main' (#1) from SevenOfAces/Voxelis:main into main
All checks were successful
Error Check / luacheck_errcheck (push) Successful in 38s
Unit Tests / busted_unit_test (push) Successful in 44s

Reviewed-on: #1
This commit is contained in:
SevenOfAces 2024-12-11 01:04:25 +00:00
commit 70e6cd7ab4
6 changed files with 43 additions and 40 deletions

View file

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

View file

@ -1,5 +1,6 @@
{ {
# Tooling file for Nix and NixOS to get a quick start # Tooling file for Nix and NixOS to get a quick start
# Run 'nix develop' to enter the development shell
description = "pending"; description = "pending";
inputs = { inputs = {
@ -15,6 +16,11 @@
buildInputs = [ buildInputs = [
# Run CI/CD actions locally # Run CI/CD actions locally
pkgs.act pkgs.act
# Lua 5.1 development tools
lua51Packages.lua
lua51Packages.luarocks
lua51Packages.busted
lua51Packages.luacheck
]; ];
shellHook = '' shellHook = ''
alias run_workflows='act -W $PWD/.forgejo/workflows -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest --pull=false' alias run_workflows='act -W $PWD/.forgejo/workflows -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest --pull=false'

View file

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

View file

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

View file

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