-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle-map.lua
264 lines (241 loc) · 7.67 KB
/
bundle-map.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
local _map_bag = "6ca58b"
local _last_id = ""
local loading = true
-- local my_objects = []
function onLoad()
local buttons = {
{
click_function = "bundle",
function_owner = self,
label = "Bundle",
position = {0, 1.8, -0.6},
scale = {0.5, 0.5, 0.5},
width = 1600,
height = 800,
font_size = 500,
color = {0.118, 0.53, 1, 1}
},
{
click_function = "add_id_button",
function_owner = self,
label = "+",
position = {-0.4, 1.79999995231628, 0.400000005960464},
scale = {0.5, 0.5, 0.5},
width = 900,
height = 800,
font_size = 500,
color = {0.2588, 0.8235, 0.4078, 1},
tooltip = "Add item below bag"
},
{
click_function = "create_area",
function_owner = self,
label = "A",
position = {0.4, 1.79999995231628, 0.400000005960464},
scale = {0.5, 0.5, 0.5},
width = 900,
height = 800,
font_size = 500,
color = {1, 0.2549, 0.2117, 1},
tooltip = "Create area to envelop all items\nSet area by right clicking"
}
}
for i = 1, #buttons do
self.createButton(buttons[i])
end
loading = false
end
function onCollisionEnter(info)
if not loading then
if info then
local obj = info.collision_object
if obj then
if obj.interactable then
if obj.getGUID() then
_last_id = obj.getGUID()
self.editButton({index = 1, tooltip = _last_id})
end
end
end
end
end
end
function add_id_button(owner, color, alt_click)
if color == "Black" then
local desc = self.getDescription()
if _last_id then
self.setDescription(desc .. _last_id .. "\n")
log("Added " .. _last_id)
self.editButton({index = 1, label = countIDs()})
end
end
end
function addId(id)
log("Entered addid")
local ids = nil
log(self.memo)
if self.memo ~= nil then
ids = JSON.decode(self.memo)
else ids = {} end
if type(id) == "string" then
table.insert(ids, id)
self.memo = JSON.encode(ids)
log("Added id: " .. id .. ". Total IDs: " .. #ids)
elseif type(id) == "table" then
for i=1,#id do
table.insert(ids, id[i])
end
self.memo = JSON.encode(ids)
log("Added " .. #id .. " ID(s). Total IDs: " .. #ids)
end
end
local _area = nil
function create_area(owner, color, alt_click)
if color == "Black" then
if alt_click then
if _area then
local objs = _area.getObjects()
local found = 0
local array = {}
for i = 1, #objs do
obj = objs[i]
if obj.interactable and obj ~= self then
table.insert(array, obj.getGUID())
found = found + 1
end
end
addId(array)
-- local encoded = JSON.encode(array)
-- self.setGMNotes(encoded)
destroyObject(_area)
_area = nil
print("Found " .. found .. " objects.")
found = 0
end
else
if _area then
destroyObject(_area)
_area = nil
end
positionToZone = self.getPosition()
spawnParams = {
type = "ScriptingTrigger",
position = positionToZone,
rotation = {x = 0, y = 90, z = 0},
scale = {x = 4, y = 4, z = 4},
sound = false,
snap_to_grid = true
}
_area = spawnObject(spawnParams)
end
end
end
function countIDs()
local desc = self.getDescription()
local counter = 0
local arr = strsplit(desc, "\n")
if #arr > 0 then
for i = 1, #arr do
if arr[i]:len() == 6 then
counter = counter + 1
end
end
end
local gm = self.getGMNotes()
if gm ~= nil and gm ~= "" then
counter = counter + #JSON.decode(gm)
end
return counter
end
function bundle(owner, color, alt_click)
if color == "Black" then
if not alt_click then
if self.memo ~= "" then
local ids = JSON.decode(self.memo)
for i, id in ipairs(ids) do
local obj = getObjectFromGUID(id)
if obj then
processObj(obj)
obj.setScale({0.25, 0.25, 0.25})
obj.setLock(false)
obj.setFogOfWarReveal({reveal = false})
self.putObject(obj)
end
end
elseif #self.getGMNotes() > 0 then
local desc = self.getDescription()
local ids = strsplit(desc, "\n")
if #ids > 0 then
for i = 1, #ids do
local obj = getObjectFromGUID(ids[i])
if obj then
processObj(obj)
obj.setScale({0.25, 0.25, 0.25})
obj.setLock(false)
obj.setFogOfWarReveal(
{
reveal = false
}
)
self.putObject(obj)
end
end
end
elseif #self.getDescription() > 0 then
local gm = self.getGMNotes()
if gm ~= nil and gm ~= "" then
local decoded = JSON.decode(gm)
for i = 1, #decoded do
local obj = getObjectFromGUID(decoded[i])
if obj then
processObj(obj)
obj.setScale({0.25, 0.25, 0.25})
obj.setLock(false)
obj.setFogOfWarReveal(
{
reveal = false
}
)
self.putObject(obj)
end
end
end
end
else
goHome()
end
end
end
function goHome()
local home_bag = getObjectFromGUID(_map_bag)
home_bag.putObject(self)
end
function processObj(obj)
local desc = obj.getDescription()
if desc == "" then
local str = ""
local pos = obj.getPosition()
local rotation = obj.getRotation()
local scale = obj.getScale()
str = round(pos.x, 2) .. "," .. round(pos.y, 2) .. "," .. round(pos.z, 2) .. "\n"
str = str .. round(rotation.x, 0) .. "," .. round(rotation.y, 0) .. "," .. round(rotation.z, 0) .. "\n"
str = str .. round(scale.x, 3) .. "," .. round(scale.y, 3) .. "," .. round(scale.z, 3)
obj.setDescription(str)
obj.tooltip = false
end
end
function round(num, numDecimalPlaces)
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end
function strsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
i = 1
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
t[i] = str
i = i + 1
end
return t
end