mirror of
https://github.com/pyrollo/display_modpack.git
synced 2024-11-16 07:10:30 +01:00
luacheck, remove old compatibility stuff
This commit is contained in:
parent
72a9d1bb7d
commit
1f31515cdd
10
.github/workflows/luacheck.yml
vendored
Normal file
10
.github/workflows/luacheck.yml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
name: luacheck
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: Roang-zero1/factorio-mod-luacheck@master
|
||||
with:
|
||||
luacheckrc_url: ""
|
25
.luacheckrc
Normal file
25
.luacheckrc
Normal file
|
@ -0,0 +1,25 @@
|
|||
unused_args = false
|
||||
|
||||
ignore = {
|
||||
"431", -- Shadowing an upvalue
|
||||
"432", -- Shadowing an upvalue argument
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
"minetest",
|
||||
"string",
|
||||
"table",
|
||||
"vector",
|
||||
"default"
|
||||
}
|
||||
|
||||
globals = {
|
||||
"boards",
|
||||
"display_api",
|
||||
"font_api",
|
||||
"ontime_clocks",
|
||||
"signs",
|
||||
"signs_api",
|
||||
"signs_road",
|
||||
"steles"
|
||||
}
|
|
@ -49,7 +49,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
|||
end
|
||||
end
|
||||
|
||||
models = {
|
||||
local models = {
|
||||
black_board = {
|
||||
depth = 1/16, width = 1, height = 1,
|
||||
entity_fields = {
|
||||
|
|
|
@ -19,17 +19,17 @@
|
|||
|
||||
-- Deprecation
|
||||
|
||||
function deprecated_group(deprecated_group, replacement_group)
|
||||
local function deprecated_group(old_group, replacement_group)
|
||||
for name, ndef in pairs(minetest.registered_nodes) do
|
||||
if ndef.groups and ndef.groups[deprecated_group] then
|
||||
if ndef.groups and ndef.groups[old_group] then
|
||||
minetest.log("warning", string.format(
|
||||
'Node %s belongs to deprecated "%s" group which should be replaced with new "%s" group.',
|
||||
name, deprecated_group, replacement_group))
|
||||
name, old_group, replacement_group))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function deprecated_global_table(deprecated_global_name, replacement_global_name)
|
||||
local function deprecated_global_table(deprecated_global_name, replacement_global_name)
|
||||
assert(type(deprecated_global_name) == 'string', "deprecated_global_name should be a string.")
|
||||
assert(type(replacement_global_name) == 'string', "replacement_global_name should be a string.")
|
||||
assert(deprecated_global_name ~= '', "deprecated_global_name should not be empty.")
|
||||
|
|
|
@ -65,9 +65,7 @@ local function compute_values(r)
|
|||
for _ = 1, r.x do d, w, h = rx(d), rx(w), rx(h) end
|
||||
for _ = 1, r.y do d, w, h = ry(d), ry(w), ry(h) end
|
||||
|
||||
return {
|
||||
rotation=r, depth=d, width=w, height=h,
|
||||
restricted=(r.x==0 and r.z==0) }
|
||||
return {rotation=r, depth=d, width=w, height=h}
|
||||
end
|
||||
|
||||
for i, r in pairs(facedir_rotations) do
|
||||
|
@ -78,25 +76,6 @@ for i, r in pairs(wallmounted_rotations) do
|
|||
wallmounted_values[i] = compute_values(r)
|
||||
end
|
||||
|
||||
-- Detect rotation restriction
|
||||
local rotation_restricted = nil
|
||||
minetest.register_entity('display_api:dummy_entity', {
|
||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||
visual = "upright_sprite",
|
||||
textures = {} })
|
||||
|
||||
function display_api.is_rotation_restricted()
|
||||
if rotation_restricted == nil then
|
||||
local objref = minetest.add_entity(
|
||||
{x=0, y=0, z=0}, 'display_api:dummy_entity')
|
||||
if objref then
|
||||
rotation_restricted = objref.set_rotation == nil
|
||||
objref:remove()
|
||||
end
|
||||
end
|
||||
return rotation_restricted
|
||||
end
|
||||
|
||||
-- Clip position property to maximum entity position
|
||||
|
||||
local function clip_pos_prop(posprop)
|
||||
|
@ -243,16 +222,6 @@ function display_api.on_place(itemstack, placer, pointed_thing, override_param2)
|
|||
z = pointed_thing.under.z - pointed_thing.above.z,
|
||||
}
|
||||
|
||||
local rotation_restriction = display_api.is_rotation_restricted()
|
||||
|
||||
if rotation_restriction then
|
||||
-- If item is not placed on a wall, use the player's view direction instead
|
||||
if dir.x == 0 and dir.z == 0 then
|
||||
dir = placer:get_look_dir()
|
||||
end
|
||||
dir.y = 0
|
||||
end
|
||||
|
||||
local param2 = 0
|
||||
if ndef then
|
||||
if ndef.paramtype2 == "wallmounted" or
|
||||
|
@ -261,7 +230,7 @@ function display_api.on_place(itemstack, placer, pointed_thing, override_param2)
|
|||
|
||||
elseif ndef.paramtype2 == "facedir" or
|
||||
ndef.paramtype2 == "colorfacedir" then
|
||||
param2 = minetest.dir_to_facedir(dir, not rotation_restriction)
|
||||
param2 = minetest.dir_to_facedir(dir, true)
|
||||
end
|
||||
end
|
||||
return minetest.item_place(itemstack, placer, pointed_thing,
|
||||
|
@ -291,7 +260,7 @@ function display_api.on_rotate(pos, node, user, _, new_param2)
|
|||
return
|
||||
end
|
||||
|
||||
if ov.restricted or not display_api.is_rotation_restricted() then
|
||||
if ov.restricted then
|
||||
minetest.swap_node(pos, node)
|
||||
display_api.update_entities(pos)
|
||||
return true
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-- Deprecation
|
||||
|
||||
function deprecated_global_table(deprecated_global_name, replacement_global_name)
|
||||
local function deprecated_global_table(deprecated_global_name, replacement_global_name)
|
||||
assert(type(deprecated_global_name) == 'string', "deprecated_global_name should be a string.")
|
||||
assert(type(replacement_global_name) == 'string', "replacement_global_name should be a string.")
|
||||
assert(deprecated_global_name ~= '', "deprecated_global_name should not be empty.")
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
-- This is the unicode char fallback map. If a char is not present in
|
||||
-- font, this maps indicates which char to try to use instead next.
|
||||
|
||||
-- luacheck: ignore
|
||||
return {
|
||||
-- Lowercase chars
|
||||
['a'] = 'A', ['b'] = 'B', ['c'] = 'C', ['d'] = 'D',
|
||||
|
|
|
@ -212,7 +212,7 @@ end
|
|||
-- @return Texture string
|
||||
|
||||
function Font:render(text, texturew, textureh, style)
|
||||
local style = style or {}
|
||||
style = style or {}
|
||||
|
||||
-- Split text into lines (and limit to style.lines # of lines)
|
||||
local lines = {}
|
||||
|
@ -243,17 +243,17 @@ function Font:render(text, texturew, textureh, style)
|
|||
|
||||
y = y + (self.margintop or 0)
|
||||
|
||||
for _, line in pairs(lines) do
|
||||
for _, l in pairs(lines) do
|
||||
if style.halign == "left" then
|
||||
x = 0
|
||||
elseif style.halign == "right" then
|
||||
x = texturew - line.width
|
||||
x = texturew - l.width
|
||||
else
|
||||
x = (texturew - line.width) / 2
|
||||
x = (texturew - l.width) / 2
|
||||
end
|
||||
|
||||
while line.text ~= '' do
|
||||
codepoint, line.text = self:get_next_char(line.text)
|
||||
while l.text ~= '' do
|
||||
codepoint, l.text = self:get_next_char(l.text)
|
||||
if codepoint == nil then return '' end -- UTF Error
|
||||
|
||||
-- Add image only if it is visible (at least partly)
|
||||
|
|
|
@ -60,6 +60,7 @@ local function get_default_font()
|
|||
|
||||
-- If failed, chose first font
|
||||
if default_font == nil then
|
||||
-- luacheck: ignore 512
|
||||
for _, font in pairs(font_api.registered_fonts) do
|
||||
default_font = font
|
||||
break
|
||||
|
|
|
@ -89,7 +89,6 @@ end
|
|||
function signs_api.on_place_direction(itemstack, placer, pointed_thing)
|
||||
local name = itemstack:get_name()
|
||||
local ndef = minetest.registered_nodes[name]
|
||||
local restriction = display_api.is_rotation_restricted()
|
||||
|
||||
local bdir = {
|
||||
x = pointed_thing.under.x - pointed_thing.above.x,
|
||||
|
@ -101,24 +100,14 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
|
|||
local ndir, test
|
||||
|
||||
if ndef and ndef.paramtype2 == "facedir" then
|
||||
-- If legacy mode, only accept upright nodes
|
||||
if restriction and bdir.x == 0 and bdir.z == 0 then
|
||||
-- Ceiling or floor pointed (facedir chosen from player dir)
|
||||
ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z})
|
||||
else
|
||||
-- Wall pointed or no rotation restriction
|
||||
ndir = minetest.dir_to_facedir(bdir, not restriction)
|
||||
end
|
||||
-- Wall pointed
|
||||
ndir = minetest.dir_to_facedir(bdir, true)
|
||||
|
||||
test = { [0]=-pdir.x, pdir.z, pdir.x, -pdir.z, -pdir.x, [8]=pdir.x }
|
||||
end
|
||||
|
||||
if ndef and ndef.paramtype2 == "wallmounted" then
|
||||
ndir = minetest.dir_to_wallmounted(bdir)
|
||||
-- If legacy mode, only accept upright nodes
|
||||
if restriction and (ndir == 0 or ndir == 1) then
|
||||
ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z})
|
||||
end
|
||||
|
||||
test = { [0]=-pdir.x, -pdir.x, pdir.z, -pdir.z, -pdir.x, pdir.x}
|
||||
end
|
||||
|
@ -141,7 +130,6 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
|
|||
end
|
||||
|
||||
-- Handles screwdriver rotation
|
||||
-- (see "if" block below for rotation restriction mode).
|
||||
signs_api.on_rotate = function(pos, node, player, mode, new_param2)
|
||||
-- If rotation mode is 1 and sign is directional, swap direction between
|
||||
-- each rotation.
|
||||
|
@ -165,25 +153,6 @@ signs_api.on_rotate = function(pos, node, player, mode, new_param2)
|
|||
return display_api.on_rotate(pos, node, player, mode, new_param2)
|
||||
end
|
||||
|
||||
-- Legacy mode with rotation restriction
|
||||
-- TODO:When MT < 5.0 no more in use, to be removed
|
||||
if display_api.is_rotation_restricted() then
|
||||
signs_api.on_rotate = function(pos, node, player, mode, new_param2)
|
||||
-- If rotation mode is 2 and sign is directional, swap direction.
|
||||
-- Otherwise use display_api's on_rotate function.
|
||||
if mode == 2 then
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if ndef and ndef.signs_other_dir then
|
||||
minetest.swap_node(pos, {name = ndef.signs_other_dir,
|
||||
param1 = node.param1, param2 = node.param2})
|
||||
display_api.update_entities(pos)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return display_api.on_rotate(pos, node, player, mode, new_param2)
|
||||
end
|
||||
end
|
||||
|
||||
function signs_api.register_sign(mod, name, model)
|
||||
-- Default fields
|
||||
local fields = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user