Sprache Deutsch Language English

Script Dokumentation LS 2015 - TreePlaceable (Patch 1.3)

Script Dokumentation Übersicht

scripts/placeables/TreePlaceable.lua

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
3TreePlaceable = {};
4TreePlaceable_mt = Class(TreePlaceable, Placeable);
5
6InitStaticObjectClass(TreePlaceable, "TreePlaceable", ObjectIds.OBJECT_TREE_PLACEABLE);
7
8function 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;
21end;
22
23function TreePlaceable:delete()
24 unregisterObjectClassName(self);
25 TreePlaceable:superClass().delete(self);
26end;
27
28function 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;
36end;
37
38function 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;
43end;
44
45
46function 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;
60end;
61
62function TreePlaceable:finalizePlacement()
63 TreePlaceable:superClass().finalizePlacement(self);
64end
65
66function 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);
73end;
74
75function 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;
84end;
85
86function 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;
92end;
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht