Rendi anteprima e ritratto proprietà delle skin impostate automaticamente (controllando nomi file al lancio)

master
Zughy 2022-04-23 16:14:15 +02:00
parent 902bfa242c
commit 0d7f79a505
3 changed files with 25 additions and 16 deletions

View File

@ -20,7 +20,6 @@ skinID:
hint: (optional, default "(locked)")
model: (optional, default none)
tier: (optional, default 1)
splash_art: (optional, default none)
author: (optional, default "???")
```

View File

@ -40,15 +40,29 @@ local function load_skins()
for ID, skin in pairs(skins) do
-- il decodificatore aggiunge_N ai doppioni, per diversificarli e salvarli entrambi. Tolgo quindi _ecc
-- il decodificatore aggiunge _N ai doppioni, per diversificarli e salvarli entrambi. Tolgo quindi _ecc
-- da eventuali cifre iniziali per vedere se già esiste (se è stringa, è errore a prescindere)
if type(ID) == "string" then
assert(loaded_skins[tonumber(ID:match("(%d+)_"))] == nil, "[SKINS COLLECTIBLE] There are two or more skins with the same ID!")
error("[SKINS COLLECTIBLE] Invalid skin ID '" .. ID .. "': numbers only!")
end
assert(skin.name, "[SKINS COLLECTIBLE] Skin #" .. ID .. " has no name!")
assert(skin.description, "[SKINS COLLECTIBLE] Skin #" .. ID .. " has no description!")
assert(skin.texture, "[SKINS COLLECTIBLE] Skin #" .. ID .. " has no texture!")
assert(skin.name, "[SKINS COLLECTIBLE] Skin #" .. ID .. " has no name!")
assert(skin.description, "[SKINS COLLECTIBLE] Skin #" .. ID .. " has no description!")
assert(skin.texture, "[SKINS COLLECTIBLE] Skin #" .. ID .. " has no texture!")
local sk_preview = ""
local sk_splash = "blank.png"
local sk_txtr_noprefix = string.match(skin.texture, "(.*)%.png")
-- calcolo anteprima e splash, dato che devono corrispondere a un nome
-- specifico (e se non trova l'anteprima, interrompo)
for _, txtr_name in pairs(minetest.get_dir_list(txtr_dir)) do
if txtr_name == sk_txtr_noprefix .. "_preview.png" then sk_preview = txtr_name
elseif txtr_name == sk_txtr_noprefix .. "_splash.png" then sk_splash = txtr_name
end
end
assert(sk_preview ~= "", "[SKINS COLLECTIBLE] Skin #" .. ID .. " has no preview!")
loaded_skins[ID] = {
name = skin.name,
@ -56,8 +70,9 @@ local function load_skins()
hint = skin.hint or "(locked)",
model = skin.model,
texture = skin.texture,
preview = sk_preview,
splash_art = sk_splash,
tier = skin.tier or 1,
img = skin.splash_art or "blank.png",
author = skin.author or "???",
}
end
@ -202,12 +217,6 @@ end
-----------------GETTERS----------------------
----------------------------------------------
function skins_collectible.get_preview(skin_ID)
return string.match(loaded_skins[skin_ID].texture, "(.*)%.png") .. "_preview.png"
end
function skins_collectible.get_skin(skin_ID)
return loaded_skins[skin_ID]
end

View File

@ -33,7 +33,7 @@ function skins_collectible.get_formspec(p_name, page, skin_ID)
else
selected_skin = skins_collectible.get_skin(skin_ID)
skin_bg = "skinsc_gui_bg_tier" .. selected_skin.tier .. ".png"
skin_preview = skins_collectible.get_preview(skin_ID)
skin_preview = selected_skin.preview
skin_stars = "skinsc_gui_stars" .. selected_skin.tier .. ".png"
minetest.get_player_by_name(p_name):get_meta():set_int("skins_collectible:selected_skin_ID", skin_ID) -- metadato per "Wear" se è sbloccata
@ -42,7 +42,7 @@ function skins_collectible.get_formspec(p_name, page, skin_ID)
local formspec = {
-- immagini
"image[0,0;16.15,9.24;" .. skin_bg .. "]",
"image[0,0;16.15,9.24;" .. selected_skin.img .. "]",
"image[0,0;16.15,9.24;" .. selected_skin.splash_art .. "]",
"image[0,0;16.15,9.24;skinsc_gui_overlay.png]",
-- skin selezionata
"image[1.95,0.85;1.05,0.15;" .. skin_stars .. "]",
@ -78,12 +78,13 @@ function skins_collectible.get_formspec(p_name, page, skin_ID)
local indent_y = 1.8
local slot_size = size_x .. "," .. size_y .. ";"
local slot_pos = indent_x + pos_x .. "," .. indent_y + pos_y .. ";"
local skin = skins_collectible.get_skin(skin_ID)
if skins_collectible.is_skin_unlocked(p_name, skin_ID) then
table.insert(formspec, skin_ID, "image_button[" .. slot_pos .. slot_size .. skins_collectible.get_preview(skin_ID) .. ";" .. skin_ID .. ";]")
table.insert(formspec, skin_ID, "image_button[" .. slot_pos .. slot_size .. skin.preview .. ";" .. skin_ID .. ";]")
else
table.insert(formspec, skin_ID, "image_button[" .. slot_pos .. slot_size .. "skinsc_gui_button.png;LOCKED;]")
table.insert(formspec, skin_ID +1, "tooltip[" .. slot_pos .. slot_size .. FS(skins_collectible.get_skin(skin_ID).hint) .. " ;#dff6f5;#5a5353]")
table.insert(formspec, skin_ID +1, "tooltip[" .. slot_pos .. slot_size .. FS(skin.hint) .. " ;#dff6f5;#5a5353]")
end
end
end