14 | function ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, key, objects, rootNode, parent) |
15 | local i = 0; |
16 | while true do |
17 | local nodeKey = string.format(key .. ".objectChange(%d)", i); |
18 | if not hasXMLProperty(xmlFile, nodeKey) then |
19 | break; |
20 | end |
21 | local node = Utils.indexToObject(rootNode, getXMLString(xmlFile, nodeKey .. "#node")) |
22 | if node ~= nil then |
23 | local object = {}; |
24 | object.node = node; |
25 | ObjectChangeUtil.loadValuesFromXML(xmlFile, nodeKey, node, object, parent); |
26 | table.insert(objects, object); |
27 | end |
28 | i = i + 1; |
29 | end |
30 | end |
39 | function ObjectChangeUtil.loadValuesFromXML(xmlFile, key, node, object, parent) |
40 | object.visibilityActive = Utils.getNoNil(getXMLBool(xmlFile, key.."#visibilityActive"), getVisibility(node)); |
41 | object.visibilityInactive = Utils.getNoNil(getXMLBool(xmlFile, key.."#visibilityInactive"), getVisibility(node)); |
42 | object.translationActive = Utils.getNoNil(Utils.getVectorNFromString(getXMLString(xmlFile, key.."#translationActive"), 3), {getTranslation(node)}); |
43 | object.translationInactive = Utils.getNoNil(Utils.getVectorNFromString(getXMLString(xmlFile, key.."#translationInactive"), 3), {getTranslation(node)}); |
44 | object.rotationActive = Utils.getNoNil(Utils.getRadiansFromString(getXMLString(xmlFile, key.."#rotationActive"), 3), {getRotation(node)}); |
45 | object.rotationInactive = Utils.getNoNil(Utils.getRadiansFromString(getXMLString(xmlFile, key.."#rotationInactive"), 3), {getRotation(node)}); |
46 | object.scaleActive = Utils.getNoNil(Utils.getVectorNFromString(getXMLString(xmlFile, key.."#scaleActive"), 3), {getScale(node)}); |
47 | object.scaleInactive = Utils.getNoNil(Utils.getVectorNFromString(getXMLString(xmlFile, key.."#scaleInactive"), 3), {getScale(node)}); |
48 | object.collisionMask = getCollisionMask(object.node); |
49 | object.collisionActive = getXMLBool(xmlFile, key.."#collisionActive"); |
50 | object.collisionInactive = getXMLBool(xmlFile, key.."#collisionInactive"); |
51 | |
52 | if parent ~= nil and parent.loadObjectChangeValuesFromXML ~= nil then |
53 | parent:loadObjectChangeValuesFromXML(xmlFile, key, node, object) |
54 | end |
55 | end |
75 | function ObjectChangeUtil.setObjectChange(object, isActive, target, updateFunc) |
76 | if isActive then |
77 | setVisibility(object.node, object.visibilityActive); |
78 | setTranslation(object.node, object.translationActive[1], object.translationActive[2], object.translationActive[3]); |
79 | setRotation(object.node, object.rotationActive[1], object.rotationActive[2], object.rotationActive[3]); |
80 | setScale(object.node, object.scaleActive[1], object.scaleActive[2], object.scaleActive[3]); |
81 | if object.collisionActive then |
82 | setCollisionMask(object.node, object.collisionMask); |
83 | elseif object.collisionActive == false then |
84 | setCollisionMask(object.node, 0); |
85 | end |
86 | else |
87 | setVisibility(object.node, object.visibilityInactive); |
88 | setTranslation(object.node, object.translationInactive[1], object.translationInactive[2], object.translationInactive[3]); |
89 | setRotation(object.node, object.rotationInactive[1], object.rotationInactive[2], object.rotationInactive[3]); |
90 | setScale(object.node, object.scaleInactive[1], object.scaleInactive[2], object.scaleInactive[3]); |
91 | if object.collisionInactive then |
92 | setCollisionMask(object.node, object.collisionMask); |
93 | elseif object.collisionInactive == false then |
94 | setCollisionMask(object.node, 0); |
95 | end |
96 | end; |
97 | if target ~= nil then |
98 | if target.setObjectChangeValues ~= nil then |
99 | target:setObjectChangeValues(object, isActive) |
100 | end |
101 | if updateFunc ~= nil then |
102 | updateFunc(target, object.node); |
103 | end |
104 | end |
105 | end |
114 | function ObjectChangeUtil.updateObjectChanges(xmlFile, key, configKey, rootNode, parent) |
115 | local i = 0; |
116 | local activeI = (configKey - 1); |
117 | while true do |
118 | local objectChangeKey = string.format(key.."(%d)", i); |
119 | if not hasXMLProperty(xmlFile, objectChangeKey) then |
120 | break; |
121 | end |
122 | if i ~= activeI then |
123 | local objects = {}; |
124 | ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, objectChangeKey, objects, rootNode, parent); |
125 | ObjectChangeUtil.setObjectChanges(objects, false, parent); |
126 | end |
127 | i = i + 1; |
128 | end |
129 | -- Set the active config last so that it can overwrite settings of inactive configurations |
130 | if i > activeI then |
131 | local objectChangeKey = string.format(key.."(%d)", activeI); |
132 | local objects = {}; |
133 | ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, objectChangeKey, objects, rootNode, parent); |
134 | ObjectChangeUtil.setObjectChanges(objects, true, parent); |
135 | end |
136 | end |