Sprache Deutsch Language English

Script Dokumentation LS 2015 - SaplingPallet (Patch 1.3)

Script Dokumentation Übersicht

scripts/objects/SaplingPallet.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
3SaplingPallet = {};
4SaplingPallet_mt = Class(SaplingPallet, FillablePallet);
5
6InitStaticObjectClass(SaplingPallet, "SaplingPallet", ObjectIds.OBJECT_SAPLING_PALLET);
7
8function SaplingPallet:new(isServer, isClient, customMt)
9 local mt = customMt;
10 if mt == nil then
11 mt = SaplingPallet_mt;
12 end;
13
14 local self = FillablePallet:new(isServer, isClient, mt);
15
16 registerObjectClassName(self, "SaplingPallet");
17
18 self.fillType = Fillable.FILLTYPE_TREESAPLINGS;
19 self.fillLevel = 0;
20 self.capacity = 20;
21 self.synchronizeFillLevel = false;
22
23 return self;
24end;
25
26function SaplingPallet:delete()
27 if self.saplingFilename ~= nil then
28 Utils.releaseSharedI3DFile(self.saplingFilename, nil, true);
29 end;
30 unregisterObjectClassName(self);
31 SaplingPallet:superClass().delete(self);
32end;
33
34function SaplingPallet:readStream(streamId, connection)
35 SaplingPallet:superClass().readStream(self, streamId, connection);
36 local fillLevel = streamReadUInt8(streamId);
37 self:setFillLevel(fillLevel, false);
38end;
39
40function SaplingPallet:writeStream(streamId, connection)
41 SaplingPallet:superClass().writeStream(self, streamId, connection);
42 streamWriteUInt8(streamId, self.fillLevel);
43end;
44
45function SaplingPallet:readUpdateStream(streamId, timestamp, connection)
46 SaplingPallet:superClass().readUpdateStream(self, streamId, timestamp, connection);
47 if connection:getIsServer() then
48 if not self.synchronizeFillLevel then
49 if streamReadBool(streamId) then
50 local fillLevel = streamReadUInt8(streamId);
51 self:setFillLevel(fillLevel, false);
52 end
53 end;
54 end
55end;
56
57function SaplingPallet:writeUpdateStream(streamId, connection, dirtyMask)
58 SaplingPallet:superClass().writeUpdateStream(self, streamId, connection, dirtyMask);
59 if not connection:getIsServer() then
60 if not self.synchronizeFillLevel then
61 if streamWriteBool(streamId, bitAND(dirtyMask, self.fillablePalletDirtyFlag) ~= 0) then
62 streamWriteUInt8(streamId, self.fillLevel);
63 end
64 end;
65 end
66end;
67
68function SaplingPallet:setNodeId(nodeId)
69 SaplingPallet:superClass().setNodeId(self, nodeId);
70
71 self.capacity = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "capacity")), self.capacity);
72
73 self.saplingFilename = getUserAttribute(nodeId, "saplingFilename");
74 if self.saplingFilename ~= nil then
75 if self.visibilityNodes ~= nil then
76 self.saplingFilename = Utils.getFilename(self.saplingFilename, self.baseDirectory)
77 local i3dNode = Utils.loadSharedI3DFile(self.saplingFilename);
78 self.capacity = getNumOfChildren(self.visibilityNodes);
79 if i3dNode ~= 0 and self.capacity > 0 then
80 for i=0, self.capacity-1 do
81 local node = clone(i3dNode, false, false, false);
82 link(getChildAt(self.visibilityNodes, i), node);
83 if getUserAttribute(nodeId, "useRandomRot") then
84 setRotation(node, 0, math.random(0, 2*math.pi), 0);
85 end;
86 end;
87 self:setFillLevel(Utils.getNoNil(tonumber(getUserAttribute(nodeId, "startFillLevel")), 0), false);
88 end;
89 else
90 print("Warning: fillNodeFillename requires use of visibilityNodes");
91 end;
92 end;
93
94 local treeType = getUserAttribute(nodeId, "treeType");
95 if treeType ~= nil then
96 local tree = TreePlantUtil.treeTypes[treeType];
97 if tree == nil then
98 print("Warning: Invalid treeType '"..treeType.."'.");
99 tree = next(TreePlantUtil.treeTypes);
100 end;
101 self.treeType = tree.index;
102 else
103 self.treeType = next(TreePlantUtil.treeTypes).index;
104 print("Warning: Missing treetype!");
105 end;
106end;
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