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 23KB

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