map_formspec cleanup part 1 - Fix some long lines and start using gui API
This commit is contained in:
parent
5af69ccd14
commit
9ce982c7cf
14
formspec.lua
14
formspec.lua
@ -10,9 +10,23 @@ function gui.formspec(args)
|
||||
};
|
||||
end
|
||||
|
||||
for _,element in ipairs(args) do
|
||||
data = data .. element;
|
||||
end
|
||||
|
||||
return data;
|
||||
end
|
||||
|
||||
function gui.animated_image(args)
|
||||
return string.format("animated_image[%f,%f;%f,%f;%s;%s;%d;%d]",
|
||||
args.x, args.y,
|
||||
args.w, args.h,
|
||||
args.id or "",
|
||||
args.animation.texture .. ".png",
|
||||
args.animation.frame_count,
|
||||
args.animation.frame_duration);
|
||||
end
|
||||
|
||||
function gui.bg9(args)
|
||||
return string.format("background9[%f,%f;%f,%f;%s;%s;%s]",
|
||||
args.x or 0, args.y or 0,
|
||||
|
13
init.lua
13
init.lua
@ -52,11 +52,14 @@ local biome_lookup = {};
|
||||
local marker_lookup = {};
|
||||
|
||||
-- Includes
|
||||
cartographer.skin = loadfile(modpath .. "/skin_api.lua") ();
|
||||
cartographer.gui = loadfile(modpath .. "/formspec.lua") ();
|
||||
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
||||
local gui = loadfile(modpath .. "/formspec.lua") ();
|
||||
|
||||
cartographer.skin = skin;
|
||||
|
||||
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
||||
loadfile(modpath .. "/map_api.lua") (chunk, biome_lookup, marker_lookup);
|
||||
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, cartographer.gui, cartographer.skin);
|
||||
loadfile(modpath .. "/map_formspec.lua") (map_data);
|
||||
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin);
|
||||
loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin);
|
||||
loadfile(modpath .. "/commands.lua") ();
|
||||
loadfile(modpath .. "/table.lua") (_cartographer.materials_by_name, _cartographer.materials_by_group, cartographer.gui, cartographer.skin);
|
||||
loadfile(modpath .. "/table.lua") (_cartographer.materials_by_name, _cartographer.materials_by_group, gui, skin);
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- Arguments
|
||||
-- map_data: The cartographer map data table
|
||||
local map_data = ...;
|
||||
local map_data, gui, skin = ...;
|
||||
|
||||
-- Constants
|
||||
local TILE_SIZE = 0.25;
|
||||
@ -28,16 +28,6 @@ local function get_variant(x, z, noise)
|
||||
return math.floor(math.min(noise[x + 1][z + 1] * 3, 3)) + 1;
|
||||
end
|
||||
|
||||
local map_formspec_prefix = [[
|
||||
formspec_version[3]
|
||||
size[%f,%f]
|
||||
real_coordinates[true]
|
||||
style_type[image_button;border=false]
|
||||
]];
|
||||
|
||||
local tile = "image[%f,%f;%f,%f;%s]";
|
||||
local player_marker = "animated_image[%f,%f;%f,%f;;%s;%d;%d]";
|
||||
|
||||
-- Generate formspec markup for an unknown biome tile
|
||||
-- x: The x position of the tile
|
||||
-- y: The y position of the tile
|
||||
@ -94,7 +84,14 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
|
||||
height = height * 0.05;
|
||||
|
||||
if height_mode then
|
||||
str = str .. tile:format(fx, fy - height + TILE_OFFSET, TILE_SIZE, height + 0.01, cartographer.detail_texture(cartographer.skin.cliff_textures, detail) .. ".png");
|
||||
str = str .. gui.image {
|
||||
x = fx,
|
||||
y = fy - height + TILE_OFFSET,
|
||||
w = TILE_SIZE,
|
||||
h = height + 0.01,
|
||||
|
||||
image = cartographer.detail_texture(skin.cliff_textures, detail) .. ".png",
|
||||
};
|
||||
else
|
||||
height = 0;
|
||||
end
|
||||
@ -102,22 +99,39 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
|
||||
mod = "^[colorize:#1f1f34:"..tostring(depth * 10)
|
||||
end
|
||||
|
||||
str = str..tile:format(fx, fy - height, TILE_SIZE, TILE_SIZE, biome .. "." .. tostring(get_variant(i - x, j - y, noise)) .. ".png" .. mod)
|
||||
str = str .. gui.image {
|
||||
x = fx,
|
||||
y = fy - height,
|
||||
w = TILE_SIZE,
|
||||
h = TILE_SIZE,
|
||||
|
||||
image = biome .. "." .. tostring(get_variant(i - x, j - y, noise)) .. ".png" .. mod,
|
||||
};
|
||||
|
||||
if get_marker then
|
||||
local marker = cartographer.get_marker_texture(get_marker(user, i, j), detail);
|
||||
if marker then
|
||||
str = str..tile:format(fx, fy - height, TILE_SIZE, TILE_SIZE, marker .. ".png")
|
||||
str = str .. gui.image {
|
||||
x = fx,
|
||||
y = fy - height,
|
||||
w = TILE_SIZE,
|
||||
h = TILE_SIZE,
|
||||
|
||||
image = marker .. ".png",
|
||||
};
|
||||
end
|
||||
end
|
||||
|
||||
if i == player_x and j == player_y then
|
||||
local player_icon = cartographer.detail_texture(cartographer.skin.player_icons, detail);
|
||||
str = str .. player_marker:format(fx, fy - height,
|
||||
TILE_SIZE, TILE_SIZE,
|
||||
player_icon.texture .. ".png",
|
||||
player_icon.frame_count,
|
||||
player_icon.frame_duration);
|
||||
str = str .. gui.animated_image {
|
||||
x = fx,
|
||||
y = fy - height,
|
||||
w = TILE_SIZE,
|
||||
h = TILE_SIZE,
|
||||
|
||||
animation = player_icon,
|
||||
};
|
||||
end
|
||||
else
|
||||
str = str .. unknown_biome_tile(fx, fy, detail, get_variant(i - x, j - y, noise));
|
||||
@ -143,9 +157,12 @@ end
|
||||
function cartographer.get_map_formspec(x, y, w, h, detail, scale, height_mode)
|
||||
local formspec_width = (w + 1) * TILE_OFFSET + 0.01;
|
||||
local formspec_height = (h + 1) * TILE_OFFSET + 0.01;
|
||||
return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(x - (w * 0.5), y - (h * 0.5), w, h, x, y, detail, scale, height_mode),
|
||||
formspec_width,
|
||||
formspec_height;
|
||||
return gui.formspec {
|
||||
w = formspec_width,
|
||||
h = formspec_height,
|
||||
|
||||
generate_map(x - (w * 0.5), y - (h * 0.5), w, h, x, y, detail, scale, height_mode),
|
||||
}, formspec_width, formspec_height;
|
||||
end
|
||||
|
||||
-- Get the formspec for a given map table
|
||||
@ -159,7 +176,10 @@ end
|
||||
function cartographer.get_map_formspec_map(map, x, y, height_mode)
|
||||
local formspec_width = (map.w + 1) * TILE_OFFSET + 0.01;
|
||||
local formspec_height = (map.h + 1) * TILE_OFFSET + 0.01;
|
||||
return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(map.x, map.z, map.w, map.h, x, y, map.detail, map.scale, height_mode, cartographer.is_filled, cartographer.get_marker, map),
|
||||
formspec_width,
|
||||
formspec_height;
|
||||
return gui.formspec {
|
||||
w = formspec_width,
|
||||
h = formspec_height,
|
||||
|
||||
generate_map(map.x, map.z, map.w, map.h, x, y, map.detail, map.scale, height_mode, cartographer.is_filled, cartographer.get_marker, map),
|
||||
}, formspec_width, formspec_height;
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user