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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. if own["playback"]:
  116. Record.loadData()
  117. #..................
  118. if cont.sensors[track_left_sensor].positive:
  119. own["objIndex"] -= 2
  120. logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  121. if cont.sensors[track_right_sensor].positive:
  122. own["objIndex"] += 2
  123. logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  124. if own["playback"] == True:
  125. if rTrig > .01 and rTrig < .02:
  126. own["objIndex"] += 2
  127. logic.setLogicTicRate(frame_rate*.5)
  128. if (rTrig >= .02 and rTrig < .06) or own['loop_play'] == 1:
  129. own["objIndex"] += 2
  130. logic.setLogicTicRate(frame_rate*1)
  131. #print(own['objIndex'])
  132. if rTrig >= .06 and rTrig < .09:
  133. own["objIndex"] += 2
  134. logic.setLogicTicRate(frame_rate*1.5)
  135. if lTrig > .01 and lTrig < .02:
  136. own["objIndex"] -= 2
  137. logic.setLogicTicRate(frame_rate*.5)
  138. if lTrig >= .02 and lTrig < .06:
  139. own["objIndex"] -= 2
  140. logic.setLogicTicRate(frame_rate*1)
  141. if lTrig >= .06 and lTrig < .09:
  142. if own['loop_play'] == 1:
  143. own["objIndex"] -= 6
  144. #logic.setLogicTicRate(frame_rate*1.5)
  145. else:
  146. own["objIndex"] -= 2
  147. logic.setLogicTicRate(frame_rate*1.5)
  148. if b_on == True:
  149. print("bbut_on")
  150. own['objIndex'] = 0
  151. own['valueIndex'] = 0
  152. logic.setLogicTicRate(frame_rate*1)
  153. #....................
  154. if allow_playback_break:
  155. if own['back_state'] == 0 and back_on == 1 and last_back == 0:
  156. own["playbackBroken"] = True
  157. own["playback"] = False
  158. #print("break - add hud, remove stance (back_state == False)")
  159. #cont.activate(own.actuators['add_hud'])
  160. #cont.activate(own.actuators['remove_stance'])
  161. #removescene = cont.actuators["remove_hud"]
  162. #removescene.scene = "replay_HUD"
  163. #addscene = cont.actuators["add_hud"]
  164. #addscene.scene = "stance"
  165. #cont.activate(addscene)
  166. #cont.activate(removescene)
  167. elif own["playbackBroken"] and back_on == 0:
  168. Record.breakOut()
  169. #cont.activate(own.actuators['remove_hud'])
  170. #cont.activate(own.actuators['add_stance'])
  171. #addscene = cont.actuators["add_hud"]
  172. #addscene.scene = "replay_HUD"
  173. #removescene = cont.actuators["remove_hud"]
  174. #removescene.scene = "stance"
  175. #cont.activate(addscene)
  176. #cont.activate(removescene)
  177. logic.setLogicTicRate(frame_rate)
  178. #set value index
  179. own.state = recorder_state
  180. own["playbackBroken"] = False
  181. skater.stopAction(9999)
  182. deck.stopAction(9999)
  183. trucks.stopAction(9999)
  184. cont.activate(own.actuators['replayCam'])
  185. print("unbreak")
  186. own['loop_play'] = 0
  187. #own['valueIndex'] = 0
  188. #own["objIndex"] += 2
  189. #logic.setLogicTicRate(frame_rate*1)
  190. #own['objectIndex'] = 0
  191. #print("valueIndex = ", own['valueIndex'])
  192. if back_on == 1 and own['back_but'] == 0:
  193. print("change back state")
  194. if own['back_state'] == True:
  195. own['back_state'] = False
  196. #elif own['back_state'] == False:
  197. else:
  198. own['back_state'] = True
  199. ###
  200. if own['last_playback'] != own['playback']:
  201. if own['last_playback'] == True:
  202. cont.activate(own.actuators['remove_hud'])
  203. cont.activate(own.actuators['add_stance'])
  204. own['camnum'] = 0
  205. cam = camList["Camera.003"]
  206. scene.active_camera = cam
  207. print("turning replay off", own['playback'])
  208. if own['last_playback'] == False:
  209. print("turning replay on", own['playback'])
  210. cont.activate(own.actuators['add_hud'])
  211. cont.activate(own.actuators['remove_stance'])
  212. own['objIndex'] = 0
  213. own['valueIndex'] = 3
  214. logic.setLogicTicRate(frame_rate*1)
  215. ####
  216. if a_on == 1 and own['a_but'] == False:
  217. if own['loop_play'] == 1:
  218. own['loop_play'] = 0
  219. else:
  220. own['loop_play'] = 1
  221. if rLR > .05 and own["playback"]:
  222. act = cont.actuators["replayCam"]
  223. if rLR > .07:
  224. act.dLoc = [ .06, 0.0, 0.0]
  225. else:
  226. act.dLoc = [ .03, 0.0, 0.0]
  227. #cont.deactivate(own.actuators['Camera'])
  228. cont.activate(own.actuators['replayCam'])
  229. #print("move")
  230. elif rLR < -.05 and own["playback"]:
  231. act = cont.actuators["replayCam"]
  232. if rLR < -.07:
  233. act.dLoc = [ -.06, 0.0, 0.0]
  234. else:
  235. act.dLoc = [ -.03, 0.0, 0.0]
  236. #cont.deactivate(own.actuators['Camera'])
  237. #act.damping = 6
  238. cont.activate(own.actuators['replayCam'])
  239. #print("move")
  240. else:
  241. #pass
  242. cont.deactivate(own.actuators['replayCam'])
  243. #cont.activate(own.actuators['Camera'])
  244. #print("back state: ", own['back_state'], "last_back_but: ", own['last_back_but'], "back_but :", own['back_but'])
  245. #integer
  246. #
  247. #0 = +X axis
  248. #
  249. #1 = +Y axis
  250. #
  251. #2 = +Z axis
  252. #
  253. #3 = -X axis
  254. #
  255. #4 = -Y axis
  256. #
  257. #5 = -Z axis
  258. # if rLR > .05 and own["playback"]:
  259. # if own['last_rtsBut'] == True and rtsBut == False:
  260. # if replay_cam_axis == 0:
  261. # replay_cam_axis = 1
  262. # elif replay_cam_axis == 1:
  263. # replay_cam_axis = 3
  264. # elif replay_cam_axis == 3 :
  265. # replay_cam_axis = 4
  266. # elif replay_cam_axis == 4:
  267. # replay_cam_axis = 0
  268. # cam.axis = replay_cam_axis
  269. # cont.activate(cam)
  270. # print("set replay_cam_axis: ", replay_cam_axis)
  271. # own['replay_cam_axis'] = replay_cam_axis
  272. if own['last_ltsBut'] == True and ltsBut == False and own['playback']:
  273. # get camera named SecurityCam
  274. if own['camnum'] == 1:
  275. own['camnum'] = 2
  276. elif own['camnum'] == 0:
  277. own['camnum'] = 1
  278. elif own['camnum'] == 2:
  279. own['camnum'] = 0
  280. if own['last_rtsBut'] == True and rtsBut == False and own['playback']:
  281. # get camera named SecurityCam
  282. if "replay_HUD" in scene_list:
  283. cont.activate(own.actuators['remove_hud'])
  284. else:
  285. cont.activate(own.actuators['add_hud'])
  286. if own['camnum'] == 1 and own['playback']:
  287. scene.active_camera = followcam
  288. #################
  289. camspeed1 = .04 #.015
  290. camspeed2 = .1 #.055
  291. camrot1 = .02 #.005
  292. camrot2 = .04 #.02
  293. #up
  294. if lUD < -0.080:
  295. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  296. cont.activate(followcam.actuators["up"])
  297. #print("fastup")
  298. else:
  299. cont.deactivate(followcam.actuators["up"])
  300. # #down
  301. if lUD > .080:
  302. followcam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  303. cont.activate(followcam.actuators["down"])
  304. else:
  305. cont.deactivate(followcam.actuators["down"])
  306. # #left
  307. if lLR < -0.080:
  308. followcam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  309. cont.activate(followcam.actuators["left"])
  310. else:
  311. cont.deactivate(followcam.actuators["left"])
  312. # #right
  313. if lLR > 0.080:
  314. followcam.actuators["right"].dLoc = [camspeed2, 0, 0]
  315. cont.activate(followcam.actuators["right"])
  316. else:
  317. cont.deactivate(followcam.actuators["right"])
  318. #up
  319. if rUD < -0.080:
  320. followcam.actuators["rotup"].dLoc = [0, 0, camrot2]
  321. cont.activate(followcam.actuators["rotup"])
  322. #print("uppppppppppppppppppppppppppp")
  323. else:
  324. cont.deactivate(followcam.actuators["rotup"])
  325. # #down
  326. if rUD > .080:
  327. followcam.actuators["rotdown"].dLoc = [0, 0, -camrot2]
  328. cont.activate(followcam.actuators["rotdown"])
  329. else:
  330. cont.deactivate(followcam.actuators["rotdown"])
  331. # #left
  332. if rLR < -0.080:
  333. followcam.actuators["rotleft"].dRot = [0, 0, camrot2]
  334. cont.activate(followcam.actuators["rotleft"])
  335. else:
  336. cont.deactivate(followcam.actuators["rotleft"])
  337. # #right
  338. if rLR > 0.080:
  339. followcam.actuators["rotright"].dRot = [0, 0, -camrot2]
  340. cont.activate(followcam.actuators["rotright"])
  341. else:
  342. cont.deactivate(followcam.actuators["rotright"])
  343. #*********************************************
  344. if lUD > -0.080 and lUD < -0.030:
  345. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  346. cont.activate(followcam.actuators["up"])
  347. #print(lUD)
  348. else:
  349. cont.deactivate(followcam.actuators["up"])
  350. # #down
  351. if lUD < .080 and lUD > .03:
  352. followcam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  353. cont.activate(followcam.actuators["down"])
  354. else:
  355. cont.deactivate(followcam.actuators["down"])
  356. # #left
  357. if lLR > -0.080 and lLR < -0.030:
  358. followcam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  359. cont.activate(followcam.actuators["left"])
  360. else:
  361. cont.deactivate(followcam.actuators["left"])
  362. # #right
  363. if lLR < .080 and lLR > .03:
  364. followcam.actuators["right"].dLoc = [camspeed1, 0, 0]
  365. cont.activate(followcam.actuators["right"])
  366. else:
  367. cont.deactivate(followcam.actuators["right"])
  368. #up
  369. if rUD > -0.080 and rUD < -0.030:
  370. followcam.actuators["rotup"].dRot = [camrot1, 0, 0]
  371. cont.activate(followcam.actuators["rotup"])
  372. else:
  373. cont.deactivate(followcam.actuators["rotup"])
  374. # #down
  375. if rUD < .080 and rUD > .03:
  376. followcam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  377. cont.activate(followcam.actuators["rotdown"])
  378. else:
  379. cont.deactivate(followcam.actuators["rotdown"])
  380. # #left
  381. if rLR > -0.080 and rLR < -0.030:
  382. followcam.actuators["rotleft"].dRot = [0, 0, camrot1]
  383. cont.activate(followcam.actuators["rotleft"])
  384. else:
  385. cont.deactivate(followcam.actuators["rotleft"])
  386. # #right
  387. if rLR < .080 and rLR > .03:
  388. followcam.actuators["rotright"].dRot = [0, 0, -camrot1]
  389. cont.activate(followcam.actuators["rotright"])
  390. else:
  391. cont.deactivate(followcam.actuators["rotright"])
  392. #################
  393. if own['camnum'] == 2 and own['playback']:
  394. scene.active_camera = freecam
  395. #act = freecam.actuators[
  396. camspeed1 = .015
  397. camspeed2 = .055
  398. camrot1 = .005
  399. camrot2 = .02
  400. #up
  401. if lUD < -0.080:
  402. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  403. cont.activate(freecam.actuators["up"])
  404. #print("fastup")
  405. else:
  406. cont.deactivate(freecam.actuators["up"])
  407. # #down
  408. if lUD > .080:
  409. freecam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  410. cont.activate(freecam.actuators["down"])
  411. else:
  412. cont.deactivate(freecam.actuators["down"])
  413. # #left
  414. if lLR < -0.080:
  415. freecam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  416. cont.activate(freecam.actuators["left"])
  417. else:
  418. cont.deactivate(freecam.actuators["left"])
  419. # #right
  420. if lLR > 0.080:
  421. freecam.actuators["right"].dLoc = [camspeed2, 0, 0]
  422. cont.activate(freecam.actuators["right"])
  423. else:
  424. cont.deactivate(freecam.actuators["right"])
  425. #up
  426. if rUD < -0.080:
  427. freecam.actuators["rotup"].dRot = [camrot2, 0, 0]
  428. cont.activate(freecam.actuators["rotup"])
  429. else:
  430. cont.deactivate(freecam.actuators["rotup"])
  431. # #down
  432. if rUD > .080:
  433. freecam.actuators["rotdown"].dRot = [-camrot2, 0, 0]
  434. cont.activate(freecam.actuators["rotdown"])
  435. else:
  436. cont.deactivate(freecam.actuators["rotdown"])
  437. # #left
  438. if rLR < -0.080:
  439. freecam.actuators["rotleft"].dRot = [0, 0, camrot2]
  440. cont.activate(freecam.actuators["rotleft"])
  441. else:
  442. cont.deactivate(freecam.actuators["rotleft"])
  443. # #right
  444. if rLR > 0.080:
  445. freecam.actuators["rotright"].dRot = [0, 0, -camrot2]
  446. cont.activate(freecam.actuators["rotright"])
  447. else:
  448. cont.deactivate(freecam.actuators["rotright"])
  449. #*********************************************
  450. if lUD > -0.080 and lUD < -0.030:
  451. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  452. cont.activate(freecam.actuators["up"])
  453. #print(lUD)
  454. else:
  455. cont.deactivate(freecam.actuators["up"])
  456. # #down
  457. if lUD < .080 and lUD > .03:
  458. freecam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  459. cont.activate(freecam.actuators["down"])
  460. else:
  461. cont.deactivate(freecam.actuators["down"])
  462. # #left
  463. if lLR > -0.080 and lLR < -0.030:
  464. freecam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  465. cont.activate(freecam.actuators["left"])
  466. else:
  467. cont.deactivate(freecam.actuators["left"])
  468. # #right
  469. if lLR < .080 and lLR > .03:
  470. freecam.actuators["right"].dLoc = [camspeed1, 0, 0]
  471. cont.activate(freecam.actuators["right"])
  472. else:
  473. cont.deactivate(freecam.actuators["right"])
  474. #up
  475. if rUD > -0.080 and rUD < -0.030:
  476. freecam.actuators["rotup"].dRot = [camrot1, 0, 0]
  477. cont.activate(freecam.actuators["rotup"])
  478. else:
  479. cont.deactivate(freecam.actuators["rotup"])
  480. # #down
  481. if rUD < .080 and rUD > .03:
  482. freecam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  483. cont.activate(freecam.actuators["rotdown"])
  484. else:
  485. cont.deactivate(freecam.actuators["rotdown"])
  486. # #left
  487. if rLR > -0.080 and rLR < -0.030:
  488. freecam.actuators["rotleft"].dRot = [0, 0, camrot1]
  489. cont.activate(freecam.actuators["rotleft"])
  490. else:
  491. cont.deactivate(freecam.actuators["rotleft"])
  492. # #right
  493. if rLR < .080 and rLR > .03:
  494. freecam.actuators["rotright"].dRot = [0, 0, -camrot1]
  495. cont.activate(freecam.actuators["rotright"])
  496. else:
  497. cont.deactivate(freecam.actuators["rotright"])
  498. ########################################
  499. if own['camnum'] == 0:
  500. cam = camList["Camera.003"]
  501. scene.active_camera = cam
  502. valueIndex = own['valueIndex']
  503. n = (valueIndex / recording_cutoff) * 1000
  504. n = int(round(n))
  505. #n = 10
  506. #print("n: ", n, "--", valueIndex, recording_cutoff)
  507. #dict = logic.globalDict #Get the global dictionary
  508. dict['playhead'] = n
  509. own['last_back_but'] = own['back_but']
  510. own['back_but'] = back_on
  511. own['last_a_but'] = own['a_but']
  512. own['a_but'] = a_on
  513. own['last_ltsBut'] = ltsBut
  514. own['last_rtsBut'] = rtsBut
  515. own['last_playback'] = own['playback']