main #1

Merged
SevenOfAces merged 2 commits from mad-star-studio/Voxelis:main into main 2024-12-11 01:27:45 +00:00
6 changed files with 43 additions and 40 deletions
Showing only changes of commit 70e6cd7ab4 - Show all commits

View file

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

View file

@ -1,5 +1,6 @@
{
# Tooling file for Nix and NixOS to get a quick start
# Run 'nix develop' to enter the development shell
description = "pending";
inputs = {
@ -15,6 +16,11 @@
buildInputs = [
# Run CI/CD actions locally
pkgs.act
# Lua 5.1 development tools
lua51Packages.lua
lua51Packages.luarocks
lua51Packages.busted
lua51Packages.luacheck
];
shellHook = ''
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/>.
---------------------------------------------------------------------------
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