Sprache Deutsch Language English

Script Dokumentation LS 2015 - Cover (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/Cover.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1--
2-- Cover
3-- This is the specialization for Covers
4--
5-- @author Stefan Geiger
6-- @date 16/07/2014
7--
8-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
9
10source("dataS/scripts/vehicles/specializations/SetCoverStateEvent.lua");
11
12Cover = {};
13
14function Cover.prerequisitesPresent(specializations)
15 return SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations);
16end;
17
18function Cover:preLoad(xmlFile)
19 self.getIsToggleCoverAllowed = Cover.getIsToggleCoverAllowed;
20end;
21
22function Cover:load(xmlFile)
23
24 self.setCoverState = SpecializationUtil.callSpecializationsFunction("setCoverState");
25 self.allowFillType = Utils.overwrittenFunction(self.allowFillType, Cover.allowFillType);
26 self.getAllowFillFromAir = Utils.overwrittenFunction(self.getAllowFillFromAir, Cover.getAllowFillFromAir);
27
28 self.coverAnimation = getXMLString(xmlFile, "vehicle.cover#animationName");
29 if self.coverAnimation ~= nil then
30 self:setCoverState(true, true);
31 else
32 self.isCoverOpen = true;
33 end;
34end;
35
36function Cover:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
37 if self.coverAnimation ~= nil then
38 local isCoverOpen = getXMLBool(xmlFile, key.."#isCoverOpen");
39 self:setCoverState(isCoverOpen, true);
40 end
41 return BaseMission.VEHICLE_LOAD_OK;
42end;
43
44function Cover:getSaveAttributesAndNodes(nodeIdent)
45 if self.coverAnimation ~= nil then
46 local attributes = 'isCoverOpen="'..tostring(self.isCoverOpen)..'"';
47 return attributes, nil;
48 end
49 return nil;
50end;
51
52function Cover:delete()
53end;
54
55function Cover:mouseEvent(posX, posY, isDown, isUp, button)
56end;
57
58function Cover:keyEvent(unicode, sym, modifier, isDown)
59end;
60
61function Cover:readStream(streamId, connection)
62 if connection:getIsServer() then
63 if self.coverAnimation ~= nil then
64 local isOpen = streamReadBool(streamId);
65 self:setCoverState(isOpen, true);
66 end;
67 end;
68end;
69
70function Cover:writeStream(streamId, connection)
71 if not connection:getIsServer() then
72 if self.coverAnimation ~= nil then
73 streamWriteBool(streamId, self.isCoverOpen);
74 end;
75 end;
76end;
77
78function Cover:update(dt)
79 if self:getIsActiveForInput() then
80 if self.coverAnimation ~= nil then
81 if InputBinding.hasEvent(InputBinding.TOGGLE_COVER) then
82 if self:getIsToggleCoverAllowed(not self.isCoverOpen) then
83 self:setCoverState(not self.isCoverOpen);
84 end;
85 end;
86 end;
87 end;
88end;
89
90function Cover:draw()
91 if self.isClient and self:getIsActiveForInput(true) then
92 if self.coverAnimation ~= nil and self:getIsToggleCoverAllowed(not self.isCoverOpen) then
93 if self.isCoverOpen then
94 g_currentMission:addHelpButtonText(g_i18n:getText("CLOSE_COVER"), InputBinding.TOGGLE_COVER);
95 else
96 g_currentMission:addHelpButtonText(g_i18n:getText("OPEN_COVER"), InputBinding.TOGGLE_COVER);
97 end;
98 end;
99 end;
100end;
101
102function Cover:getIsToggleCoverAllowed(isCoverOpen)
103 return true;
104end;
105
106function Cover:allowFillType(superFunc, fillType, allowEmptying)
107 if not self.isCoverOpen then
108 return false;
109 end;
110
111 return superFunc(self, fillType, allowEmptying);
112end
113
114function Cover:setCoverState(isOpen, noEventSend)
115 if self.coverAnimation ~= nil then
116 SetCoverStateEvent.sendEvent(self, isOpen, noEventSend);
117 self.isCoverOpen = isOpen;
118
119 if isOpen then
120 self:playAnimation(self.coverAnimation, -1, self:getAnimationTime(self.coverAnimation), true);
121 else
122 self:playAnimation(self.coverAnimation, 1, self:getAnimationTime(self.coverAnimation), true);
123 end;
124 end;
125end;
126
127function Cover:getAllowFillFromAir(superFunc)
128 if not self.isCoverOpen then
129 return false;
130 end
131 return superFunc(self);
132end
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