-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.lua
161 lines (147 loc) · 5.74 KB
/
config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
-- player name -> car lua entity (that's being configured)
local config = {}
function show_automobile_config(player_name)
local entity = config[player_name]
local color = entity.color
local decal = entity.decal
local front = entity.front
local back = entity.back
local wheel = entity.wheel
--local texture = config[player_name]:get_properties().textures[1]
-- parse index vars
--[[local s_end
local s_start
-- color
_, s_end = texture:find(".png")
color = texture:sub(1,s_end)
-- backs
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
back = texture:sub(s_start + 1, s_end)
-- fronts
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
front = texture:sub(s_start + 1, s_end)
-- wheels
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
wheel = texture:sub(s_start + 1, s_end)
-- decal
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
decal = texture:sub(s_start + 1, s_end)]]
--[[formspec = formspec .. "label[0,0;color:]"
.. "dropdown[0,1;2;color;"
for _, value in pairs(colors) do
formspec = formspec .. value .. ","
end
formspec = formspec .. ";" .. color .. "]"]]
local auto_type = entity.automobile_type
local num_wheels = 8
local formspec = "size[10,7.5]button_exit[9,0;1,1;quit;X]"
-- colors
formspec = formspec .. "label[0,0;color:]"
for i = 1, entity.num_colors do
formspec = formspec .. "image_button[" .. (i - 1) .. ",0.5;1,1;automobiles_" .. auto_type .. "_color_" .. i .. "_preview.png;color_automobiles_" .. auto_type .. "_color_".. i ..".png;;true;true;]"
end
-- decals
formspec = formspec .. "label[0,1.5;decal:]"
for i = 1, entity.num_decals do
formspec = formspec .. "image_button[" .. (i - 1) .. ",2;1,1;automobiles_" .. auto_type .. "_decal_" .. i .. "_preview.png;decal_automobiles_" .. auto_type .. "_decal_".. i ..".png;;true;true;]"
end
-- fronts
formspec = formspec .. "label[0,3;front:]"
for i = 1, entity.num_fronts do
formspec = formspec .. "image_button[" .. (i - 1) .. ",3.5;1,1;automobiles_" .. auto_type .. "_front_" .. i .. "_preview.png;front_automobiles_" .. auto_type .. "_front_".. i ..".png;;true;true;]"
end
-- backs
formspec = formspec .. "label[0,4.5;back:]"
for i = 1, entity.num_backs do
formspec = formspec .. "image_button[" .. (i - 1) .. ",5;1,1;automobiles_" .. auto_type .. "_back_" .. i .. "_preview.png;back_automobiles_" .. auto_type .. "_back_".. i ..".png;;true;true;]"
end
-- wheels
formspec = formspec .. "label[0,6;wheels:]"
for i = 1, num_wheels do
formspec = formspec .. "image_button[" .. (i - 1) .. ",6.5;1,1;automobiles_wheel_" .. i .. "_preview.png;wheel_automobiles_wheel_" .. i .. ".png;;true;true;]"
end
--formspec = formspec .. "box[2,;1,1;red]"
--formspec = formspec .. "image_button[0,0;1,1;automobiles_config_tool.png;button;;true;true;automobiles_car_inv.png]"
--formspec = formspec .. "image_button[2,2;1,1;automobiles_config_tool.png;button;;true;false;automobiles_car_inv.png]"
minetest.show_formspec(player_name, "automobiles:config", formspec)
end
minetest.register_tool("automobiles:config_tool",{
description = "Automobile Configuration Tool",
inventory_image = "automobiles_config_tool.png",
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type == "object" and not pointed_thing.ref:is_player() then
local entity = pointed_thing.ref:get_luaentity()
--[[for key,value in pairs(entity) do
minetest.chat_send_all(key)
end]]
if entity.automobile_type then
if entity.owner_name ~= user:get_player_name() then
minetest.chat_send_player(user:get_player_name(), "This " .. entity.automobile_type .. " is owned by " .. entity.owner_name)
return
end
--local texture = pointed_thing.ref:get_properties().textures[1]
--[[ parse index vars
local s_end
local s_start
-- color
_, s_end = texture:find(".png")
local color = texture:sub(1,s_end)
-- back
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
local back = texture:sub(s_start + 1, s_end)
-- front
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
local front = texture:sub(s_start + 1, s_end)
-- wheel
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
local wheel = texture:sub(s_start + 1, s_end)
-- decal
_, s_start = texture:find("=", s_end)
_, s_end = texture:find(".png", s_end)
local decal = texture:sub(s_start + 1, s_end)]]
config[user:get_player_name()] = entity
show_automobile_config(user:get_player_name())
end
end
end,
})
minetest.register_craft({
output = "automobiles:config_tool",
recipe = {
{"default:steel_ingot", "", ""},
{"", "default:steel_ingot", ""},
{"", "", "default:steel_ingot"}
},
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "automobiles:config" then
for str, _ in pairs(fields) do
if str == "quit" then
config[player:get_player_name()] = nil
else
local texture_type
local texture
local devider
local entity = config[player:get_player_name()]
_, devider = str:find("_")
texture_type = str:sub(1, devider - 1)
texture = str:sub(devider + 1)
--minetest.chat_send_all(texture_type)
entity[texture_type] = texture
local entity_props = entity.object:get_properties()
-- recompile texure
entity_props.textures = { entity.compile_texture(entity.color, entity.wheel, entity.decal, entity.back, entity.front) }
entity.object:set_properties(entity_props)
end
end
return true
end
return false
end)