Skip to content

Instantly share code, notes, and snippets.

@Jordach

Jordach/.lua

Created Feb 22, 2017
Embed
What would you like to do?
-- how to add your own textures to the wardrobe;
--[[
Make sure your textures are in greyscale, eg, from black to white in 0-255 steps
The engine prefers this colour as it is easier to look right once a player has
set their colour preferences for a specific piece of clothing.
The only non-colourable texture is the mouth, as that either lightly shades the mouth area or
Textures that can be added to the wardrobe;
wardrobe_under_shirt_[number].png
wardrobe_shirt_[number].png
wardrobe_socks_[number].png
wardrobe_shoes_[number].png
wardrobe_leggings_[number].png
wardrobe_trousers_[number].png
wardrobe_hair_[number].png
wardrobe_eyes_white_[number].png
wardrobe_eyes_pupil_[number].png
wardrobe_mouth_[number].png
wardrobe_acc_[number].png
]]--
-- wardrobe vars
wardrobe = {}
wardrobe.texture_path = minetest.get_modpath("wardrobe").."/textures/"
wardrobe.player_materials = {}
wardrobe.formspec_selections = {}
wardrobe.formspec_selections_rgb = {}
--clothing
wardrobe.undershirts = 1
wardrobe.shirts = 1
wardrobe.under_trousers = 1
wardrobe.trousers = 1
wardrobe.socks = 1
wardrobe.shoes = 1
wardrobe.accessories = 1
--biological features
wardrobe.mouth_parts = 1
wardrobe.hair_styles = 1
wardrobe.eyes = 1
wardrobe.pupils = 1
-- load textures (indented to show it's a hybrid of a function and a loop)
--logic will always overcount by ONE, unless the total is exactly ONE,
--however, there will always be a minimum of TWO textures.
-- under shirts
local f
while true do
f = io.open(wardrobe.texture_path.."wardrobe_under_shirt_"..wardrobe.undershirts..".png")
if not f then break end
f:close()
wardrobe.undershirts = wardrobe.undershirts + 1
end
wardrobe.undershirts = wardrobe.undershirts - 1
print ("[Wardrobe]: "..wardrobe.undershirts.." Under Shirts detected")
-- shirts
while true do
f = io.open(wardrobe.texture_path.."wardrobe_shirt_"..wardrobe.shirts..".png")
if not f then break end
f:close()
wardrobe.shirts = wardrobe.shirts + 1
end
wardrobe.shirts = wardrobe.shirts - 1
print ("[Wardrobe]: "..wardrobe.shirts.." Over Shirts detected")
-- trousers / leggings
while true do
f = io.open(wardrobe.texture_path.."wardrobe_leggings_"..wardrobe.under_trousers..".png")
if not f then break end
f:close()
wardrobe.under_trousers = wardrobe.under_trousers + 1
end
wardrobe.under_trousers = wardrobe.under_trousers - 1
print ("[Wardrobe]: "..wardrobe.under_trousers.." Pair(s) of Leggings detected")
-- overalls / "trousers"
while true do
f = io.open(wardrobe.texture_path.."wardrobe_trousers_"..wardrobe.trousers..".png")
if not f then break end
f:close()
wardrobe.trousers = wardrobe.trousers + 1
end
wardrobe.trousers = wardrobe.trousers - 1
print ("[Wardrobe]: "..wardrobe.trousers.." Pair(s) of Trousers detected")
-- socks
while true do
f = io.open(wardrobe.texture_path.."wardrobe_socks_"..wardrobe.socks..".png")
if not f then break end
f:close()
wardrobe.socks = wardrobe.socks + 1
end
wardrobe.socks = wardrobe.socks - 1
print ("[Wardrobe]: "..wardrobe.socks.." Pair(s) of Socks detected")
-- shoes
while true do
f = io.open(wardrobe.texture_path.."wardrobe_shoes_"..wardrobe.shoes..".png")
if not f then break end
f:close()
wardrobe.shoes = wardrobe.shoes + 1
end
wardrobe.shoes = wardrobe.shoes - 1
print ("[Wardrobe]: "..wardrobe.shoes.." Pair(s) of Shoes detected")
-- accessories
while true do
f = io.open(wardrobe.texture_path.."wardrobe_acc_"..wardrobe.accessories..".png")
if not f then break end
f:close()
wardrobe.accessories = wardrobe.accessories + 1
end
wardrobe.accessories = wardrobe.accessories - 1
print ("[Wardrobe]: "..wardrobe.accessories.." Accessories detected")
-- hair
while true do
f = io.open(wardrobe.texture_path.."wardrobe_hair_"..wardrobe.hair_styles..".png")
if not f then break end
f:close()
wardrobe.hair_styles = wardrobe.hair_styles + 1
end
wardrobe.hair_styles = wardrobe.hair_styles - 1
print ("[Wardrobe]: "..wardrobe.hair_styles.." Hair Styles detected")
-- eyes & pupils
while true do
f = io.open(wardrobe.texture_path.."wardrobe_eyes_white_"..wardrobe.eyes..".png")
if not f then break end
f:close()
wardrobe.eyes = wardrobe.eyes + 1
end
wardrobe.eyes = wardrobe.eyes - 1
print ("[Wardrobe]: "..wardrobe.eyes.." Eye Whites detected")
while true do
f = io.open(wardrobe.texture_path.."wardrobe_eyes_pupil_"..wardrobe.pupils..".png")
if not f then break end
f:close()
wardrobe.pupils = wardrobe.pupils + 1
end
wardrobe.pupils = wardrobe.pupils - 1
print ("[Wardrobe]: "..wardrobe.pupils.." Eye Pupils detected")
-- mouth
while true do
f = io.open(wardrobe.texture_path.."wardrobe_mouth_"..wardrobe.mouth_parts..".png")
if not f then break end
f:close()
wardrobe.mouth_parts = wardrobe.mouth_parts + 1
end
wardrobe.mouth_parts = wardrobe.mouth_parts - 1
print ("[Wardrobe]: "..wardrobe.mouth_parts.." Mouth Overlays detected")
-- test dummy
minetest.register_entity("wardrobe:dummy", {
collisionbox = {0,0,0,0,0,0},
visual = "mesh",
mesh = "wardrobe_dummy.x",
textures = {
"ptextures_transparent.png",
"(wardrobe_skin.png^[multiply:#ffffff)",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png"
},
visual_size = {x=1, y=1},
})
function wardrobe.formspec_meta(texture_table, rgb_table )
--[[ texture ID's (21 vars)
eye,
hair,
mouth,
ushirt, ushirt2,
utrou, utrou2,
socks, socks2,
jacket, jacket2,
trous, trous2,
shoes, shoes2,
acc1, acc2, acc3, acc4, acc5, acc6,
-- RGB colours (22 vars)
skinrgb,
eyergb,
pupilrgb,
hairrgb,
ushirtrgb, ushirt2rgb,
utrourgb, utrou2rgb,
socksrgb, socks2rgb,
jacketrgb, jacket2rgb,
trousrgb, trous2rgb,
shoesrgb, shoes2rgb,
acc1rgb, acc2rgb, acc3rgb, acc4rgb, acc5rgb, acc6rgb
)
]]-- notice - old varnames
local formspec =
"size[15,11]"..
-- Skin Tone setting
"label[0,0.15;Skin Tone:]"..
"field[2,0.3;3.22,1;skintone;;"..rgb_table[1].."]".. --//
--
-- Eye White (Schelra Colouring and Eye Styling)
"label[0,1.0;Eye Type and]"..
"label[0,1.38;Eye Colour:]"..
"button[1.7,1;1,1;eyedown;<-]".. --\\
"field[2.75,1.32;1.75,1;ewhite;;"..rgb_table[2].."]".. --//
"button[3.97,1;1,1;eyeup;->]".. --\\
--
-- Pupil Colours
-- Eye White (Schelra Colouring and Eye Styling)
"label[0,2.0;Pupil Style &]"..
"label[0,2.38;Pupil Colour:]"..
"button[1.7,2;1,1;pupdown;<-]".. --\\
"field[2.75,2.32;1.75,1;pcolour;;"..rgb_table[3].."]".. --//
"button[3.97,2;1,1;pupup;->]".. --\\
--
-- Hair styling and dyes, not only just to look good...or bald.
"label[0,3;Hair Style and]"..
"label[0,3.38;Hair Colour:]"..
"button[1.7,3;1,1;hairdown;<-]".. --\\
"field[2.75,3.32;1.75,1;hairdye;;"..rgb_table[4].."]".. --//
"button[3.97,3;1,1;hairup;->]".. --\\
--
-- Mouth Shape, not coloured - but for those who want to eat...or wanting to scream
"label[0, 4.18;Mouth Shape:]"..
"button[1.7,4;1.5,1;mouthdown;<-]".. --\\
"button[3.47,4;1.5,1;mouthup;->]".. --\\
--
-- Under Shirt Layer 1
"label[0, 5;Under Shirt]"..
"label[0, 5.38;Layer 1:]"..
"button[1.7,5;1,1;ushirtdown;<-]".. --\\
"field[2.75,5.32;1.75,1;undshirt;;"..rgb_table[5].."]".. --//
"button[3.97,5;1,1;ushirtup;->]".. --\\
--
-- Under Shirt Layer 2
"label[0, 6;Under Shirt]"..
"label[0, 6.38;Layer 2:]"..
"button[1.7,6;1,1;ushirtdown2;<-]".. --\\
"field[2.75,6.32;1.75,1;undshirt2;;"..rgb_table[6].."]".. --//
"button[3.97,6;1,1;ushirtup2;->]".. --\\
--
-- Leggings Layer 1
"label[0, 7;Leggings]"..
"label[0, 7.38;Layer 1:]"..
"button[1.7,7;1,1;leggdown;<-]".. --\\
"field[2.75,7.32;1.75,1;leggings;;"..rgb_table[7].."]".. --//
"button[3.97,7;1,1;leggup;->]".. --\\
--
-- Leggings Layer 2
"label[0, 8;Leggings]"..
"label[0, 8.38;Layer 2:]"..
"button[1.7,8;1,1;leggdown2;<-]".. --\\
"field[2.75,8.32;1.75,1;leggings2;;"..rgb_table[8].."]".. --//
"button[3.97,8;1,1;leggup2;->]".. --\\
--
-- Socks Layer 1
"label[0, 9;Socks]"..
"label[0, 9.38;Layer 1:]"..
"button[1.7,9;1,1;sockdown;<-]".. --\\
"field[2.75,9.32;1.75,1;socks;;"..rgb_table[9].."]".. --//
"button[3.97,9;1,1;sockup;->]".. --\\
--
-- Socks Layer 1
"label[0, 10;Socks]"..
"label[0, 10.38;Layer 2:]"..
"button[1.7,10;1,1;sockdown2;<-]".. --\\
"field[2.75,10.32;1.75,1;socks2;;"..rgb_table[10].."]".. --//
"button[3.97,10;1,1;sockup2;->]".. --\\
--
-- Shirt Layer 1
"label[5,0;Over Shirt]"..
"label[5,0.38;Layer 1:]"..
"button[6.7,0;1,1;topshirtdown;<-]".. --\\
"field[7.75,0.32;1.75,1;topshirt;;"..rgb_table[11].."]".. --//
"button[8.97,0;1,1;topshirtup;->]".. --\\
--
-- Shirt Layer 2
"label[5,1;Over Shirt]"..
"label[5,1.38;Layer 2:]"..
"button[6.7,1;1,1;topshirtdown2;<-]".. --\\
"field[7.75,1.32;1.75,1;topshirt2;;"..rgb_table[12].."]".. --//
"button[8.97,1;1,1;topshirtup2;->]".. --\\
--
-- Trousers Layer 1
"label[5,2;Trousers]"..
"label[5,2.38;Layer 2:]"..
"button[6.7,2;1,1;troudown;<-]".. --\\
"field[7.75,2.32;1.75,1;trousers;;"..rgb_table[13].."]".. --//
"button[8.97,2;1,1;trouup;->]".. --\\
--
-- Trousers Layer 2
"label[5,3;Trousers]"..
"label[5,3.38;Layer 2:]"..
"button[6.7,3;1,1;troudown2;<-]".. --\\
"field[7.75,3.32;1.75,1;trousers2;;"..rgb_table[14].."]".. --//
"button[8.97,3;1,1;trouup2;->]".. --\\
--
-- Shoes Layer 1
"label[5,4;Shoes]"..
"label[5,4.38;Layer 1:]"..
"button[6.7,4;1,1;shoedown;<-]".. --\\
"field[7.75,4.32;1.75,1;shoes;;"..rgb_table[15].."]".. --//
"button[8.97,4;1,1;shoeup;->]".. --\\
--
-- Shoes Layer 2
"label[5,5;Shoes]"..
"label[5,5.38;Layer 2:]"..
"button[6.7,5;1,1;shoedown2;<-]".. --\\
"field[7.75,5.32;1.75,1;shoes2;;"..rgb_table[16].."]".. --//
"button[8.97,5;1,1;shoeup2;->]".. --\\
--
-- Accessory Layer 1
"label[10,0;Accessory]"..
"label[10,0.38;Layer 1:]"..
"button[11.7,0;1,1;acc1down;<-]".. --\\
"field[12.75,0.32;1.75,1;acc1;;"..rgb_table[17].."]".. --//
"button[13.97,0;1,1;acc1up;->]".. --\\
--
-- Accessory Layer 2
"label[10,1;Accessory]"..
"label[10,1.38;Layer 2:]"..
"button[11.7,1;1,1;acc2down;<-]".. --\\
"field[12.75,1.32;1.75,1;acc2;;"..rgb_table[18].."]".. --//
"button[13.97,1;1,1;acc2up;->]".. --\\
--
-- Accessory Layer 3
"label[10,2;Accessory]"..
"label[10,2.38;Layer 3:]"..
"button[11.7,2;1,1;acc3down;<-]".. --\\
"field[12.75,2.32;1.75,1;acc3;;"..rgb_table[19].."]".. --//
"button[13.97,2;1,1;acc3up;->]".. --\\
--
-- Accessory Layer 4
"label[10,3;Accessory]"..
"label[10,3.38;Layer 4:]"..
"button[11.7,3;1,1;acc4down;<-]".. --\\
"field[12.75,3.32;1.75,1;acc4;;"..rgb_table[20].."]".. --//
"button[13.97,3;1,1;acc4up;->]".. --\\
--
-- Accessory Layer 5
"label[10,4;Accessory]"..
"label[10,4.38;Layer 5:]"..
"button[11.7,4;1,1;acc5down;<-]".. --\\
"field[12.75,4.32;1.75,1;acc5;;"..rgb_table[21].."]".. --//
"button[13.97,4;1,1;acc5up;->]".. --\\
--
-- Accessory Layer 6
"label[10,5;Accessory]"..
"label[10,5.38;Layer 6:]"..
"button[11.7,5;1,1;acc6down;<-]".. --\\
"field[12.75,5.32;1.75,1;acc6;;"..tostring(rgb_table[22]).."]".. --//
"button[13.97,5;1,1;acc6up;->]".. --\\
--
--Apply Texture to Dummy Player;
"button[12.97,10;2,1;preview;Preview]"..
--Apply Texture to Real Player;
"button[10.97,10;2,1;apply;Apply to Me!]"
--Apply Texture to Player;
return formspec
end
minetest.register_node("wardrobe:node", {
description = "Mirror (Customise Player)",
drawtype = "mesh",
mesh = "wardrobe_mirror.b3d",
tiles = {"wardrobe_mirror.png"},
groups = {crumbly=3},
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local pchoices = {}
local pname = placer:get_player_name()
meta:set_string("formspec", wardrobe.formspec_meta(wardrobe.formspec_selections[pname], wardrobe.formspec_selections_rgb[pname]))
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields.quit then return end
local pname = sender:get_player_name()
local meta = minetest.get_meta(pos)
wardrobe.save_text_fields(fields, pname)
meta:set_string("formspec", wardrobe.formspec_meta(wardrobe.formspec_selections[pname], wardrobe.formspec_selections_rgb[pname]))
-- eyes
if (fields.eyedown) then
wardrobe.table_incrementer(1, false, sender, wardrobe.eyes)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.eyeup) then
wardrobe.table_incrementer(1, true, sender, wardrobe.eyes)
wardrobe.update_dummy(pos, fields, sender)
end
-- pupils
if (fields.pupdown) then
wardrobe.table_incrementer(2, false, sender, wardrobe.pupils)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.pupup) then
wardrobe.table_incrementer(2, true, sender, wardrobe.pupils)
wardrobe.update_dummy(pos, fields, sender)
end
-- hair
if (fields.hairdown) then
wardrobe.table_incrementer(3, false, sender, wardrobe.hair_styles)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.hairup) then
wardrobe.table_incrementer(3, true, sender, wardrobe.hair_styles)
wardrobe.update_dummy(pos, fields, sender)
end
-- mouth
-- TABLE POS 4
-- undershirt L1 + L2
if (fields.ushirtdown) then
wardrobe.table_incrementer(5, false, sender, wardrobe.undershirts)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.ushirtup) then
wardrobe.table_incrementer(5, true, sender, wardrobe.undershirts)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.ushirtdown2) then
wardrobe.table_incrementer(6, true, sender, wardrobe.undershirts)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.ushirtup2) then
wardrobe.table_incrementer(6, true, sender, wardrobe.undershirts)
wardrobe.update_dummy(pos, fields, sender)
end
-- Leggings L1 + L2
if (fields.leggdown) then
wardrobe.table_incrementer(7, false, sender, wardrobe.under_trousers)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.leggup) then
wardrobe.table_incrementer(7, true, sender, wardrobe.under_trousers)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.leggdown2) then
wardrobe.table_incrementer(8, false, sender, wardrobe.under_trousers)
wardrobe.update_dummy(pos, fields, sender)
end
if (fields.leggup2) then
wardrobe.table_incrementer(8, true, sender, wardrobe.under_trousers)
wardrobe.update_dummy(pos, fields, sender)
end
-- Socks L1 + L2
-- Apply current data to entity.
if (fields.preview) then
wardrobe.update_dummy(pos, fields, sender)
end
end,
})
function wardrobe.update_player(player)
print("meow")
end
function wardrobe.update_dummy(pos, fields, player)
local pname = player:get_player_name()
local entity = minetest.get_objects_inside_radius({x=pos.x, y=pos.y+0.5, z=pos.z}, 0.1)
if entity[1] == nil then
minetest.add_entity({x=pos.x, y=pos.y+0.5, z=pos.z}, "wardrobe:dummy")
entity = minetest.get_objects_inside_radius({x=pos.x, y=pos.y+0.5, z=pos.z}, 0.1)
entity[1]:set_animation({x=0, y=1339}, 30, 0)
end
entity = minetest.get_objects_inside_radius({x=pos.x, y=pos.y+0.5, z=pos.z}, 0.1)
if entity[1] then
entity[1]:set_animation({x=0, y=1339}, 30, 0)
entity[1]:set_properties({
textures = {
"ptextures_transparent.png",
"(wardrobe_skin.png^[multiply:#"..fields.skintone..")^"..
"(wardrobe_eyes_white_"..wardrobe.formspec_selections[pname][1]..".png^[multiply:#"..fields.ewhite..")^"..
"(wardrobe_eyes_pupil_"..wardrobe.formspec_selections[pname][2]..".png^[multiply:#"..fields.pcolour..")^"..
"(wardrobe_hair_"..wardrobe.formspec_selections[pname][3]..".png^[multiply:#"..fields.hairdye..")^"..
"(wardrobe_under_shirt_"..wardrobe.formspec_selections[pname][5]..".png^[multiply:#"..fields.undshirt..")^"..
"(wardrobe_under_shirt_"..wardrobe.formspec_selections[pname][6]..".png^[multiply:#"..fields.undshirt2..")^"..
"(wardrobe_socks_2.png^[multiply:#"..fields.socks..")^"..
"(wardrobe_leggings_2.png^[multiply:#"..fields.leggings..")^"..
"(wardrobe_shoes_2.png^[multiply:#"..fields.shoes..")^"..
"(wardrobe_acc_2.png^[multiply:#"..fields.topshirt..")",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png"
}
})
end
end
function wardrobe.table_incrementer(arraynum, operator, player, maxval)
if operator then
if wardrobe.formspec_selections[player:get_player_name()][arraynum] == maxval then
--nothing
else
wardrobe.formspec_selections[player:get_player_name()][arraynum] = wardrobe.formspec_selections[player:get_player_name()][arraynum] + 1
end
else
if wardrobe.formspec_selections[player:get_player_name()][arraynum] == 1 then
-- nothing
else
wardrobe.formspec_selections[player:get_player_name()][arraynum] = wardrobe.formspec_selections[player:get_player_name()][arraynum] - 1
end
end
end
function wardrobe.number_or_nil(number)
return number or 1
end
function wardrobe.save_text_fields(fields, pname)
if wardrobe.is_hex(fields.skintone) then
wardrobe.formspec_selections_rgb[pname][1] = fields.skintone
else
wardrobe.formspec_selections_rgb[pname][1] = "ffffff"
end
if wardrobe.is_hex(fields.ewhite) then
wardrobe.formspec_selections_rgb[pname][2] = fields.ewhite
else
wardrobe.formspec_selections_rgb[pname][2] = "ffffff"
end
if wardrobe.is_hex(fields.pcolour) then
wardrobe.formspec_selections_rgb[pname][3] = fields.pcolour
else
wardrobe.formspec_selections_rgb[pname][3] = "ffffff"
end
if wardrobe.is_hex(fields.hairdye) then
wardrobe.formspec_selections_rgb[pname][4] = fields.hairdye
else
wardrobe.formspec_selections_rgb[pname][4] = "ffffff"
end
if wardrobe.is_hex(fields.undshirt) then
wardrobe.formspec_selections_rgb[pname][5] = fields.undshirt
else
wardrobe.formspec_selections_rgb[pname][5] = "ffffff"
end
if wardrobe.is_hex(fields.undshirt2) then
wardrobe.formspec_selections_rgb[pname][6] = fields.undshirt2
else
wardrobe.formspec_selections_rgb[pname][6] = "ffffff"
end
if wardrobe.is_hex(fields.leggings) then
wardrobe.formspec_selections_rgb[pname][7] = fields.leggings
else
wardrobe.formspec_selections_rgb[pname][7] = "ffffff"
end
if wardrobe.is_hex(fields.leggings2) then
wardrobe.formspec_selections_rgb[pname][8] = fields.leggings2
else
wardrobe.formspec_selections_rgb[pname][8] = "ffffff"
end
if wardrobe.is_hex(fields.socks) then
wardrobe.formspec_selections_rgb[pname][9] = fields.socks
else
wardrobe.formspec_selections_rgb[pname][9] = "ffffff"
end
if wardrobe.is_hex(fields.socks2) then
wardrobe.formspec_selections_rgb[pname][10] = fields.socks2
else
wardrobe.formspec_selections_rgb[pname][10] = "ffffff"
end
if wardrobe.is_hex(fields.topshirt) then
wardrobe.formspec_selections_rgb[pname][11] = fields.topshirt
else
wardrobe.formspec_selections_rgb[pname][11] = "ffffff"
end
if wardrobe.is_hex(fields.topshirt2) then
wardrobe.formspec_selections_rgb[pname][12] = fields.topshirt2
else
wardrobe.formspec_selections_rgb[pname][12] = "ffffff"
end
if wardrobe.is_hex(fields.trousers) then
wardrobe.formspec_selections_rgb[pname][13] = fields.trousers
else
wardrobe.formspec_selections_rgb[pname][13] = "ffffff"
end
if wardrobe.is_hex(fields.trousers2) then
wardrobe.formspec_selections_rgb[pname][14] = fields.trousers2
else
wardrobe.formspec_selections_rgb[pname][14] = "ffffff"
end
if wardrobe.is_hex(fields.shoes) then
wardrobe.formspec_selections_rgb[pname][15] = fields.shoes
else
wardrobe.formspec_selections_rgb[pname][15] = "ffffff"
end
if wardrobe.is_hex(fields.shoes2) then
wardrobe.formspec_selections_rgb[pname][16] = fields.shoes2
else
wardrobe.formspec_selections_rgb[pname][16] = "ffffff"
end
if wardrobe.is_hex(fields.acc1) then
wardrobe.formspec_selections_rgb[pname][17] = fields.acc1
else
wardrobe.formspec_selections_rgb[pname][17] = "ffffff"
end
if wardrobe.is_hex(fields.acc2) then
wardrobe.formspec_selections_rgb[pname][18] = fields.acc2
else
wardrobe.formspec_selections_rgb[pname][18] = "ffffff"
end
if wardrobe.is_hex(fields.acc3) then
wardrobe.formspec_selections_rgb[pname][19] = fields.acc3
else
wardrobe.formspec_selections_rgb[pname][19] = "ffffff"
end
if wardrobe.is_hex(fields.acc4) then
wardrobe.formspec_selections_rgb[pname][20] = fields.acc4
else
wardrobe.formspec_selections_rgb[pname][20] = "ffffff"
end
if wardrobe.is_hex(fields.acc5) then
wardrobe.formspec_selections_rgb[pname][21] = fields.acc5
else
wardrobe.formspec_selections_rgb[pname][21] = "ffffff"
end
if wardrobe.is_hex(fields.acc6) then
wardrobe.formspec_selections_rgb[pname][22] = fields.acc6
else
wardrobe.formspec_selections_rgb[pname][22] = "ffffff"
end
end
function wardrobe.is_hex(textfield)
if string.match(textfield, "^[0-9a-fA-F]+$") and #textfield == 6 then
return true
else
return false
end
end
function wardrobe.load_user_data()
end
minetest.register_on_joinplayer(function(player)
pname = player:get_player_name()
wardrobe.formspec_selections[pname] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
wardrobe.formspec_selections_rgb[pname] = {}
for i=1,22 do -- if you think i'm writing ffffff for each table line, think again
wardrobe.formspec_selections_rgb[pname][i] = "ffffff"
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment