Skip to content

Commit 4674fa9

Browse files
authored
Maintenance map editor (#511)
1 parent 679c01b commit 4674fa9

File tree

16 files changed

+84
-57
lines changed

16 files changed

+84
-57
lines changed

[editor]/edf/edf.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,11 @@ function edfCreateElement(elementType, creatorClient, fromResource, parametersTa
620620
elseif dataField == "rotation" then
621621
edfSetElementRotation(newElement, dataValue[1], dataValue[2], dataValue[3], dataValue[4])
622622
elseif dataField == "interior" then
623-
setElementInterior(newElement, dataValue)
623+
if dataValue == -1 then
624+
setElementInterior(newElement, 0) -- Interior -1 only works on removeWorldModel (But element data must be set to -1)
625+
else
626+
setElementInterior(newElement, dataValue)
627+
end
624628
setElementData(newElement, dataField, dataValue)
625629
elseif dataField == "dimension" then
626630
setElementDimension(newElement, dataValue)

[editor]/edf/interface.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
local interface_mt = {
22
__index = function(t, k)
3-
t[k] = function(...) return call(t.res, k, ...) end
3+
t[k] = function(...)
4+
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
5+
return call(t.res, k, ...)
6+
end
47
return t[k]
58
end
69
}

[editor]/edf/properties_client.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ propertyGetters = {
2323
model = getElementModel,
2424
rotZ = getPedRotation,
2525
health = getElementHealth,
26-
armor = setPedArmor,
26+
armor = getPedArmor,
2727
collisions = function(element)
2828
local collisions = getElementData(element, "collisions")
2929
if collisions == "true" or collisions == false then

[editor]/editor/freeroam.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ addEventHandler("onResourceStart", resourceRoot,
33
if not getResourceFromName("freeroam") then
44
outputChatBox("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!", root, 255, 0, 0)
55
outputDebugString("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!")
6-
editor_gui.outputMessage("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!", root, 255, 0, 0)
76
end
87
end
98
)

[editor]/editor_gui/client/elementproperties.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,8 @@ function openPropertiesBox( element, resourceName, shortcut )
814814
addEventHandler("onClientElementDataChange", selectedElement, checkForNewID)
815815

816816
addEDFPropertyControlsForElement( selectedElement )
817-
addPropertyControl("selection", "locked", "Locked", function (control) exports.editor_main:lockSelectedElement(selectedElement, control:getValue() == "true" or false) end, {value = exports.editor_main:isElementLocked(selectedElement) and "true" or "false", validvalues = {"false","true"}, datafield = "locked"})
817+
-- `locked` is reserved for vehicles
818+
addPropertyControl("selection", "locked-s", "Locked selection", function (control) exports.editor_main:lockSelectedElement(selectedElement, control:getValue() == "true" or false) end, {value = exports.editor_main:isElementLocked(selectedElement) and "true" or "false", validvalues = {"false","true"}, datafield = "locked"})
818819

819820
creatingNewElment = false
820821
syncPropertiesCallback = applyPropertiesChanges

[editor]/editor_gui/client/interface.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ local interface = {
1414

1515
local interface_mt = {
1616
__index = function(t, k)
17-
return function(...) return call(t.res, k, ...) end
17+
return function(...)
18+
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
19+
return call(t.res, k, ...)
20+
end
1821
end
1922
}
2023

[editor]/editor_gui/server/interface.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local interface = {
77

88
local interface_mt = {
99
__index = function(t, k)
10+
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
1011
return function(...) return call(t.res, k, ...) end
1112
end
1213
}

[editor]/editor_main/client/colpatch.lua

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,26 @@ function createColPatchObjects()
6464
g_placementObjs = {}
6565
g_placementIDObjs = {}
6666

67-
for k,v in ipairs(g_placementData) do
68-
if k % COL_CREATE_FRAME == 0 then
69-
coroutine.yield()
70-
end
71-
72-
local obj = createObject(v.id, v.x, v.y, v.z, v.rx, v.ry, v.rz)
73-
if obj then
74-
setElementDimension(obj, getWorkingDimension())
75-
setElementAlpha(obj, 0)
76-
if v.int > 0 and v.int < 256 then
77-
setElementInterior(obj, v.int)
67+
if g_placementData then
68+
for k,v in ipairs(g_placementData) do
69+
if k % COL_CREATE_FRAME == 0 then
70+
coroutine.yield()
7871
end
79-
g_placementObjs[obj] = v
8072

81-
if not g_placementIDObjs[v.id] then
82-
g_placementIDObjs[v.id] = {}
73+
local obj = createObject(v.id, v.x, v.y, v.z, v.rx, v.ry, v.rz)
74+
if obj then
75+
setElementDimension(obj, getWorkingDimension())
76+
setElementAlpha(obj, 0)
77+
if v.int > 0 and v.int < 256 then
78+
setElementInterior(obj, v.int)
79+
end
80+
g_placementObjs[obj] = v
81+
82+
if not g_placementIDObjs[v.id] then
83+
g_placementIDObjs[v.id] = {}
84+
end
85+
table.insert(g_placementIDObjs[v.id], obj)
8386
end
84-
table.insert(g_placementIDObjs[v.id], obj)
8587
end
8688
end
8789

@@ -95,12 +97,14 @@ end
9597

9698
function destroyColPatchObjects()
9799
local i = 0
98-
for obj in pairs(g_placementObjs) do
99-
if i % COL_DESTROY_FRAME == 0 then
100-
coroutine.yield()
100+
if g_placementObjs then
101+
for obj in pairs(g_placementObjs) do
102+
if i % COL_DESTROY_FRAME == 0 then
103+
coroutine.yield()
104+
end
105+
destroyElement(obj)
106+
i = i + 1
101107
end
102-
destroyElement(obj)
103-
i = i + 1
104108
end
105109

106110
g_placementObjs = nil
@@ -175,17 +179,19 @@ end
175179

176180
function loadAndReplaceCollision()
177181
g_colElements = {}
178-
for k,colData in ipairs(g_colData) do
179-
if k % COL_LOAD_FRAME == 0 then
180-
coroutine.yield()
181-
end
182-
183-
local col = engineLoadCOL(colData.colFile)
184-
if col then
185-
if engineReplaceCOL(col, colData.colID) then
186-
table.insert(g_colElements, col)
187-
else
188-
destroyElement(col)
182+
if g_colData then
183+
for k,colData in ipairs(g_colData) do
184+
if k % COL_LOAD_FRAME == 0 then
185+
coroutine.yield()
186+
end
187+
188+
local col = engineLoadCOL(colData.colFile)
189+
if col then
190+
if engineReplaceCOL(col, colData.colID) then
191+
table.insert(g_colElements, col)
192+
else
193+
destroyElement(col)
194+
end
189195
end
190196
end
191197
end
@@ -194,27 +200,33 @@ function loadAndReplaceCollision()
194200
end
195201

196202
function restoreAndDestroyCollision()
197-
for k,colData in ipairs(g_colData) do
198-
if k % COL_RESTORE_FRAME == 0 then
199-
coroutine.yield()
200-
end
201-
engineRestoreCOL(colData.colID)
202-
end
203-
for k,col in ipairs(g_colElements) do
204-
if isElement(col) then
203+
if g_colData then
204+
for k,colData in ipairs(g_colData) do
205205
if k % COL_RESTORE_FRAME == 0 then
206206
coroutine.yield()
207207
end
208-
destroyElement(col)
208+
engineRestoreCOL(colData.colID)
209209
end
210210
end
211-
212-
g_colElements = nil
211+
if g_colElements then
212+
for k,col in ipairs(g_colElements) do
213+
if isElement(col) then
214+
if k % COL_RESTORE_FRAME == 0 then
215+
coroutine.yield()
216+
end
217+
destroyElement(col)
218+
end
219+
end
220+
g_colElements = nil
221+
end
222+
213223
destroyColPatchObjects()
214224
end
215225

216226
-- Called after we finish loading to apply removed world objects in current map
217227
function applyRemovedColPatches()
228+
if not g_placementIDObjs then return end
229+
if not g_placementObjs then return end
218230
for i,element in ipairs(getElementsByType("removeWorldObject")) do
219231
local model = getElementData(element, "model")
220232
if g_placementIDObjs[model] then
@@ -242,6 +254,8 @@ end
242254

243255
local function onClientElementCreateDestroy()
244256
if not g_placementData then return end
257+
if not g_placementIDObjs then return end
258+
if not g_placementObjs then return end
245259
if (getElementType(source) ~= "removeWorldObject") then return end
246260

247261
local model = getElementData(source, "model")

[editor]/editor_main/client/interface.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local interface = {
1111

1212
local interface_mt = {
1313
__index = function(t, k)
14+
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
1415
return function(...) return call(t.res, k, ...) end
1516
end
1617
}

[editor]/editor_main/client/main.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ function processClick ( clickedElement, key, keyState, lookX, lookY, lookZ )
488488
end
489489
end
490490

491-
if g_selectedElement ~= clickedElement and g_lock[clickedElement] then
491+
if g_selectedElement ~= clickedElement and g_lock[edf.edfGetAncestor(clickedElement)] then
492492
editor_gui.outputMessage("This element is locked, Press '"..cc["lock_selected_element"]:upper().."' to unlock it.", 255,255,255)
493493
return false
494494
end
@@ -517,7 +517,7 @@ end
517517
function processDoubleClick ( clickedElement, key )
518518
if not clickedElement then return end
519519

520-
if g_selectedElement ~= clickedElement and g_lock[clickedElement] then
520+
if g_selectedElement ~= clickedElement and g_lock[edf.edfGetAncestor(clickedElement)] then
521521
editor_gui.outputMessage("This element is locked, Press '"..cc["lock_selected_element"]:upper().."' to unlock it.", 255,255,255)
522522
return false
523523
end

0 commit comments

Comments
 (0)