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 pathCourseEditorEvent.lua
More file actions
Latest commit
175 lines (153 loc) · 6.66 KB
/
Copy pathCourseEditorEvent.lua
File metadata and controls
175 lines (153 loc) · 6.66 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
CourseEditorEvent= {};
localCourseEditorEvent_mt=Class(CourseEditorEvent, Event);
InitEventClass(CourseEditorEvent, "CourseEditorEvent");
functionCourseEditorEvent:emptyNew()
localself=Event:new(CourseEditorEvent_mt);
self.className="CourseEditorEvent";
returnself;
end
functionCourseEditorEvent:new(vehicle,action,values)
self.vehicle=vehicle;
self.action=action;
self.values=values;
returnself;
end
functionCourseEditorEvent:readStream(streamId, connection)
self.vehicle=NetworkUtil.readNodeObject(streamId);
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,self.vehicle,"readStream Course Editor")
self.action=streamReadString(streamId);
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,self.vehicle,'readStream Course Editor: Recieving %s event', tostring(self.action));
ifself.action=="DragTo"
orself.action=="UndoDragTo"
then
self.values= {
wpSelected=streamReadInt32(streamId),
wpInfo= {
cx=streamReadFloat32(streamId),
cy=streamReadFloat32(streamId),
cz=streamReadFloat32(streamId)
}
};
elseifself.action=="UndoDelete" then
self.values= {
wpSelected=streamReadInt32(streamId),
wpInfo= {
cx=streamReadFloat32(streamId),
cy=streamReadFloat32(streamId),
cz=streamReadFloat32(streamId),
angle=streamReadFloat32(streamId),
speed=streamReadInt32(streamId)
}
};
elseifself.action=="SaveCourse"
orself.action=="IncreaseSpeed"
orself.action=="DecreaseSpeed"
orself.action=="UndoInsert"
orself.action=="DeleteSelected"
orself.action=="DeleteNext"
orself.action=="DeleteToStart"
orself.action=="DeleteToEnd"
then
self.values=streamReadInt32(streamId);
elseifself.action=="InsertNewWP" then
self.values= {
wpSelected=streamReadInt32(streamId),
midPNx=streamReadFloat32(streamId),
midPNy=streamReadFloat32(streamId),
midPNz=streamReadFloat32(streamId)
};
elseifself.action=="ChangeType" then
self.values= {
wpSelected=streamReadInt32(streamId),
typeIndex=streamReadInt8(streamId)
};
end
self:run(connection);
end
functionCourseEditorEvent:writeStream(streamId, connection)
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,self.vehicle,'writeStream Course Editor: Sending %s event', tostring(self.action));
NetworkUtil.writeNodeObject(streamId, self.vehicle);
streamWriteString(streamId, self.action);
ifself.action=="DragTo"
orself.action=="UndoDragTo"
then
streamWriteInt32( streamId, self.values.wpSelected);
streamWriteFloat32(streamId, self.values.wpInfo.cx);
streamWriteFloat32(streamId, self.values.wpInfo.cy);
streamWriteFloat32(streamId, self.values.wpInfo.cz);
elseifself.action=="UndoDelete" then
streamWriteInt32( streamId, self.values.wpSelected);
streamWriteFloat32(streamId, self.values.wpInfo.cx);
streamWriteFloat32(streamId, self.values.wpInfo.cy);
streamWriteFloat32(streamId, self.values.wpInfo.cz);
streamWriteFloat32(streamId, self.values.wpInfo.angle);
streamWriteInt32( streamId, self.values.wpInfo.speed);
elseifself.action=="SaveCourse"
orself.action=="IncreaseSpeed"
orself.action=="DecreaseSpeed"
orself.action=="UndoInsert"
orself.action=="DeleteSelected"
orself.action=="DeleteNext"
orself.action=="DeleteToStart"
orself.action=="DeleteToEnd"
then
streamWriteInt32(streamId, self.values);
elseifself.action=="InsertNewWP" then
streamWriteInt32( streamId, self.values.wpSelected);
streamWriteFloat32(streamId, self.values.midPNx);
streamWriteFloat32(streamId, self.values.midPNy);
streamWriteFloat32(streamId, self.values.midPNz);
elseifself.action=="ChangeType" then
streamWriteInt32(streamId, self.values.wpSelected);
streamWriteInt8( streamId, self.values.typeIndex)
end
end
functionCourseEditorEvent:run(connection)
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,self.vehicle,"run Course Editor event")
ifself.action=="SaveCourse" then
courseEditor:doSaveCourseAction(self.vehicle,self.values,true);
elseifself.action=="IncreaseSpeed" then
courseEditor:doIncreaseSpeedAction(self.vehicle,self.values,true);
elseifself.action=="IncreaseSpeed" then
courseEditor:doIncreaseSpeedAction(self.vehicle,self.values,true);
elseifself.action=="DecreaseSpeed" then
courseEditor:doDecreaseSpeedAction(self.vehicle,self.values,true);
elseifself.action=="DragTo" then
courseEditor:doDragToAction(self.vehicle, self.values.wpSelected, self.values.wpInfo, true);
elseifself.action=="UndoDragTo" then
courseEditor:doUndoDragToAction(self.vehicle, self.values.wpSelected, self.values.wpInfo, true);
elseifself.action=="UndoDelete" then
courseEditor:doUndoDeleteAction(self.vehicle, self.values.wpSelected, self.values.wpInfo, true);
elseifself.action=="UndoInsert" then
courseEditor:doUndoInsertAction(self.vehicle,self.values,true);
elseifself.action=="DeleteSelected" then
courseEditor:doDeleteSelectedAction(self.vehicle,self.values,true);
elseifself.action=="DeleteNext" then
courseEditor:doDeleteNextAction(self.vehicle,self.values,true);
elseifself.action=="DeleteToStart" then
courseEditor:doDeleteToStartAction(self.vehicle,self.values,true);
elseifself.action=="DeleteToEnd" then
courseEditor:doDeleteToEndAction(self.vehicle,self.values,true);
elseifself.action=="InsertNewWP" then
courseEditor:doInsertAction(self.vehicle,self.values.wpSelected,self.values.midPNx,self.values.midPNy,self.values.midPNz,true);
elseifself.action=="ChangeType" then
courseEditor:doChangeTypeAction(self.vehicle,self.values.wpSelected,self.values.typeIndex,true);
end
ifnotconnection:getIsServer() then
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,self.vehicle,"broadcast Course Editor event feedback");
g_server:broadcastEvent(CourseEditorEvent:new(self.vehicle,self.action,self.values), nil, connection, self.vehicle);
end;
end
functionCourseEditorEvent.sendEvent(vehicle,action,values,noEventSend)
ifnoEventSend==nilornoEventSend==falsethen
ifg_server~=nilthen
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,vehicle,"broadcast Course Editor event");
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,vehicle,'action=%s, values=%s', tostring(action), tostring(values));
g_server:broadcastEvent(CourseEditorEvent:new(vehicle,action,values), nil, nil, vehicle);
else
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,vehicle,"send Course Editor event");
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,vehicle,'action=%s, values=%s', tostring(action), tostring(values));
g_client:getServerConnection():sendEvent(CourseEditorEvent:new(vehicle,action,values));
end;
end
end