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 | SaplingPallet = {}; |
4 | SaplingPallet_mt = Class(SaplingPallet, FillablePallet); |
5 | |
6 | InitStaticObjectClass(SaplingPallet, "SaplingPallet", ObjectIds.OBJECT_SAPLING_PALLET); |
7 | |
8 | function 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; |
24 | end; |
25 | |
26 | function 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); |
32 | end; |
33 | |
34 | function SaplingPallet:readStream(streamId, connection) |
35 | SaplingPallet:superClass().readStream(self, streamId, connection); |
36 | local fillLevel = streamReadUInt8(streamId); |
37 | self:setFillLevel(fillLevel, false); |
38 | end; |
39 | |
40 | function SaplingPallet:writeStream(streamId, connection) |
41 | SaplingPallet:superClass().writeStream(self, streamId, connection); |
42 | streamWriteUInt8(streamId, self.fillLevel); |
43 | end; |
44 | |
45 | function 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 |
55 | end; |
56 | |
57 | function 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 |
66 | end; |
67 | |
68 | function 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; |
106 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de