Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
2 | |
3 | TreePlaceable = {}; |
4 | TreePlaceable_mt = Class(TreePlaceable, Placeable); |
5 | |
6 | InitStaticObjectClass(TreePlaceable, "TreePlaceable", ObjectIds.OBJECT_TREE_PLACEABLE); |
7 | |
8 | function TreePlaceable:new(isServer, isClient, customMt) |
9 | local mt = customMt; |
10 | if mt == nil then |
11 | mt = TreePlaceable_mt; |
12 | end; |
13 | |
14 | local self = Placeable:new(isServer, isClient, mt); |
15 | |
16 | self.useMultiRootNode = true; |
17 | |
18 | registerObjectClassName(self, "TreePlaceable"); |
19 | |
20 | return self; |
21 | end; |
22 | |
23 | function TreePlaceable:delete() |
24 | unregisterObjectClassName(self); |
25 | TreePlaceable:superClass().delete(self); |
26 | end; |
27 | |
28 | function TreePlaceable:readStream(streamId, connection) |
29 | TreePlaceable:superClass().readStream(self, streamId, connection); |
30 | if connection:getIsServer() then |
31 | local serverSplitShapeFileId = streamReadInt32(streamId); |
32 | if self.splitShapeFileId ~= nil and self.splitShapeFileId >= 0 and serverSplitShapeFileId >= 0 then |
33 | setSplitShapesFileIdMapping(self.splitShapeFileId, serverSplitShapeFileId); |
34 | end |
35 | end; |
36 | end; |
37 | |
38 | function TreePlaceable:writeStream(streamId, connection) |
39 | TreePlaceable:superClass().writeStream(self, streamId, connection); |
40 | if not connection:getIsServer() then |
41 | streamWriteInt32(streamId, Utils.getNoNil(self.splitShapeFileId, -1)); |
42 | end; |
43 | end; |
44 | |
45 | |
46 | function TreePlaceable:createNode(i3dFilename) |
47 | -- make sure the i3d is loaded, so that the file id will not be used by the i3d clone source |
48 | setSplitShapesLoadingFileId(-1); |
49 | setSplitShapesNextFileId(true); |
50 | Utils.fillSharedI3DFileCache(i3dFilename, nil); |
51 | |
52 | setSplitShapesLoadingFileId(Utils.getNoNil(self.splitShapeFileId, -1)); |
53 | self.splitShapeFileId = setSplitShapesNextFileId(); |
54 | |
55 | if not TreePlaceable:superClass().createNode(self, i3dFilename) then |
56 | return false; |
57 | end; |
58 | |
59 | return true; |
60 | end; |
61 | |
62 | function TreePlaceable:finalizePlacement() |
63 | TreePlaceable:superClass().finalizePlacement(self); |
64 | end |
65 | |
66 | function TreePlaceable:getNeedsSaving() |
67 | if getNumOfChildren(self.nodeId) == 0 or (self.splitShapeFileId ~= nil and not getFileIdHasSplitShapes(self.splitShapeFileId)) then |
68 | -- remove placeable of all split shapes have been removed |
69 | self:delete(); |
70 | return false; |
71 | end |
72 | return TreePlaceable:superClass().getNeedsSaving(self); |
73 | end; |
74 | |
75 | function TreePlaceable:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
76 | |
77 | self.splitShapeFileId = getXMLInt(xmlFile, key.."#splitShapeFileId"); -- note: might be nil if not available |
78 | |
79 | if not TreePlaceable:superClass().loadFromAttributesAndNodes(self, xmlFile, key, resetVehicles) then |
80 | return false; |
81 | end; |
82 | |
83 | return true; |
84 | end; |
85 | |
86 | function TreePlaceable:getSaveAttributesAndNodes(nodeIdent) |
87 | local attributes, nodes = TreePlaceable:superClass().getSaveAttributesAndNodes(self, nodeIdent); |
88 | if self.splitShapeFileId ~= nil then |
89 | attributes = string.format('%s splitShapeFileId="%d"', attributes, self.splitShapeFileId); |
90 | end |
91 | return attributes, nodes; |
92 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de