Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Manager.py 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. def main():
  2. #"""
  3. #Modified BGE Gameplay Recorder Version 2
  4. #originally written by Nicholas Anderson, aka Red Frost Games.
  5. #"""
  6. #####Tweakables###############
  7. #Watch out! These numbers might bite!
  8. frame_rate = 60 #Set this to the framerate of your game.
  9. optimization = 1 #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
  10. recording_cutoff = 7300 #3600 #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
  11. recorder_state = 1 #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
  12. allow_playback_break = True #Allow the player to resume playing from the position in the recording.
  13. #####Sensor names#############
  14. record_sensor = "Record"
  15. save_recording_sensor = "Save"
  16. load_recording_sensor = "Load"
  17. track_left_sensor = "Left"
  18. track_right_sensor = "Right"
  19. break_sensor = "Break"
  20. ##############################
  21. from bge import logic
  22. import Record
  23. import SortData
  24. cont = logic.getCurrentController()
  25. own = cont.owner
  26. cont.sensors[record_sensor].skippedTicks = optimization
  27. dict = logic.globalDict
  28. #dict['recorder_on'] = recorder_on
  29. recorder_on = dict.get('recorder_on')
  30. own['recorder_on'] = recorder_on
  31. #print("recorder on: ", recorder_on)
  32. if recorder_on == 1:
  33. #----
  34. scene = logic.getCurrentScene()
  35. scene_list = logic.getSceneList()
  36. camList = scene.cameras
  37. followcam = camList["followcam"]
  38. freecam = camList["freecam"]
  39. skater = scene.objects["Char4"]
  40. cube = scene.objects["control_cube.002"]
  41. deck = scene.objects["deck"]
  42. trucks = scene.objects["trucks"]
  43. replay_cam_axis = own['replay_cam_axis']
  44. cam = own.actuators['Camera']
  45. #----
  46. joybutsens = "joyBut"
  47. #butt = cont.sensors[joybutsens]
  48. #aXis = cont.sensors["joysticksens"]
  49. #bk_but = 4
  50. back_on = dict['bkBut']
  51. #a_but = 0
  52. a_on = dict['aBut']
  53. #b_but = 1
  54. b_on = dict['bBut']
  55. #print(a on)
  56. last_back = own['last_back_but']
  57. #last_back = own['last_a_but']
  58. # reduction = 400000
  59. # axisTh = 0.03
  60. # lt = 4
  61. # rt = 5
  62. # lts_pr = 7
  63. # rts_pr = 8
  64. # lar_lts = 0
  65. # uad_lts = 1
  66. # lar_rts = 2
  67. # uad_rts = 3
  68. #lts_pr = 7
  69. #rts_pr = 8
  70. # lTrig = aXis.axisValues[lt] / reduction
  71. # rTrig = aXis.axisValues[rt] / reduction
  72. # lLR = aXis.axisValues[lar_lts] / reduction
  73. # lUD = aXis.axisValues[uad_lts] / reduction
  74. # rLR = aXis.axisValues[lar_rts] / reduction
  75. # rUD = aXis.axisValues[uad_rts] / reduction
  76. # ltsBut = butt.getButtonStatus(lts_pr)
  77. # rtsBut = butt.getButtonStatus(rts_pr)
  78. #
  79. lLR = dict['lLR']
  80. lUD = dict['lUD']
  81. rLR = dict['rLR']
  82. rUD = dict['rUD']
  83. lTrig = dict['lTrig']
  84. rTrig = dict['rTrig']
  85. aBut = dict['aBut']
  86. bBut = dict['bBut']
  87. xBut = dict['xBut']
  88. yBut = dict['yBut']
  89. lBump = dict['lBump']
  90. rBump = dict['rBump']
  91. bkBut = dict['bkBut']
  92. stBut = dict['stBut']
  93. xbBut = dict['xbBut']
  94. ltsBut = dict['ltsBut']
  95. rtsBut = dict['rtsBut']
  96. ldPad = dict['ldPad']
  97. rdPad = dict['rdPad']
  98. udPad = dict['udPad']
  99. ddPad = dict['ddPad']
  100. #trigs results range 0 - .08
  101. #print(lTrig, rTrig)
  102. #if cont.sensors[record_sensor].positive:
  103. if own["playback"] != True:
  104. Record.main(recording_cutoff, cube)
  105. if cont.sensors[save_recording_sensor].positive:
  106. SortData.writeData.saveAll()
  107. #if cont.sensors[load_recording_sensor].positive or (cube["sel"] == 1 and cube["last_sel"] == 0):
  108. if own['back_state'] == 1 and back_on == 1 and last_back == 0:
  109. cube["last_sel"] == 1
  110. SortData.writeData.saveAll()
  111. own["playback"] = True
  112. own["playbackBroken"] = False
  113. freecam.worldPosition = own.worldPosition
  114. followcam.worldPosition = own.worldPosition
  115. cube['grindcement_vol'] = 0
  116. cube['grindcement_pitch'] = 0
  117. cube['grindrail_vol'] = 0
  118. cube['grindrail_pitch'] = 0
  119. cube['sroll_vol'] = 0
  120. cube['sroll_pitch'] = 0
  121. if own["playback"]:
  122. Record.loadData()
  123. #..................
  124. if cont.sensors[track_left_sensor].positive:
  125. own["objIndex"] -= 2
  126. logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  127. if cont.sensors[track_right_sensor].positive:
  128. own["objIndex"] += 2
  129. logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  130. if own["playback"] == True:
  131. if rTrig > .01 and rTrig < .02:
  132. own["objIndex"] += 2
  133. logic.setLogicTicRate(frame_rate*.5)
  134. if (rTrig >= .02 and rTrig < .06) or own['loop_play'] == 1:
  135. own["objIndex"] += 2
  136. logic.setLogicTicRate(frame_rate*1)
  137. #print(own['objIndex'])
  138. if rTrig >= .06 and rTrig < .09:
  139. own["objIndex"] += 2
  140. logic.setLogicTicRate(frame_rate*1.5)
  141. if lTrig > .01 and lTrig < .02:
  142. own["objIndex"] -= 2
  143. logic.setLogicTicRate(frame_rate*.5)
  144. if lTrig >= .02 and lTrig < .06:
  145. own["objIndex"] -= 2
  146. logic.setLogicTicRate(frame_rate*1)
  147. if lTrig >= .06 and lTrig < .09:
  148. if own['loop_play'] == 1:
  149. own["objIndex"] -= 6
  150. #logic.setLogicTicRate(frame_rate*1.5)
  151. else:
  152. own["objIndex"] -= 2
  153. logic.setLogicTicRate(frame_rate*1.5)
  154. if b_on == True:
  155. print("bbut_on")
  156. own['objIndex'] = 0
  157. own['valueIndex'] = 0
  158. logic.setLogicTicRate(frame_rate*1)
  159. #....................
  160. if allow_playback_break:
  161. if own['back_state'] == 0 and back_on == 1 and last_back == 0:
  162. own["playbackBroken"] = True
  163. own["playback"] = False
  164. #print("break - add hud, remove stance (back_state == False)")
  165. #cont.activate(own.actuators['add_hud'])
  166. #cont.activate(own.actuators['remove_stance'])
  167. #removescene = cont.actuators["remove_hud"]
  168. #removescene.scene = "replay_HUD"
  169. #addscene = cont.actuators["add_hud"]
  170. #addscene.scene = "stance"
  171. #cont.activate(addscene)
  172. #cont.activate(removescene)
  173. elif own["playbackBroken"] and back_on == 0:
  174. Record.breakOut()
  175. #cont.activate(own.actuators['remove_hud'])
  176. #cont.activate(own.actuators['add_stance'])
  177. #addscene = cont.actuators["add_hud"]
  178. #addscene.scene = "replay_HUD"
  179. #removescene = cont.actuators["remove_hud"]
  180. #removescene.scene = "stance"
  181. #cont.activate(addscene)
  182. #cont.activate(removescene)
  183. logic.setLogicTicRate(frame_rate)
  184. #set value index
  185. own.state = recorder_state
  186. own["playbackBroken"] = False
  187. skater.stopAction(9999)
  188. deck.stopAction(9999)
  189. trucks.stopAction(9999)
  190. cont.activate(own.actuators['replayCam'])
  191. print("unbreak")
  192. own['loop_play'] = 0
  193. #own['valueIndex'] = 0
  194. #own["objIndex"] += 2
  195. #logic.setLogicTicRate(frame_rate*1)
  196. #own['objectIndex'] = 0
  197. #print("valueIndex = ", own['valueIndex'])
  198. if back_on == 1 and own['back_but'] == 0:
  199. print("change back state")
  200. if own['back_state'] == True:
  201. own['back_state'] = False
  202. #elif own['back_state'] == False:
  203. else:
  204. own['back_state'] = True
  205. ###
  206. if own['last_playback'] != own['playback']:
  207. if own['last_playback'] == True:
  208. cont.activate(own.actuators['remove_hud'])
  209. cont.activate(own.actuators['add_stance'])
  210. own['camnum'] = 0
  211. cam = camList["Camera.003"]
  212. scene.active_camera = cam
  213. print("turning replay off", own['playback'])
  214. if own['last_playback'] == False:
  215. print("turning replay on", own['playback'])
  216. cont.activate(own.actuators['add_hud'])
  217. cont.activate(own.actuators['remove_stance'])
  218. own['objIndex'] = 0
  219. own['valueIndex'] = 3
  220. logic.setLogicTicRate(frame_rate*1)
  221. ####
  222. if a_on == 1 and own['a_but'] == False:
  223. if own['loop_play'] == 1:
  224. own['loop_play'] = 0
  225. else:
  226. own['loop_play'] = 1
  227. if rLR > .05 and own["playback"]:
  228. act = cont.actuators["replayCam"]
  229. if rLR > .07:
  230. act.dLoc = [ .06, 0.0, 0.0]
  231. else:
  232. act.dLoc = [ .03, 0.0, 0.0]
  233. #cont.deactivate(own.actuators['Camera'])
  234. cont.activate(own.actuators['replayCam'])
  235. #print("move")
  236. elif rLR < -.05 and own["playback"]:
  237. act = cont.actuators["replayCam"]
  238. if rLR < -.07:
  239. act.dLoc = [ -.06, 0.0, 0.0]
  240. else:
  241. act.dLoc = [ -.03, 0.0, 0.0]
  242. #cont.deactivate(own.actuators['Camera'])
  243. #act.damping = 6
  244. cont.activate(own.actuators['replayCam'])
  245. #print("move")
  246. else:
  247. #pass
  248. cont.deactivate(own.actuators['replayCam'])
  249. #cont.activate(own.actuators['Camera'])
  250. #print("back state: ", own['back_state'], "last_back_but: ", own['last_back_but'], "back_but :", own['back_but'])
  251. #integer
  252. #
  253. #0 = +X axis
  254. #
  255. #1 = +Y axis
  256. #
  257. #2 = +Z axis
  258. #
  259. #3 = -X axis
  260. #
  261. #4 = -Y axis
  262. #
  263. #5 = -Z axis
  264. # if rLR > .05 and own["playback"]:
  265. # if own['last_rtsBut'] == True and rtsBut == False:
  266. # if replay_cam_axis == 0:
  267. # replay_cam_axis = 1
  268. # elif replay_cam_axis == 1:
  269. # replay_cam_axis = 3
  270. # elif replay_cam_axis == 3 :
  271. # replay_cam_axis = 4
  272. # elif replay_cam_axis == 4:
  273. # replay_cam_axis = 0
  274. # cam.axis = replay_cam_axis
  275. # cont.activate(cam)
  276. # print("set replay_cam_axis: ", replay_cam_axis)
  277. # own['replay_cam_axis'] = replay_cam_axis
  278. if own['last_ltsBut'] == True and ltsBut == False and own['playback']:
  279. # get camera named SecurityCam
  280. if own['camnum'] == 1:
  281. own['camnum'] = 2
  282. elif own['camnum'] == 0:
  283. own['camnum'] = 1
  284. elif own['camnum'] == 2:
  285. own['camnum'] = 0
  286. if own['last_rtsBut'] == True and rtsBut == False and own['playback']:
  287. # get camera named SecurityCam
  288. if "replay_HUD" in scene_list:
  289. cont.activate(own.actuators['remove_hud'])
  290. else:
  291. cont.activate(own.actuators['add_hud'])
  292. if own['camnum'] == 1 and own['playback']:
  293. scene.active_camera = followcam
  294. #################
  295. camspeed1 = .04 #.015
  296. camspeed2 = .1 #.055
  297. camrot1 = .02 #.005
  298. camrot2 = .04 #.02
  299. #up
  300. if lUD < -0.080:
  301. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  302. cont.activate(followcam.actuators["up"])
  303. #print("fastup")
  304. else:
  305. cont.deactivate(followcam.actuators["up"])
  306. # #down
  307. if lUD > .080:
  308. followcam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  309. cont.activate(followcam.actuators["down"])
  310. else:
  311. cont.deactivate(followcam.actuators["down"])
  312. # #left
  313. if lLR < -0.080:
  314. followcam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  315. cont.activate(followcam.actuators["left"])
  316. else:
  317. cont.deactivate(followcam.actuators["left"])
  318. # #right
  319. if lLR > 0.080:
  320. followcam.actuators["right"].dLoc = [camspeed2, 0, 0]
  321. cont.activate(followcam.actuators["right"])
  322. else:
  323. cont.deactivate(followcam.actuators["right"])
  324. #up
  325. if rUD < -0.080:
  326. followcam.actuators["rotup"].dLoc = [0, 0, camrot2]
  327. cont.activate(followcam.actuators["rotup"])
  328. #print("uppppppppppppppppppppppppppp")
  329. else:
  330. cont.deactivate(followcam.actuators["rotup"])
  331. # #down
  332. if rUD > .080:
  333. followcam.actuators["rotdown"].dLoc = [0, 0, -camrot2]
  334. cont.activate(followcam.actuators["rotdown"])
  335. else:
  336. cont.deactivate(followcam.actuators["rotdown"])
  337. # #left
  338. if rLR < -0.080:
  339. followcam.actuators["rotleft"].dRot = [0, 0, camrot2]
  340. cont.activate(followcam.actuators["rotleft"])
  341. else:
  342. cont.deactivate(followcam.actuators["rotleft"])
  343. # #right
  344. if rLR > 0.080:
  345. followcam.actuators["rotright"].dRot = [0, 0, -camrot2]
  346. cont.activate(followcam.actuators["rotright"])
  347. else:
  348. cont.deactivate(followcam.actuators["rotright"])
  349. #*********************************************
  350. if lUD > -0.080 and lUD < -0.030:
  351. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  352. cont.activate(followcam.actuators["up"])
  353. #print(lUD)
  354. else:
  355. cont.deactivate(followcam.actuators["up"])
  356. # #down
  357. if lUD < .080 and lUD > .03:
  358. followcam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  359. cont.activate(followcam.actuators["down"])
  360. else:
  361. cont.deactivate(followcam.actuators["down"])
  362. # #left
  363. if lLR > -0.080 and lLR < -0.030:
  364. followcam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  365. cont.activate(followcam.actuators["left"])
  366. else:
  367. cont.deactivate(followcam.actuators["left"])
  368. # #right
  369. if lLR < .080 and lLR > .03:
  370. followcam.actuators["right"].dLoc = [camspeed1, 0, 0]
  371. cont.activate(followcam.actuators["right"])
  372. else:
  373. cont.deactivate(followcam.actuators["right"])
  374. #up
  375. if rUD > -0.080 and rUD < -0.030:
  376. followcam.actuators["rotup"].dRot = [camrot1, 0, 0]
  377. cont.activate(followcam.actuators["rotup"])
  378. else:
  379. cont.deactivate(followcam.actuators["rotup"])
  380. # #down
  381. if rUD < .080 and rUD > .03:
  382. followcam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  383. cont.activate(followcam.actuators["rotdown"])
  384. else:
  385. cont.deactivate(followcam.actuators["rotdown"])
  386. # #left
  387. if rLR > -0.080 and rLR < -0.030:
  388. followcam.actuators["rotleft"].dRot = [0, 0, camrot1]
  389. cont.activate(followcam.actuators["rotleft"])
  390. else:
  391. cont.deactivate(followcam.actuators["rotleft"])
  392. # #right
  393. if rLR < .080 and rLR > .03:
  394. followcam.actuators["rotright"].dRot = [0, 0, -camrot1]
  395. cont.activate(followcam.actuators["rotright"])
  396. else:
  397. cont.deactivate(followcam.actuators["rotright"])
  398. #################
  399. if own['camnum'] == 2 and own['playback']:
  400. scene.active_camera = freecam
  401. #act = freecam.actuators[
  402. camspeed1 = .015
  403. camspeed2 = .055
  404. camrot1 = .005
  405. camrot2 = .02
  406. #up
  407. if lUD < -0.080:
  408. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  409. cont.activate(freecam.actuators["up"])
  410. #print("fastup")
  411. else:
  412. cont.deactivate(freecam.actuators["up"])
  413. # #down
  414. if lUD > .080:
  415. freecam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  416. cont.activate(freecam.actuators["down"])
  417. else:
  418. cont.deactivate(freecam.actuators["down"])
  419. # #left
  420. if lLR < -0.080:
  421. freecam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  422. cont.activate(freecam.actuators["left"])
  423. else:
  424. cont.deactivate(freecam.actuators["left"])
  425. # #right
  426. if lLR > 0.080:
  427. freecam.actuators["right"].dLoc = [camspeed2, 0, 0]
  428. cont.activate(freecam.actuators["right"])
  429. else:
  430. cont.deactivate(freecam.actuators["right"])
  431. #up
  432. if rUD < -0.080:
  433. freecam.actuators["rotup"].dRot = [camrot2, 0, 0]
  434. cont.activate(freecam.actuators["rotup"])
  435. else:
  436. cont.deactivate(freecam.actuators["rotup"])
  437. # #down
  438. if rUD > .080:
  439. freecam.actuators["rotdown"].dRot = [-camrot2, 0, 0]
  440. cont.activate(freecam.actuators["rotdown"])
  441. else:
  442. cont.deactivate(freecam.actuators["rotdown"])
  443. # #left
  444. if rLR < -0.080:
  445. freecam.actuators["rotleft"].dRot = [0, 0, camrot2]
  446. cont.activate(freecam.actuators["rotleft"])
  447. else:
  448. cont.deactivate(freecam.actuators["rotleft"])
  449. # #right
  450. if rLR > 0.080:
  451. freecam.actuators["rotright"].dRot = [0, 0, -camrot2]
  452. cont.activate(freecam.actuators["rotright"])
  453. else:
  454. cont.deactivate(freecam.actuators["rotright"])
  455. #*********************************************
  456. if lUD > -0.080 and lUD < -0.030:
  457. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  458. cont.activate(freecam.actuators["up"])
  459. #print(lUD)
  460. else:
  461. cont.deactivate(freecam.actuators["up"])
  462. # #down
  463. if lUD < .080 and lUD > .03:
  464. freecam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  465. cont.activate(freecam.actuators["down"])
  466. else:
  467. cont.deactivate(freecam.actuators["down"])
  468. # #left
  469. if lLR > -0.080 and lLR < -0.030:
  470. freecam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  471. cont.activate(freecam.actuators["left"])
  472. else:
  473. cont.deactivate(freecam.actuators["left"])
  474. # #right
  475. if lLR < .080 and lLR > .03:
  476. freecam.actuators["right"].dLoc = [camspeed1, 0, 0]
  477. cont.activate(freecam.actuators["right"])
  478. else:
  479. cont.deactivate(freecam.actuators["right"])
  480. #up
  481. if rUD > -0.080 and rUD < -0.030:
  482. freecam.actuators["rotup"].dRot = [camrot1, 0, 0]
  483. cont.activate(freecam.actuators["rotup"])
  484. else:
  485. cont.deactivate(freecam.actuators["rotup"])
  486. # #down
  487. if rUD < .080 and rUD > .03:
  488. freecam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  489. cont.activate(freecam.actuators["rotdown"])
  490. else:
  491. cont.deactivate(freecam.actuators["rotdown"])
  492. # #left
  493. if rLR > -0.080 and rLR < -0.030:
  494. freecam.actuators["rotleft"].dRot = [0, 0, camrot1]
  495. cont.activate(freecam.actuators["rotleft"])
  496. else:
  497. cont.deactivate(freecam.actuators["rotleft"])
  498. # #right
  499. if rLR < .080 and rLR > .03:
  500. freecam.actuators["rotright"].dRot = [0, 0, -camrot1]
  501. cont.activate(freecam.actuators["rotright"])
  502. else:
  503. cont.deactivate(freecam.actuators["rotright"])
  504. ########################################
  505. if own['camnum'] == 0:
  506. cam = camList["Camera.003"]
  507. scene.active_camera = cam
  508. valueIndex = own['valueIndex']
  509. n = (valueIndex / recording_cutoff) * 1000
  510. n = int(round(n))
  511. #n = 10
  512. #print("n: ", n, "--", valueIndex, recording_cutoff)
  513. #dict = logic.globalDict #Get the global dictionary
  514. dict['playhead'] = n
  515. own['last_back_but'] = own['back_but']
  516. own['back_but'] = back_on
  517. own['last_a_but'] = own['a_but']
  518. own['a_but'] = a_on
  519. own['last_ltsBut'] = ltsBut
  520. own['last_rtsBut'] = rtsBut
  521. own['last_playback'] = own['playback']