Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on May 23, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathStateModule.lua
More file actions
Latest commit
70 lines (59 loc) · 1.78 KB
/
Copy pathStateModule.lua
File metadata and controls
70 lines (59 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
StateModule=CpObject()
functionStateModule:init(debugClass,debugFunc, vehicle)
self.states= {}
self.debugClass=debugClass
self.debugFunc=debugFunc
self.vehicle=vehicle
end
--- Aggregation of states from this and all descendant classes
functionStateModule:initStates(states)
forkey, stateinpairs(states) do
self.states[key] = {name=tostring(key), properties=state}
end
end
functionStateModule:debug(lastState,newState)
ifself.vehiclethen
self.debugClass[self.debugFunc](self.debugClass,self.vehicle,"lastState: %s => newState: %s",lastState.name,newState.name)
else
self.debugClass[self.debugFunc](self.debugClass,"lastState: %s => newState: %s",lastState.name,newState.name)
end
end
functionStateModule:changeState(newStateName)
localnewState=self.states[newStateName]
ifself.state~=newStatethen
self:debug(self.state,newState)
self.state=newState
end
end
functionStateModule:get()
returnself.state
end
functionStateModule:getName()
returnself.state.name
end
functionStateModule:is(state)
returnself.state==self.states[state]
end
functionStateModule:onReadStream(streamId)
localnameState=streamReadString(streamId)
self.state=self.states[nameState]
end
functionStateModule:onWriteStream(streamId)
streamWriteString(streamId,self.state.name)
self.lastStateSent=self.state
end
functionStateModule:onWriteUpdateStream(streamId)
ifself.lastStateSent==nilorself.lastStateSent~=self.statethen
streamWriteBool(streamId,true)
streamWriteString(streamId,self.state.name)
self.lastStateSent=self.state
else
streamWriteBool(streamId,false)
end
end
functionStateModule:onReadUpdateStream(streamId)
ifstreamReadBool(streamId) then
localnameState=streamReadString(streamId)
self.state=self.states[nameState]
end
end