Add .luacheckrc and cleanup some warnings

master
Olivier Dragon 2022-03-17 20:51:23 -04:00
parent 56ec0692c6
commit a1a4949751
5 changed files with 69 additions and 104 deletions

4
.gitattributes vendored
View File

@ -1,7 +1,9 @@
.gitattributes text
.gitignore text
*.pl text
mod.conf text
.luacheckrc text
*.lua text
*.tr text
*.md text

60
.luacheckrc Normal file
View File

@ -0,0 +1,60 @@
unused_args = false
allow_defined_top = true
globals = {
"maple",
}
read_globals = {
"DIR_DELIM", "INIT",
"minetest", "core",
"dump", "dump2",
"Raycast",
"Settings",
"PseudoRandom",
"PerlinNoise",
"VoxelManip",
"SecureRandom",
"VoxelArea",
"PerlinNoiseMap",
"PcgRandom",
"ItemStack",
"AreaStore",
"vector",
"default",
"stairs",
"stairsplus",
"bonemeal",
"doors",
"drawers",
"pkarcs",
table = {
fields = {
"copy",
"indexof",
"insert_all",
"key_value_swap",
"shuffle",
}
},
string = {
fields = {
"split",
"trim",
}
},
math = {
fields = {
"hypot",
"sign",
"factorial"
}
},
}

View File

@ -1,5 +1,3 @@
local S = maple.get_translator;
minetest.register_decoration({
deco_type = "schematic",
place_on = {"default:dirt_with_grass"},

View File

@ -1,12 +1,10 @@
local S = maple.get_translator;
local random = math.random
-- I don't remember if snow function is needed.
local function is_snow_nearby(pos)
return minetest.find_node_near(pos, 1,
{"default:snow", "default:snowblock", "default:dirt_with_snow"})
end
-- local function is_snow_nearby(pos)
-- return minetest.find_node_near(pos, 1,
-- {"default:snow", "default:snowblock", "default:dirt_with_snow"})
-- end
-- Sapling ABM
@ -14,11 +12,10 @@ end
function maple.grow_sapling(pos)
if not default.can_grow(pos) then
-- Can't grow yet, try later.
minetest.get_node_timer(pos):start(math.random(240, 600))
minetest.get_node_timer(pos):start(random(240, 600))
return
end
local mg_name = minetest.get_mapgen_setting("mg_name")
local node = minetest.get_node(pos)
if node.name == "maple:maple_sapling" then
@ -33,7 +30,7 @@ minetest.register_lbm({
name = "maple:convert_saplings_to_node_timer",
nodenames = {"maple:maple_sapling"},
action = function(pos)
minetest.get_node_timer(pos):start(math.random(1200, 2400))
minetest.get_node_timer(pos):start(random(1200, 2400))
end
})

View File

@ -1,92 +0,0 @@
#!/usr/bin/perl -w
use strict;
use integer;
use File::Basename;
use File::Find;
use File::Spec;
use Cwd;
my %trstrings;
{
my $dir = getcwd() or die "Don't know which directory to run from: $!\n";
chdir $dir;
find(\&translations, $dir);
my @strings = keys %trstrings;
my $size = @strings;
if ($size > 0)
{
my $modname = &get_current_modname($dir);
my $englishfile = File::Spec->catfile($dir, "locale", "$modname.en.tr");
open my $trtemplate, ">$englishfile" or die "Cannot write to file $englishfile: $!\n";
print $trtemplate "# textdomain:$modname\n";
foreach my $string (sort @strings)
{
print $trtemplate "$string=$string\n";
}
close $trtemplate;
}
}
sub translations()
{
if (-T $_)
{
if (m/\.lua/)
{
open my $codefile, "<$_";
while (<$codefile>)
{
if (m/S\("(.*?)"\)/)
{
if (defined $1)
{
$trstrings{$1} = 1;
}
}
}
close $codefile;
}
}
}
sub get_current_modname($)
{
my ($dir) = @_;
my $defaultmodname = "modname";
my $modname = $defaultmodname;
my $modconf = File::Spec->catfile($dir, "mod.conf");
if (-T $modconf)
{
open my $modconffile, "<$modconf";
while (<$modconffile>)
{
if (m/name\s*=\s*(\S*)/)
{
if ($1)
{
$modname = $1;
}
}
}
close $modconffile;
}
if ($modname eq $defaultmodname)
{
$modname = basename($dir);
}
return $modname;
}