This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 525
/
CourseEditorEvent.lua
175 lines (153 loc) · 6.66 KB
/
CourseEditorEvent.lua
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 = {};
local CourseEditorEvent_mt = Class(CourseEditorEvent, Event);
InitEventClass(CourseEditorEvent, "CourseEditorEvent");
function CourseEditorEvent:emptyNew()
local self = Event:new(CourseEditorEvent_mt);
self.className = "CourseEditorEvent";
return self;
end
function CourseEditorEvent:new(vehicle,action,values)
self.vehicle = vehicle;
self.action = action;
self.values = values;
return self;
end
function CourseEditorEvent: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));
if self.action == "DragTo"
or self.action == "UndoDragTo"
then
self.values = {
wpSelected = streamReadInt32(streamId),
wpInfo = {
cx = streamReadFloat32(streamId),
cy = streamReadFloat32(streamId),
cz = streamReadFloat32(streamId)
}
};
elseif self.action == "UndoDelete" then
self.values = {
wpSelected = streamReadInt32(streamId),
wpInfo = {
cx = streamReadFloat32(streamId),
cy = streamReadFloat32(streamId),
cz = streamReadFloat32(streamId),
angle = streamReadFloat32(streamId),
speed = streamReadInt32(streamId)
}
};
elseif self.action == "SaveCourse"
or self.action == "IncreaseSpeed"
or self.action == "DecreaseSpeed"
or self.action == "UndoInsert"
or self.action == "DeleteSelected"
or self.action == "DeleteNext"
or self.action == "DeleteToStart"
or self.action == "DeleteToEnd"
then
self.values = streamReadInt32(streamId);
elseif self.action == "InsertNewWP" then
self.values = {
wpSelected = streamReadInt32(streamId),
midPNx = streamReadFloat32(streamId),
midPNy = streamReadFloat32(streamId),
midPNz = streamReadFloat32(streamId)
};
elseif self.action == "ChangeType" then
self.values = {
wpSelected = streamReadInt32(streamId),
typeIndex = streamReadInt8(streamId)
};
end
self:run(connection);
end
function CourseEditorEvent: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);
if self.action == "DragTo"
or self.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);
elseif self.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);
elseif self.action == "SaveCourse"
or self.action == "IncreaseSpeed"
or self.action == "DecreaseSpeed"
or self.action == "UndoInsert"
or self.action == "DeleteSelected"
or self.action == "DeleteNext"
or self.action == "DeleteToStart"
or self.action == "DeleteToEnd"
then
streamWriteInt32(streamId, self.values);
elseif self.action == "InsertNewWP" then
streamWriteInt32( streamId, self.values.wpSelected);
streamWriteFloat32(streamId, self.values.midPNx);
streamWriteFloat32(streamId, self.values.midPNy);
streamWriteFloat32(streamId, self.values.midPNz);
elseif self.action == "ChangeType" then
streamWriteInt32(streamId, self.values.wpSelected);
streamWriteInt8( streamId, self.values.typeIndex)
end
end
function CourseEditorEvent:run(connection)
courseplay.debugVehicle(courseplay.DBG_MULTIPLAYER,self.vehicle,"run Course Editor event")
if self.action == "SaveCourse" then
courseEditor:doSaveCourseAction(self.vehicle,self.values,true);
elseif self.action == "IncreaseSpeed" then
courseEditor:doIncreaseSpeedAction(self.vehicle,self.values,true);
elseif self.action == "IncreaseSpeed" then
courseEditor:doIncreaseSpeedAction(self.vehicle,self.values,true);
elseif self.action == "DecreaseSpeed" then
courseEditor:doDecreaseSpeedAction(self.vehicle,self.values,true);
elseif self.action == "DragTo" then
courseEditor:doDragToAction(self.vehicle, self.values.wpSelected, self.values.wpInfo, true);
elseif self.action == "UndoDragTo" then
courseEditor:doUndoDragToAction(self.vehicle, self.values.wpSelected, self.values.wpInfo, true);
elseif self.action == "UndoDelete" then
courseEditor:doUndoDeleteAction(self.vehicle, self.values.wpSelected, self.values.wpInfo, true);
elseif self.action == "UndoInsert" then
courseEditor:doUndoInsertAction(self.vehicle,self.values,true);
elseif self.action == "DeleteSelected" then
courseEditor:doDeleteSelectedAction(self.vehicle,self.values,true);
elseif self.action == "DeleteNext" then
courseEditor:doDeleteNextAction(self.vehicle,self.values,true);
elseif self.action == "DeleteToStart" then
courseEditor:doDeleteToStartAction(self.vehicle,self.values,true);
elseif self.action == "DeleteToEnd" then
courseEditor:doDeleteToEndAction(self.vehicle,self.values,true);
elseif self.action == "InsertNewWP" then
courseEditor:doInsertAction(self.vehicle,self.values.wpSelected,self.values.midPNx,self.values.midPNy,self.values.midPNz,true);
elseif self.action == "ChangeType" then
courseEditor:doChangeTypeAction(self.vehicle,self.values.wpSelected,self.values.typeIndex,true);
end
if not connection: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
function CourseEditorEvent.sendEvent(vehicle,action,values,noEventSend)
if noEventSend == nil or noEventSend == false then
if g_server ~= nil then
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