Browse Source

adding recorder scripts

shuvit 6 years ago
parent
commit
b044908322
2 changed files with 1184 additions and 0 deletions
  1. 610
    0
      Record.py
  2. 574
    0
      SortData.py

+ 610
- 0
Record.py View File

@@ -0,0 +1,610 @@
1
+#record
2
+from bge import logic
3
+from mathutils import Vector
4
+from SortData import *
5
+
6
+cont = logic.getCurrentController()
7
+own = cont.owner
8
+scene = logic.getCurrentScene()
9
+cube = scene.objects["control_cube.002"]
10
+#obj = scene.objects["control_cube.002"]
11
+#sound_empty = scene.objects['replay_sound_empty']
12
+path = logic.expandPath(own["filePath"])
13
+
14
+PAF = 0
15
+DAF = 0
16
+
17
+deck = scene.objects["deck"]
18
+trucks = scene.objects["trucks"]
19
+
20
+throw_deck_empty = scene.objects["throw_deck_empty"]
21
+wheel1 = scene.objects["rollen.000"]
22
+wheel2 = scene.objects["rollen.001"]
23
+wheel3 = scene.objects["rollen.002"]
24
+wheel4 = scene.objects["rollen.003"]
25
+
26
+
27
+deckact = deck.actuators["Visibility"]
28
+trucksact = trucks.actuators["Visibility"]
29
+wheel1act = wheel1.actuators["Visibility"]
30
+wheel2act = wheel2.actuators["Visibility"]
31
+wheel3act = wheel3.actuators["Visibility"]
32
+wheel4act = wheel4.actuators["Visibility"]
33
+
34
+class getData:
35
+
36
+
37
+
38
+    def savePosition(obj, cut):
39
+        
40
+        position = [Vector(obj.worldPosition)[0],
41
+            Vector(obj.worldPosition)[1],
42
+            Vector(obj.worldPosition)[2]]
43
+        position = str(position).strip("[]")
44
+        position = position.replace(", ",",")
45
+       
46
+        writeData.addPosition(obj, position, cut)
47
+     
48
+    def saveOrientation(obj, cut):
49
+            
50
+        orientation = [Vector(obj.localOrientation.to_euler())[0],
51
+            Vector(obj.localOrientation.to_euler())[1],
52
+            Vector(obj.localOrientation.to_euler())[2]]
53
+        orientation = str(orientation).strip("[]")
54
+        orientation = orientation.replace(", ",",")
55
+                
56
+        writeData.addOrientation(obj, orientation, cut)
57
+                    
58
+    def saveScale(obj, cut):
59
+        
60
+        scale = [Vector(obj.localScale)[0],
61
+            Vector(obj.localScale)[1],
62
+            Vector(obj.localScale)[2]]
63
+        scale = str(scale).strip("[]")
64
+        scale = scale.replace(", ",",")
65
+         
66
+        writeData.addScale(obj, scale, cut)
67
+        
68
+    def saveColor(obj, cut):
69
+        
70
+        color = [Vector(obj.color)[0],
71
+            Vector(obj.color)[1],
72
+            Vector(obj.color)[2],
73
+            Vector(obj.color)[3]]
74
+        color = str(color).strip("[]")
75
+        color = color.replace(", ",",")
76
+        
77
+        writeData.addColor(obj, color, cut)
78
+        
79
+    def saveState(obj, cut):
80
+        
81
+        state = str(obj.state)
82
+        writeData.addState(obj, state, cut)
83
+        
84
+    def saveVisibility(obj, cut):
85
+        
86
+        visible = obj.visible
87
+        
88
+        if visible:
89
+            visible = 1
90
+        else:
91
+            visible = 0
92
+            
93
+        writeData.addVisibility(obj, str(visible), cut)
94
+    
95
+    def saveSkaterAnim(obj, cut):
96
+        import bge
97
+        scene = bge.logic.getCurrentScene()
98
+        skater = scene.objects["Char4"]
99
+        deck = scene.objects["deck"]
100
+        trucks = scene.objects["trucks"]
101
+        playing_layer = 0
102
+        for x in range(3020):
103
+            l1 = skater.isPlayingAction(x)
104
+            if l1 == True:
105
+                playing_layer = x
106
+                #print(x)
107
+        playing_action = skater.getActionName(playing_layer)
108
+        playing_action_frame = skater.getActionFrame(playing_layer)
109
+        PAF = playing_action_frame
110
+        own['PAF'] = PAF
111
+       #print(playing_action, playing_action_frame)        
112
+        writeData.addSkaterAnim(obj, str(playing_action), cut)
113
+        
114
+    def saveSkaterAnimF(obj, cut):
115
+        PAF = own['PAF']
116
+        writeData.addSkaterAnimF(obj, str(PAF), cut)   
117
+        
118
+    def saveDeckAnim(obj, cut):
119
+        import bge
120
+        scene = bge.logic.getCurrentScene()
121
+        skater = scene.objects["Char4"]
122
+        deck = scene.objects["deck"]
123
+        trucks = scene.objects["trucks"]
124
+        wheel1 = scene.objects["rollen.000"]
125
+        wheel2 = scene.objects["rollen.001"]
126
+        wheel3 = scene.objects["rollen.002"]
127
+        wheel4 = scene.objects["rollen.003"]        
128
+        playing_layer = 0
129
+        for x in range(3020):
130
+            l1 = deck.isPlayingAction(x)
131
+            if l1 == True:
132
+                playing_layer = x
133
+                #print(x)
134
+        playing_action = deck.getActionName(playing_layer)
135
+        playing_action_frame = deck.getActionFrame(playing_layer)
136
+        DAF = playing_action_frame
137
+        own['DAF'] = DAF
138
+       #print(playing_action, playing_action_frame)        
139
+        writeData.addDeckAnim(obj, str(playing_action), cut)
140
+        
141
+    def saveDeckAnimF(obj, cut):
142
+        DAF = own['DAF']
143
+        writeData.addDeckAnimF(obj, str(DAF), cut)
144
+
145
+    def saveSrollVol(obj, cut):
146
+        num = cube['sroll_vol']
147
+        writeData.addSrollVol(obj, str(num), cut) 
148
+    def saveSrollPitch(obj, cut):
149
+        num = cube['sroll_pitch']
150
+        writeData.addSrollPitch(obj, str(num), cut) 
151
+    
152
+    def saveSgrind_cementVol(obj, cut):
153
+        num = cube['grindcement_vol']
154
+        writeData.addSgrind_cementVol(obj, str(num), cut) 
155
+    def saveSgrind_cementPitch(obj, cut):
156
+        num = cube['grindcement_pitch']
157
+        writeData.addSgrind_cementPitch(obj, str(num), cut) 
158
+    def saveSgrind_railVol(obj, cut):
159
+        num = cube['grindrail_vol']
160
+        writeData.addSgrind_railVol(obj, str(num), cut) 
161
+    def saveSgrind_railPitch(obj, cut):
162
+        num = cube['grindrail_pitch']
163
+        writeData.addSgrind_railPitch(obj, str(num), cut)
164
+    def saveSpopsound(obj, cut):
165
+        num = cube['pop_sound']
166
+        writeData.addSpopsound(obj, str(num), cut) 
167
+    def saveSlandsound(obj, cut):
168
+        num = cube['land_sound']
169
+        writeData.addSlandsound(obj, str(num), cut) 
170
+    def saveSdeckvis(obj, cut):
171
+        num = cube['deckvis']
172
+        writeData.addSdeckvis(obj, str(num), cut)                                                                
173
+              
174
+def loadData():
175
+    
176
+    #Function for loading the data from
177
+    #the disk and setting it.
178
+    
179
+    objIndex = own["objIndex"]
180
+    own["valueIndex"] = objIndex + 1
181
+    valueIndex = own["valueIndex"]
182
+    playbackSpeed = own["playbackSpeed"]
183
+    loadedPosition = own["loadedPosition"]
184
+    loadedOrientation = own["loadedOrientation"]
185
+    loadedScale = own["loadedScale"]
186
+    loadedColor = own["loadedColor"]
187
+    loadedVisibility = own["loadedVisibility"]
188
+    loadedSkaterAnim = own["loadedSkaterAnim"]
189
+    loadedSkaterAnimf = own["loadedSkaterAnimF"]
190
+    loadedDeckAnim = own["loadedDeckAnim"]
191
+    loadedDeckAnimf = own["loadedDeckAnimF"]
192
+    loadedSrollVol = own["loadedSrollVol"]
193
+    loadedSrollPitch = own["loadedSrollPitch"]
194
+    loadedSgrind_cementlVol = own["loadedSgrind_cementVol"]
195
+    loadedSgrind_cementPitch = own["loadedSgrind_cementPitch"]
196
+    loadedSgrind_railVol = own["loadedSgrind_railVol"]
197
+    loadedSgrind_railPitch = own["loadedSgrind_railPitch"] 
198
+    loadedSpopsound = own["loadedSpopsound"]            
199
+    loadedSlandsound = own["loadedSlandsound"] 
200
+    loadedSdeckvis = own["loadedSdeckvis"]    
201
+    
202
+    skater = scene.objects["Char4"]
203
+    deck = scene.objects["deck"]
204
+    trucks = scene.objects["trucks"]
205
+    
206
+    num = 1
207
+    obj = scene.objects['control_cube.002']
208
+    if num == 1:    
209
+    #for obj in scene.objects:        
210
+        if not "recorder" in obj:
211
+            obj.state = 100
212
+            obj.suspendDynamics()
213
+                     
214
+    readData.loadAll()    #Load the file!!!
215
+    
216
+    #-----Position-----#
217
+    own["lengthPos"] = readData.getLengthPos()
218
+    lengthPos = own["lengthPos"] 
219
+    
220
+    if lengthPos:
221
+        
222
+        if objIndex > lengthPos-1:
223
+            own["objIndex"] = 0
224
+        if objIndex < 0:
225
+            own["objIndex"] = lengthPos-2
226
+
227
+        name, position = readData.returnPosition(objIndex, valueIndex)
228
+        
229
+        if name in scene.objects:
230
+            try:
231
+                scene.objects[name].worldPosition = position
232
+                scene.objects['replay_sound_empty'].worldPosition = position
233
+                #print("replay_sound_empty changing position")
234
+            except:
235
+                pass
236
+    #-----Orientation-----#
237
+    own["lengthOri"] = readData.getLengthOri()   
238
+    lengthOri = own["lengthOri"]
239
+    
240
+    if lengthPos:
241
+  
242
+        if valueIndex > lengthOri-1:
243
+            own["valueIndex"] = 0
244
+        if objIndex < 0:
245
+            own["objIndex"] = lengthOri-2
246
+
247
+        name, orientation = readData.returnOrientation(objIndex, valueIndex)
248
+        
249
+        if name in scene.objects:
250
+            oXYZ = scene.objects[name].localOrientation.to_euler()
251
+
252
+            oXYZ[0] = float(orientation[0])
253
+            oXYZ[1] = float(orientation[1])
254
+            oXYZ[2] = float(orientation[2])
255
+            
256
+            try:
257
+                scene.objects[name].localOrientation = oXYZ.to_matrix()
258
+            except:
259
+                pass
260
+    #-----Scale-----#
261
+    own["lengthSca"] = readData.getLengthSca()
262
+    lengthSca = own["lengthSca"]
263
+    
264
+    if lengthSca:
265
+    
266
+        if valueIndex > lengthSca-1:
267
+            own["valueIndex"] = 0
268
+        if objIndex < 0:
269
+            own["objIndex"] = lengthSca-2
270
+       
271
+        name, scale = readData.returnScale(objIndex, valueIndex)
272
+        
273
+        if name in scene.objects:
274
+            try:
275
+                scene.objects[name].localScale = scale
276
+            except:
277
+                pass
278
+    #-----Color-----#
279
+    own["lengthCol"] = readData.getLengthCol()   
280
+    lengthCol = own["lengthCol"]
281
+    
282
+    if lengthCol:
283
+
284
+        if valueIndex > lengthCol-1:
285
+            own["valueIndex"] = 0
286
+        if objIndex < 0:
287
+            own["objIndex"] = lengthCol-2
288
+
289
+        name, color = readData.returnColor(objIndex, valueIndex)
290
+        
291
+        if name in scene.objects:
292
+            try:
293
+                scene.objects[name].color = color
294
+            except:
295
+                pass
296
+    #-----Visibility-----#
297
+    own["lengthVis"] = readData.getLengthVis()
298
+    lengthVis = own["lengthVis"]
299
+    
300
+    if lengthVis:
301
+
302
+        if valueIndex > lengthVis-1:
303
+            own["valueIndex"] = 0
304
+        if objIndex < 0:
305
+            own["objIndex"] = lengthVis-2
306
+
307
+        name, visible = readData.returnVisibility(objIndex, valueIndex)
308
+        
309
+        if name in scene.objects:
310
+            try:
311
+                scene.objects[name].visible = int(visible)
312
+            except:
313
+                pass
314
+    #-----Skater Animation Name-----#
315
+    own["lengthSkaterAnim"] = readData.getLengthSkaterAnim()
316
+    lengthSkaterAnim = own["lengthSkaterAnim"]
317
+    #print("lengthskateranim", lengthSkaterAnim)
318
+    if lengthSkaterAnim:
319
+
320
+        if valueIndex > lengthSkaterAnim-1:
321
+            own["valueIndex"] = 0
322
+        if objIndex < 0:
323
+            own["objIndex"] = lengthSkaterAnim-2
324
+
325
+        name, skateranim = readData.returnSkaterAnim(objIndex, valueIndex)
326
+        name, PAF = readData.returnSkaterAnimF(objIndex, valueIndex)
327
+        #print(PAF)
328
+        PAF = float(PAF)
329
+        if name in scene.objects:
330
+            #print("name in")
331
+            try:
332
+                skater.stopAction(0)
333
+                skater.stopAction(1)
334
+                skater.stopAction(2)
335
+                skater.stopAction(3)
336
+                skater.stopAction(9999)
337
+                if skater != '':
338
+                    skater.playAction(skateranim, PAF,PAF, layer=9999, play_mode=1, speed=1)
339
+                #print("Playing: ", skateranim, PAF)
340
+            except:
341
+                print("something is wrong")
342
+                #pass  
343
+                
344
+                
345
+    #-----Deck Animation Name-----#
346
+    own["lengthDeckAnim"] = readData.getLengthDeckAnim()
347
+    lengthDeckAnim = own["lengthDeckAnim"]
348
+    #print("lengthDeckanim", lengthDeckAnim)
349
+    if lengthDeckAnim:
350
+
351
+        if valueIndex > lengthDeckAnim-1:
352
+            own["valueIndex"] = 0
353
+        if objIndex < 0:
354
+            own["objIndex"] = lengthDeckAnim-2
355
+
356
+        name, deckanim = readData.returnDeckAnim(objIndex, valueIndex)
357
+        name, DAF = readData.returnDeckAnimF(objIndex, valueIndex)
358
+        #print(DAF)
359
+        DAF = float(DAF)
360
+        if name in scene.objects:
361
+            #print("name in")
362
+            try:
363
+                deck.stopAction(0)
364
+                deck.stopAction(1)
365
+                deck.stopAction(2)
366
+                deck.stopAction(3)
367
+                deck.stopAction(9999)
368
+                #print(deckanim)
369
+                if deckanim != '':
370
+                    deck.playAction(deckanim, DAF,DAF, layer=9999, play_mode=1, speed=1)
371
+                    trucks.playAction(deckanim, DAF,DAF, layer=9999, play_mode=1, speed=1)
372
+                #print("Playing: ", deckanim, PAF)
373
+            except:
374
+                print("deck something is wrong")
375
+                #pass  
376
+
377
+#
378
+    #-----sroll-----#
379
+    own["lengthSrollVol"] = readData.getLengthSrollVol()
380
+    lengthSrollVol = own["lengthSrollVol"]
381
+    if lengthSrollVol:
382
+        if valueIndex > lengthSrollVol-1:
383
+            own["valueIndex"] = 0
384
+        if objIndex < 0:
385
+            own["objIndex"] = lengthSrollVol-2
386
+        name, srollVol = readData.returnSrollVol(objIndex, valueIndex)
387
+        name, srollPitch = readData.returnSrollPitch(objIndex, valueIndex)    
388
+        if name in scene.objects:
389
+            try:
390
+                cube = scene.objects["control_cube.002"]
391
+                srollVol = round(srollVol, 2)
392
+                act = cube.actuators["sroll"]
393
+                if srollVol < .12:
394
+                    act.volume = srollVol
395
+                    act.pitch = srollPitch
396
+                act.startSound()
397
+            except:
398
+                pass
399
+###            
400
+#
401
+    #-----grind cement-----#
402
+    own["lengthSgrind_cementVol"] = readData.getLengthSgrind_cementVol()
403
+    lengthSgrind_cementVol = own["lengthSgrind_cementVol"]
404
+    if lengthSgrind_cementVol:
405
+        if valueIndex > lengthSgrind_cementVol-1:
406
+            own["valueIndex"] = 0
407
+        if objIndex < 0:
408
+            own["objIndex"] = lengthSgrind_cementVol-2
409
+        name, sgrind_cementVol = readData.returnSgrind_cementVol(objIndex, valueIndex)
410
+        name, sgrind_cementPitch = readData.returnSgrind_cementPitch(objIndex, valueIndex)    
411
+        if name in scene.objects:
412
+            try:
413
+                cube = scene.objects["control_cube.002"]
414
+                sgrind_cementVol = round(sgrind_cementVol, 2)
415
+                act = cube.actuators["grind_cement"]
416
+                if sgrind_cementVol < .2:
417
+                    act.volume = sgrind_cementVol
418
+                    act.pitch = sgrind_cementPitch
419
+                act.startSound()
420
+                
421
+            except:
422
+                pass
423
+###    
424
+#
425
+    #-----grind rail-----#
426
+    own["lengthSgrind_railVol"] = readData.getLengthSgrind_railVol()
427
+    lengthSgrind_railVol = own["lengthSgrind_railVol"]
428
+    if lengthSgrind_railVol:
429
+        if valueIndex > lengthSgrind_railVol-1:
430
+            own["valueIndex"] = 0
431
+        if objIndex < 0:
432
+            own["objIndex"] = lengthSgrind_railVol-2
433
+        name, sgrind_railVol = readData.returnSgrind_railVol(objIndex, valueIndex)
434
+        name, sgrind_railPitch = readData.returnSgrind_railPitch(objIndex, valueIndex)    
435
+        if name in scene.objects:
436
+            try:
437
+                cube = scene.objects["control_cube.002"]
438
+                sgrind_railVol = round(sgrind_railVol, 2)
439
+                act = cube.actuators["grind_rail"]
440
+                if sgrind_railVol < .2:
441
+                    act.volume = sgrind_railVol
442
+                    act.pitch = sgrind_railPitch
443
+                act.startSound()
444
+                #print("grindsound = ", sgrind_railVol, sgrind_railPitch)
445
+            except:
446
+                pass
447
+###  
448
+#
449
+    #-----pop sound-----#
450
+    own["lengthSpopsound"] = readData.getLengthSpopsound()
451
+    lengthSpopsound = own["lengthSpopsound"]
452
+    if lengthSpopsound:
453
+        if valueIndex > lengthSpopsound-1:
454
+            own["valueIndex"] = 0
455
+        if objIndex < 0:
456
+            own["objIndex"] = lengthSpopsound-2
457
+        name, spopsound = readData.returnSpopsound(objIndex, valueIndex)   
458
+        if name in scene.objects:
459
+            try:
460
+                #cube = scene.objects[sound_empty]
461
+                spopsound = round(spopsound, 2)
462
+                act = cube.actuators["pop"]
463
+                if spopsound == 1:
464
+                    act.startSound()
465
+                #print("grindsound = ", spopsound, sgrind_railPitch)
466
+            except:
467
+                print("sound passed")
468
+                pass
469
+###
470
+#
471
+    #-----land sound-----#
472
+    own["lengthSlandsound"] = readData.getLengthSlandsound()
473
+    lengthSlandsound = own["lengthSlandsound"]
474
+    if lengthSlandsound:
475
+        if valueIndex > lengthSlandsound-1:
476
+            own["valueIndex"] = 0
477
+        if objIndex < 0:
478
+            own["objIndex"] = lengthSlandsound-2
479
+        name, slandsound = readData.returnSlandsound(objIndex, valueIndex)   
480
+        if name in scene.objects:
481
+            try:
482
+                cube = scene.objects["control_cube.002"]
483
+                slandsound = round(slandsound, 2)
484
+                act = cube.actuators["land"]
485
+                if slandsound == 1:
486
+                    act.startSound()
487
+                #print("grindsound = ", slandsound, sgrind_railPitch)
488
+            except:
489
+                pass
490
+###  
491
+###
492
+#
493
+    #-----land sound-----#
494
+    own["lengthSdeckvis"] = readData.getLengthSdeckvis()
495
+    lengthSdeckvis = own["lengthSdeckvis"]
496
+    if lengthSdeckvis:
497
+        if valueIndex > lengthSdeckvis-1:
498
+            own["valueIndex"] = 0
499
+        if objIndex < 0:
500
+            own["objIndex"] = lengthSdeckvis-2
501
+        name, sdeckvis = readData.returnSdeckvis(objIndex, valueIndex)   
502
+        
503
+        
504
+        if name in scene.objects:
505
+            try:
506
+                cube = scene.objects["control_cube.002"]
507
+                #slandsound = round(slandsound, 2)
508
+                if sdeckvis == 1:
509
+                    print('setting deck visible')
510
+                    #wheel1.visible = True
511
+                    #wheel2.visible = True
512
+                    #wheel3.visible = True
513
+                    #wheel4.visible = True 
514
+                    #deck.visible = True
515
+                    #trucks.setVisible(True, True)
516
+                    
517
+                    
518
+                    deckact.visibility = True
519
+                    trucksact.visibility = True
520
+                    wheel1act.visibility = True
521
+                    wheel2act.visibility = True
522
+                    wheel3act.visibility = True
523
+                    wheel4act.visibility = True   
524
+                    cont.activate(deck.actuators['Visibility'])
525
+                    cont.activate(trucks.actuators['Visibility'])
526
+                    cont.activate(wheel1.actuators['Visibility'])
527
+                    cont.activate(wheel2.actuators['Visibility'])
528
+                    cont.activate(wheel3.actuators['Visibility'])
529
+                    cont.activate(wheel4.actuators['Visibility'])                     
530
+                               
531
+                else:
532
+                    print('setting deck invisible')
533
+                    #wheel1.visible = False
534
+                    #wheel2.visible = False
535
+                    #wheel3.visible = False
536
+                    #wheel4.visible = False
537
+                    #deck.visible = False
538
+                    #trucks.setVisible(False, False)
539
+
540
+                    deckact.visibility = False
541
+                    trucksact.visibility = False
542
+                    wheel1act.visibility = False
543
+                    wheel2act.visibility = False
544
+                    wheel3act.visibility = False
545
+                    wheel4act.visibility = False   
546
+                    cont.activate(deck.actuators['Visibility'])
547
+                    cont.activate(trucks.actuators['Visibility'])
548
+                    cont.activate(wheel1.actuators['Visibility'])
549
+                    cont.activate(wheel2.actuators['Visibility'])
550
+                    cont.activate(wheel3.actuators['Visibility'])
551
+                    cont.activate(wheel4.actuators['Visibility'])                     
552
+
553
+
554
+
555
+            except:
556
+                pass
557
+##    
558
+
559
+                                            
560
+                       
561
+def main(recording_cutoff, cc):
562
+    num = 1
563
+    obj = scene.objects["control_cube.002"]
564
+    if num == 1:
565
+        
566
+    #for obj in scene.objects:
567
+        if "record_position" in obj:
568
+            getData.savePosition(obj, recording_cutoff)
569
+        if "record_orientation" in obj:
570
+            getData.saveOrientation(obj, recording_cutoff)
571
+        if "record_scale" in obj:
572
+            getData.saveScale(obj, recording_cutoff)
573
+        if "record_color" in obj:
574
+            getData.saveColor(obj, recording_cutoff)
575
+        if "record_state" in obj:
576
+            getData.saveState(obj, recording_cutoff)
577
+        if "record_visibility" in obj:
578
+            getData.saveVisibility(obj, recording_cutoff)
579
+        if "record_skateranim" in obj:
580
+            getData.saveSkaterAnim(obj, recording_cutoff)
581
+        if "record_skateranimf" in obj:
582
+            getData.saveSkaterAnimF(obj, recording_cutoff) 
583
+        if "record_deckanim" in obj:
584
+            getData.saveDeckAnim(obj, recording_cutoff)
585
+        if "record_deckanimf" in obj:
586
+            getData.saveDeckAnimF(obj, recording_cutoff)    
587
+        #if "record_sroll_vol" in obj:
588
+        getData.saveSrollVol(obj, recording_cutoff)
589
+        #if "record_sroll_pitch" in obj:
590
+        getData.saveSrollPitch(obj, recording_cutoff)
591
+        getData.saveSgrind_cementVol(obj, recording_cutoff)
592
+        getData.saveSgrind_cementPitch(obj, recording_cutoff)
593
+        getData.saveSgrind_railVol(obj, recording_cutoff)
594
+        getData.saveSgrind_railPitch(obj, recording_cutoff)
595
+        getData.saveSpopsound(obj, recording_cutoff)            
596
+        getData.saveSlandsound(obj, recording_cutoff) 
597
+        getData.saveSdeckvis(obj, recording_cutoff)                               
598
+            
599
+         
600
+def breakOut():
601
+    num = 1
602
+    obj = scene.objects["control_cube.002"]
603
+    if num == 1:
604
+    #for obj in scene.objects:
605
+        obj.restoreDynamics()
606
+        try:
607
+            name, state = readData.returnState(own["objIndex"], own["valueIndex"])
608
+            obj.state = state
609
+        except:
610
+            pass

+ 574
- 0
SortData.py View File

@@ -0,0 +1,574 @@
1
+#sort
2
+
3
+from bge import logic
4
+
5
+printDebug = True    #Set to True to see some basic debug info
6
+
7
+cont = logic.getCurrentController()
8
+own = cont.owner
9
+
10
+gameName = "shuvit"    #Set this to the name of your game!
11
+
12
+path = logic.expandPath(own["filePath"])
13
+
14
+positionList = []
15
+orientationList = []
16
+scaleList = []
17
+colorList = []
18
+stateList = []
19
+visibilityList = []
20
+skaterAnimList = []
21
+skaterAnimFList = []
22
+deckAnimList = []
23
+deckAnimFList = []
24
+srollVolList = []
25
+srollPitchList = []
26
+sgrind_cementVolList = []
27
+sgrind_cementPitchList = []
28
+sgrind_railVolList = []
29
+sgrind_railPitchList = []
30
+spopsoundList = []
31
+slandsoundList = []
32
+sdeckvisList = []
33
+
34
+allDataList = []
35
+allDataPath = path+gameName+" replay.dat"
36
+
37
+class writeData:
38
+
39
+    def addPosition(obj, pos, cut):
40
+        global positionList
41
+        positionList.append(" "+str(obj))
42
+        positionList.append(pos)
43
+        
44
+        if len(positionList) >= cut and cut > 0:
45
+            del positionList[0]
46
+            del positionList[0]
47
+        
48
+    def addOrientation(obj, ori, cut):
49
+        global orientationData
50
+        orientationList.append(" "+str(obj))
51
+        orientationList.append(ori)
52
+        
53
+        if len(orientationList) >= cut and cut > 0:
54
+            del orientationList[0]
55
+            del orientationList[0]
56
+        
57
+    def addScale(obj, sca, cut):
58
+        global scaleData
59
+        scaleList.append(" "+str(obj))
60
+        scaleList.append(sca)
61
+        
62
+        if len(scaleList) >= cut and cut > 0:
63
+            del scaleList[0]
64
+            del scaleList[0]
65
+        
66
+    def addColor(obj, col, cut):
67
+        global colorData
68
+        colorList.append(" "+str(obj))
69
+        colorList.append(col)
70
+        
71
+        if len(colorList) >= cut and cut > 0:
72
+            del colorList[0]
73
+            del colorList[0]
74
+        
75
+    def addState(obj, sta, cut):
76
+        global stateData
77
+        stateList.append(" "+str(obj))
78
+        stateList.append(sta)
79
+        
80
+        if len(stateList) >= cut and cut > 0:
81
+            del stateList[0]
82
+            del stateList[0]
83
+            
84
+    def addVisibility(obj, vis, cut):
85
+        global visibilityData
86
+        visibilityList.append(" "+str(obj))
87
+        visibilityList.append(vis)
88
+        if len(visibilityList) >= cut and cut > 0:
89
+            del visibilityList[0]
90
+            del visibilityList[0]
91
+    def addSkaterAnim(obj, anim, cut):
92
+        global skaterAnimData
93
+        skaterAnimList.append(" "+str(obj))
94
+        skaterAnimList.append(anim)
95
+        
96
+        if len(skaterAnimList) >= cut and cut > 0:
97
+            del skaterAnimList[0]
98
+            del skaterAnimList[0] 
99
+    def addSkaterAnimF(obj, animf, cut):
100
+        global skaterAnimFData
101
+        skaterAnimFList.append(" "+str(obj))
102
+        skaterAnimFList.append(animf)
103
+        
104
+        if len(skaterAnimFList) >= cut and cut > 0:
105
+            del skaterAnimFList[0]
106
+            del skaterAnimFList[0]  
107
+    def addDeckAnim(obj, anim, cut):
108
+        global deckAnimData
109
+        deckAnimList.append(" "+str(obj))
110
+        deckAnimList.append(anim)
111
+        
112
+        if len(deckAnimList) >= cut and cut > 0:
113
+            del deckAnimList[0]
114
+            del deckAnimList[0] 
115
+    def addDeckAnimF(obj, animf, cut):
116
+        global deckAnimFData
117
+        deckAnimFList.append(" "+str(obj))
118
+        deckAnimFList.append(animf)
119
+        
120
+        if len(deckAnimFList) >= cut and cut > 0:
121
+            del deckAnimFList[0]
122
+            del deckAnimFList[0]
123
+###             
124
+    def addSrollVol(obj, srollVol, cut):
125
+        global srollVolData
126
+        srollVolList.append(" "+str(obj))
127
+        srollVolList.append(srollVol)
128
+        if len(srollVolList) >= cut and cut > 0:
129
+            del srollVolList[0]
130
+            del srollVolList[0]
131
+    def addSrollPitch(obj, srollPitch, cut):
132
+        global srollPitchData
133
+        srollPitchList.append(" "+str(obj))
134
+        srollPitchList.append(srollPitch)
135
+        if len(srollPitchList) >= cut and cut > 0:
136
+            del srollPitchList[0]
137
+            del srollPitchList[0] 
138
+###             
139
+    def addSgrind_cementVol(obj, sgrind_cementVol, cut):
140
+        global sgrind_cementVolData
141
+        sgrind_cementVolList.append(" "+str(obj))
142
+        sgrind_cementVolList.append(sgrind_cementVol)
143
+        if len(sgrind_cementVolList) >= cut and cut > 0:
144
+            del sgrind_cementVolList[0]
145
+            del sgrind_cementVolList[0]
146
+    def addSgrind_cementPitch(obj, sgrind_cementPitch, cut):
147
+        global sgrind_cementPitchData
148
+        sgrind_cementPitchList.append(" "+str(obj))
149
+        sgrind_cementPitchList.append(sgrind_cementPitch)
150
+        if len(sgrind_cementPitchList) >= cut and cut > 0:
151
+            del sgrind_cementPitchList[0]
152
+            del sgrind_cementPitchList[0] 
153
+###             
154
+    def addSgrind_railVol(obj, sgrind_railVol, cut):
155
+        global sgrind_railVolData
156
+        sgrind_railVolList.append(" "+str(obj))
157
+        sgrind_railVolList.append(sgrind_railVol)
158
+        if len(sgrind_railVolList) >= cut and cut > 0:
159
+            del sgrind_railVolList[0]
160
+            del sgrind_railVolList[0]
161
+    def addSgrind_railPitch(obj, sgrind_railPitch, cut):
162
+        global sgrind_railPitchData
163
+        sgrind_railPitchList.append(" "+str(obj))
164
+        sgrind_railPitchList.append(sgrind_railPitch)
165
+        if len(sgrind_railPitchList) >= cut and cut > 0:
166
+            del sgrind_railPitchList[0]
167
+            del sgrind_railPitchList[0] 
168
+##
169
+    def addSpopsound(obj, spopsound, cut):
170
+        global spopsoundData
171
+        spopsoundList.append(" "+str(obj))
172
+        spopsoundList.append(spopsound)
173
+        if len(spopsoundList) >= cut and cut > 0:
174
+            del spopsoundList[0]
175
+            del spopsoundList[0] 
176
+##
177
+    def addSlandsound(obj, slandsound, cut):
178
+        global slandsoundData
179
+        slandsoundList.append(" "+str(obj))
180
+        slandsoundList.append(slandsound)
181
+        if len(slandsoundList) >= cut and cut > 0:
182
+            del slandsoundList[0]
183
+            del slandsoundList[0] 
184
+    
185
+    def addSdeckvis(obj, sdeckvis, cut):
186
+        global sdeckvisData
187
+        sdeckvisList.append(" "+str(obj))
188
+        sdeckvisList.append(sdeckvis)
189
+        if len(sdeckvisList) >= cut and cut > 0:
190
+            del sdeckvisList[0]
191
+            del sdeckvisList[0]                                                                                       
192
+            
193
+    def saveAll():
194
+
195
+        allDataList = ["game="+gameName+"\n",
196
+            " ".join(positionList),
197
+            " ".join(orientationList),
198
+            " ".join(scaleList),
199
+            " ".join(colorList),
200
+            " ".join(stateList),
201
+            " ".join(visibilityList),
202
+            " ".join(skaterAnimList),
203
+            " ".join(skaterAnimFList),
204
+            " ".join(deckAnimList),
205
+            " ".join(deckAnimFList),
206
+            " ".join(srollVolList),
207
+            " ".join(srollPitchList), 
208
+            " ".join(sgrind_cementVolList),
209
+            " ".join(sgrind_cementPitchList),
210
+            " ".join(sgrind_railVolList),
211
+            " ".join(sgrind_railPitchList),
212
+            " ".join(spopsoundList),
213
+            " ".join(slandsoundList),
214
+            " ".join(sdeckvisList)]    
215
+        try:
216
+            with open(allDataPath,'w') as all:
217
+                all.write("|".join(allDataList))
218
+                all.close()
219
+                if printDebug:
220
+                    print("State recording saved successfuly to "+allDataPath)
221
+        except IOError:
222
+            if printDebug:
223
+                print(allDataPath+"cannot be opened for writing")
224
+
225
+class readData:
226
+                                   
227
+    def loadAll():
228
+        
229
+        global allDataList
230
+        global positionList
231
+        global orientationList
232
+        global scaleList
233
+        global colorList
234
+        global stateList
235
+        global visibilityList
236
+        global skaterAnimList
237
+        global skaterAnimFList
238
+        global deckAnimList
239
+        global deckAnimFList 
240
+        global srollVolList
241
+        global srollPitchList 
242
+        global sgrind_cementVolList
243
+        global sgrind_cementPitchList 
244
+        global sgrind_railVolList
245
+        global sgrind_railPitchList
246
+        global spopsoundList
247
+        global slandsoundList 
248
+        global sdeckvisList                                        
249
+            
250
+        if not allDataList:
251
+            try:
252
+                with open(allDataPath) as all:
253
+                    data = all.read()
254
+                    all.close()
255
+
256
+                    allDataList = data.split("|",6)
257
+
258
+                    loadedGameName = str(allDataList[0].split("=",1)[1]).strip()
259
+                    try:
260
+                        if loadedGameName == gameName:
261
+
262
+                            positionList = allDataList[1].split()
263
+                            orientationList = allDataList[2].split()
264
+                            scaleList = allDataList[3].split()
265
+                            colorList = allDataList[4].split()
266
+                            stateList = allDataList[5].split()
267
+                            visibilityList = allDataList[6].split()
268
+                            skaterAnimList = allDataList[7].split()
269
+                            skaterAnimFList = allDataList[8].split()
270
+                            deckAnimList = allDataList[9].split()
271
+                            deckAnimFList = allDataList[10].split()
272
+                            srollVolList = allDataList[11].split()
273
+                            srollPitchList = allDataList[12].split()
274
+                            sgrind_cementVolList = allDataList[13].split()
275
+                            sgrind_cementPitchList = allDataList[14].split()
276
+                            sgrind_railVolList = allDataList[15].split() 
277
+                            sgrind_railPitchList = allDataList[16].split()
278
+                            spopsoundList = allDataList[17].split()
279
+                            slandsoundList = allDataList[18].split()
280
+                            sdeckvisList = allDataList[19].split()
281
+                            
282
+                            if printDebug:
283
+                                print("Read file "+allDataPath)
284
+                    except:
285
+                        print("error reading replay data")        
286
+            except IOError:
287
+                if printDebug:
288
+                    print("Error reading "+allDataPath)
289
+
290
+    def returnPosition(objIndex, valueIndex):
291
+        
292
+        if positionList:
293
+            name = positionList[objIndex-2]   #That -2 is a little workaround to a list index out of range error.
294
+            position = positionList[valueIndex-2]
295
+
296
+            name = name.replace(" ","")
297
+
298
+            position = str(position)
299
+            position = position.replace(","," ")
300
+
301
+            pX = float(position.split()[0])
302
+            pY = float(position.split()[1])
303
+            pZ = float(position.split()[2])
304
+
305
+            position = [pX,pY,pZ]
306
+
307
+            return(name, position)
308
+
309
+    def returnOrientation(objIndex, valueIndex):
310
+        
311
+        if orientationList:
312
+            name = orientationList[objIndex-2]
313
+            orientation = orientationList[valueIndex-2]
314
+            
315
+            name = name.replace(" ","")
316
+            
317
+            orientation = str(orientation)
318
+            orientation = orientation.replace(","," ")
319
+            orientation = orientation.split()
320
+
321
+            return(name, orientation)
322
+
323
+    def returnScale(objIndex, valueIndex):
324
+
325
+        if scaleList:
326
+            name = scaleList[objIndex-2]
327
+            scale = scaleList[valueIndex-2]
328
+            
329
+            name = name.replace(" ","")
330
+            
331
+            scale = str(scale)
332
+            scale = scale.replace(","," ")
333
+            
334
+            sX = float(scale.split()[0])
335
+            sY = float(scale.split()[1])
336
+            sZ = float(scale.split()[2])
337
+            
338
+            scale = [sX,sY,sZ]
339
+
340
+            return(name, scale)
341
+
342
+    def returnColor(objIndex, valueIndex):
343
+
344
+        if colorList:
345
+            name = colorList[objIndex-2]
346
+            color = colorList[valueIndex-2]
347
+            
348
+            name = name.replace(" ","")
349
+            
350
+            color = str(color)
351
+            color = color.replace(","," ")
352
+            
353
+            cR = float(color.split()[0])
354
+            cG = float(color.split()[1])
355
+            cB = float(color.split()[2])
356
+            cA = float(color.split()[3])
357
+            
358
+            color = [cR,cG,cB,cA]
359
+
360
+            return(name, color)
361
+    
362
+    def returnState(objIndex, valueIndex):
363
+        
364
+        if stateList:
365
+            name = stateList[objIndex-2]
366
+            state = stateList[valueIndex-2]
367
+            
368
+            name = name.replace(" ","")
369
+            
370
+            state = str(state)
371
+            state = state.replace(","," ")
372
+            state = int(state)
373
+            
374
+            return(name, state)
375
+    
376
+    def returnVisibility(objIndex, valueIndex):
377
+        
378
+        if visibilityList:
379
+            name = visibilityList[objIndex-2]
380
+            visible = visibilityList[valueIndex-2]
381
+            
382
+            name = name.replace(" ","")
383
+            
384
+            visible = str(visible)
385
+            visible = visible.replace(","," ")
386
+            
387
+            return(name, visible)
388
+        
389
+    def returnSkaterAnim(objIndex, valueIndex):       
390
+        if skaterAnimList:
391
+            name = skaterAnimList[objIndex-2]
392
+            skaterAnim = skaterAnimList[valueIndex-2]
393
+            name = name.replace(" ","")           
394
+            skaterAnim = str(skaterAnim)
395
+            skaterAnim = skaterAnim.replace(","," ")           
396
+            return(name, skaterAnim) 
397
+        
398
+    def returnSkaterAnimF(objIndex, valueIndex):       
399
+        if skaterAnimFList:
400
+            name = skaterAnimFList[objIndex-2]
401
+            skaterAnimF = skaterAnimFList[valueIndex-2]
402
+            name = name.replace(" ","")
403
+            skaterAnimF = str(skaterAnimF)
404
+            skaterAnimF = skaterAnimF.replace(","," ")
405
+            return(name, skaterAnimF)  
406
+        
407
+    def returnDeckAnim(objIndex, valueIndex):    
408
+        if deckAnimList:
409
+            name = deckAnimList[objIndex-2]
410
+            deckAnim = deckAnimList[valueIndex-2]
411
+            name = name.replace(" ","")
412
+            deckAnim = str(deckAnim)
413
+            deckAnim = deckAnim.replace(","," ")
414
+            return(name, deckAnim) 
415
+        
416
+    def returnDeckAnimF(objIndex, valueIndex):
417
+        if deckAnimFList:
418
+            name = deckAnimFList[objIndex-2]
419
+            deckAnimF = deckAnimFList[valueIndex-2]
420
+            name = name.replace(" ","")
421
+            deckAnimF = str(deckAnimF)
422
+            deckAnimF = deckAnimF.replace(","," ")            
423
+            return(name, deckAnimF)
424
+####
425
+    def returnSrollVol(objIndex, valueIndex):
426
+        if srollVolList:
427
+            name = srollVolList[objIndex-2]
428
+            srollVol = srollVolList[valueIndex-2]
429
+            name = name.replace(" ","")
430
+            srollVol = str(srollVol)
431
+            srollVol = srollVol.replace(","," ")
432
+            srollVol = float(srollVol)
433
+            return(name, srollVol)
434
+        
435
+    def returnSrollPitch(objIndex, valueIndex):
436
+        if srollPitchList:
437
+            name = srollPitchList[objIndex-2]
438
+            srollPitch = srollPitchList[valueIndex-2]
439
+            name = name.replace(" ","")
440
+            srollPitch = str(srollPitch)
441
+            srollPitch = srollPitch.replace(","," ")
442
+            srollPitch = float(srollPitch)
443
+            return(name, srollPitch)                             ####
444
+####
445
+    def returnSgrind_cementVol(objIndex, valueIndex):
446
+        if sgrind_cementVolList:
447
+            name = sgrind_cementVolList[objIndex-2]
448
+            sgrind_cementVol = sgrind_cementVolList[valueIndex-2]
449
+            name = name.replace(" ","")
450
+            sgrind_cementVol = str(sgrind_cementVol)
451
+            sgrind_cementVol = sgrind_cementVol.replace(","," ")
452
+            sgrind_cementVol = float(sgrind_cementVol)
453
+            return(name, sgrind_cementVol)
454
+        
455
+    def returnSgrind_cementPitch(objIndex, valueIndex):
456
+        if sgrind_cementPitchList:
457
+            name = sgrind_cementPitchList[objIndex-2]
458
+            sgrind_cementPitch = sgrind_cementPitchList[valueIndex-2]
459
+            name = name.replace(" ","")
460
+            sgrind_cementPitch = str(sgrind_cementPitch)
461
+            sgrind_cementPitch = sgrind_cementPitch.replace(","," ")
462
+            sgrind_cementPitch = float(sgrind_cementPitch)
463
+            return(name, sgrind_cementPitch)                             ####              
464
+####
465
+    def returnSgrind_railVol(objIndex, valueIndex):
466
+        if sgrind_railVolList:
467
+            name = sgrind_railVolList[objIndex-2]
468
+            sgrind_railVol = sgrind_railVolList[valueIndex-2]
469
+            name = name.replace(" ","")
470
+            sgrind_railVol = str(sgrind_railVol)
471
+            sgrind_railVol = sgrind_railVol.replace(","," ")
472
+            sgrind_railVol = float(sgrind_railVol)
473
+            return(name, sgrind_railVol)
474
+        
475
+    def returnSgrind_railPitch(objIndex, valueIndex):
476
+        if sgrind_railPitchList:
477
+            name = sgrind_railPitchList[objIndex-2]
478
+            sgrind_railPitch = sgrind_railPitchList[valueIndex-2]
479
+            name = name.replace(" ","")
480
+            sgrind_railPitch = str(sgrind_railPitch)
481
+            sgrind_railPitch = sgrind_railPitch.replace(","," ")
482
+            sgrind_railPitch = float(sgrind_railPitch)
483
+            return(name, sgrind_railPitch)                             ####
484
+    def returnSpopsound(objIndex, valueIndex):
485
+        if spopsoundList:
486
+            name = spopsoundList[objIndex-2]
487
+            spopsound = spopsoundList[valueIndex-2]
488
+            name = name.replace(" ","")
489
+            spopsound = str(spopsound)
490
+            spopsound = spopsound.replace(","," ")
491
+            spopsound = int(spopsound)
492
+            return(name, spopsound)
493
+    def returnSlandsound(objIndex, valueIndex):
494
+        if slandsoundList:
495
+            name = slandsoundList[objIndex-2]
496
+            slandsound = slandsoundList[valueIndex-2]
497
+            name = name.replace(" ","")
498
+            slandsound = str(slandsound)
499
+            slandsound = slandsound.replace(","," ")
500
+            slandsound = int(slandsound)
501
+            return(name, slandsound) 
502
+    def returnSdeckvis(objIndex, valueIndex):
503
+        if sdeckvisList:
504
+            name = sdeckvisList[objIndex-2]
505
+            sdeckvis = sdeckvisList[valueIndex-2]
506
+            name = name.replace(" ","")
507
+            sdeckvis = str(sdeckvis)
508
+            sdeckvis = sdeckvis.replace(","," ")
509
+            sdeckvis = int(sdeckvis)
510
+            return(name, sdeckvis)                
511
+####                
512
+
513
+    def getLengthPos():
514
+        if positionList:
515
+            return(len(positionList))
516
+
517
+    def getLengthOri():
518
+        if orientationList:
519
+            return(len(orientationList))
520
+
521
+    def getLengthSca():
522
+        if scaleList:
523
+            return(len(scaleList))
524
+
525
+    def getLengthCol():
526
+        if colorList:
527
+            return(len(colorList))
528
+    
529
+    def getLengthSta():
530
+        if stateList:
531
+            return(len(stateList))
532
+    
533
+    def getLengthVis():
534
+        if visibilityList:
535
+            return(len(visibilityList))
536
+    def getLengthSkaterAnim():
537
+        if skaterAnimList:
538
+            return(len(skaterAnimList)) 
539
+    def getLengthSkaterAnimF():
540
+        if skaterAnimFList:
541
+            return(len(skaterAnimFList)) 
542
+    def getLengthDeckAnim():
543
+        if deckAnimList:
544
+            return(len(deckAnimList)) 
545
+    def getLengthDeckAnimF():
546
+        if deckAnimFList:
547
+            return(len(deckAnimFList))
548
+    def getLengthSrollVol():
549
+        if srollVolList:
550
+            return(len(srollVolList)) 
551
+    def getLengthSrollPitch():
552
+        if srollPitchList:
553
+            return(len(srollPitchList)) 
554
+    def getLengthSgrind_cementVol():
555
+        if sgrind_cementVolList:
556
+            return(len(sgrind_cementVolList)) 
557
+    def getLengthSgrind_cementPitch():
558
+        if sgrind_cementPitchList:
559
+            return(len(sgrind_cementPitchList))
560
+    def getLengthSgrind_railVol():
561
+        if sgrind_railVolList:
562
+            return(len(sgrind_railVolList)) 
563
+    def getLengthSgrind_railPitch():
564
+        if sgrind_railPitchList:
565
+            return(len(sgrind_railPitchList))
566
+    def getLengthSpopsound():
567
+        if spopsoundList:
568
+            return(len(spopsoundList)) 
569
+    def getLengthSlandsound():
570
+        if slandsoundList:
571
+            return(len(slandsoundList)) 
572
+    def getLengthSdeckvis():
573
+        if sdeckvisList:
574
+            return(len(sdeckvisList))                                                                                               

Loading…
Cancel
Save