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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. import mathutils
  2. import bge
  3. def main():
  4. #"""
  5. #Modified BGE Gameplay Recorder Version 2
  6. #originally written by Nicholas Anderson, aka Red Frost Games.
  7. #"""
  8. from bge import logic
  9. import Record
  10. import SortData
  11. dict = logic.globalDict
  12. #####Tweakables###############
  13. #Watch out! These numbers might bite!
  14. frame_rate = 60 #Set this to the framerate of your game.
  15. 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.
  16. recording_cutoff = dict['replay_record_length']
  17. #recording_cutoff = 7300 #3600 #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
  18. 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.
  19. allow_playback_break = True #Allow the player to resume playing from the position in the recording.
  20. #####Sensor names#############
  21. record_sensor = "Record"
  22. save_recording_sensor = "Save"
  23. load_recording_sensor = "Load"
  24. track_left_sensor = "Left"
  25. track_right_sensor = "Right"
  26. break_sensor = "Break"
  27. ##############################
  28. cont = logic.getCurrentController()
  29. own = cont.owner
  30. cont.sensors[record_sensor].skippedTicks = optimization
  31. #dict['recorder_on'] = recorder_on
  32. recorder_on = dict.get('recorder_on')
  33. own['recorder_on'] = recorder_on
  34. #print("recorder on: ", recorder_on)
  35. if recorder_on == 1:
  36. #----
  37. scene = logic.getCurrentScene()
  38. scene_list = logic.getSceneList()
  39. camList = scene.cameras
  40. followcam = camList["followcam"]
  41. freecam = camList["freecam"]
  42. skater = scene.objects["Char4"]
  43. cube = scene.objects["control_cube.002"]
  44. deck = scene.objects["b_deck"]
  45. trucks = scene.objects["b_trucks"]
  46. replay_cam_axis = own['replay_cam_axis']
  47. cam = own.actuators['Camera']
  48. #----
  49. joybutsens = "joyBut"
  50. #butt = cont.sensors[joybutsens]
  51. #aXis = cont.sensors["joysticksens"]
  52. #bk_but = 4
  53. back_on = dict['bkBut']
  54. #a_but = 0
  55. a_on = dict['aBut']
  56. #b_but = 1
  57. b_on = dict['bBut']
  58. #print(a on)
  59. last_back = own['last_back_but']
  60. lLR = dict['lLR']
  61. lUD = dict['lUD']
  62. rLR = dict['rLR']
  63. rUD = dict['rUD']
  64. lTrig = dict['lTrig']
  65. rTrig = dict['rTrig']
  66. aBut = dict['aBut']
  67. bBut = dict['bBut']
  68. xBut = dict['xBut']
  69. yBut = dict['yBut']
  70. lBump = dict['lBump']
  71. rBump = dict['rBump']
  72. bkBut = dict['bkBut']
  73. stBut = dict['stBut']
  74. xbBut = dict['xbBut']
  75. ltsBut = dict['ltsBut']
  76. rtsBut = dict['rtsBut']
  77. ldPad = dict['ldPad']
  78. rdPad = dict['rdPad']
  79. udPad = dict['udPad']
  80. ddPad = dict['ddPad']
  81. try:
  82. pause_state = dict['npause']
  83. last_pause = dict['last_npause']
  84. except:
  85. dict['npause'] = 0
  86. dict['last_npause'] = 0
  87. pause_state = 0
  88. last_pause = 0
  89. if own["playback"] != True:
  90. Record.main(recording_cutoff, cube)
  91. #if cont.sensors[save_recording_sensor].positive:
  92. #SortData.writeData.saveAll()
  93. #if cont.sensors[load_recording_sensor].positive or (cube["sel"] == 1 and cube["last_sel"] == 0):
  94. if own['back_state'] == 1 and back_on == 1 and last_back == 0:
  95. cube["last_sel"] == 1
  96. SortData.writeData.saveAll()
  97. own["playback"] = True
  98. own["playbackBroken"] = False
  99. freecam.worldPosition = own.worldPosition
  100. followcam.worldPosition = own.worldPosition
  101. cube['grindcement_vol'] = 0
  102. cube['grindcement_pitch'] = 0
  103. cube['grindrail_vol'] = 0
  104. cube['grindrail_pitch'] = 0
  105. cube['sroll_vol'] = 0
  106. cube['sroll_pitch'] = 0
  107. if own["playback"]:
  108. Record.loadData()
  109. #..................
  110. # if cont.sensors[track_left_sensor].positive:
  111. # own["objIndex"] -= 2
  112. # logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  113. # if cont.sensors[track_right_sensor].positive:
  114. # own["objIndex"] += 2
  115. # logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  116. if own["playback"] == True:
  117. #print("objIndex = ", own["lengthPos"], own['objIndex'])
  118. if rTrig > .01 and rTrig < .02:
  119. own["objIndex"] += 2
  120. logic.setLogicTicRate(frame_rate*.5)
  121. if (rTrig >= .02 and rTrig < .06) or own['loop_play'] == 1:
  122. own["objIndex"] += 2
  123. logic.setLogicTicRate(frame_rate*1)
  124. #print(own['objIndex'])
  125. if rTrig >= .06 and rTrig < .09:
  126. own["objIndex"] += 2
  127. logic.setLogicTicRate(frame_rate*1.5)
  128. if lTrig > .01 and lTrig < .02:
  129. own["objIndex"] -= 2
  130. logic.setLogicTicRate(frame_rate*.5)
  131. if lTrig >= .02 and lTrig < .06:
  132. own["objIndex"] -= 2
  133. logic.setLogicTicRate(frame_rate*1)
  134. if lTrig >= .06 and lTrig < .09:
  135. if own['loop_play'] == 1:
  136. own["objIndex"] -= 6
  137. #logic.setLogicTicRate(frame_rate*1.5)
  138. else:
  139. own["objIndex"] -= 2
  140. logic.setLogicTicRate(frame_rate*1.5)
  141. if b_on == True and pause_state == 0:
  142. #print("bbut_on")
  143. own['objIndex'] = 0
  144. own['valueIndex'] = 0
  145. logic.setLogicTicRate(frame_rate*1)
  146. #....................
  147. if allow_playback_break:
  148. if own['back_state'] == 0 and back_on == 1 and last_back == 0:
  149. own["playbackBroken"] = True
  150. own["playback"] = False
  151. elif own["playbackBroken"] and back_on == 0:
  152. Record.breakOut()
  153. logic.setLogicTicRate(frame_rate)
  154. #set value index
  155. own.state = recorder_state
  156. own["playbackBroken"] = False
  157. skater.stopAction(9999)
  158. deck.stopAction(9999)
  159. trucks.stopAction(9999)
  160. cont.activate(own.actuators['replayCam'])
  161. #print("unbreak")
  162. own['loop_play'] = 0
  163. #print("valueIndex = ", own['valueIndex'])
  164. if back_on == 1 and own['back_but'] == 0:
  165. #print("change back state")
  166. if own['back_state'] == True:
  167. own['back_state'] = False
  168. #elif own['back_state'] == False:
  169. else:
  170. own['back_state'] = True
  171. ###
  172. if own['last_playback'] != own['playback']:
  173. if own['last_playback'] == True:
  174. cont.activate(own.actuators['remove_hud'])
  175. cont.activate(own.actuators['add_stance'])
  176. own['camnum'] = 0
  177. cam = camList["Camera.003"]
  178. scene.active_camera = cam
  179. #print("turning replay off", own['playback'])
  180. if own['last_playback'] == False:
  181. #print("turning replay on", own['playback'])
  182. cont.activate(own.actuators['add_hud'])
  183. cont.activate(own.actuators['remove_stance'])
  184. own['objIndex'] = 0
  185. own['valueIndex'] = 3
  186. logic.setLogicTicRate(frame_rate*1)
  187. if dict['rtsBut'] == False and dict['last_rtsBut'] == True and own['playback'] == True:
  188. if 'pause' in scene_list:
  189. #cont.activate(own.actuators['remove_overlay'])
  190. cont.activate(own.actuators['add_hud'])
  191. else:
  192. #cont.activate(own.actuators['add_overlay']) #pause
  193. cont.activate(own.actuators['remove_hud']) #replay
  194. cont.activate(own.actuators['pause_replay_remove'])
  195. if pause_state == 1 and last_pause == 1 and own["playback"]:
  196. #print('pause_on')
  197. if 'pause_replay' not in scene_list:
  198. cont.activate(own.actuators['pause_replay_add'])
  199. #print('pause_on')
  200. if pause_state != 1 and own["playback"]:
  201. if 'pause_replay' in scene_list:
  202. cont.activate(own.actuators['pause_replay_remove'])
  203. if own['playback'] and 'pause' in scene_list:
  204. cont.activate(cube.actuators['remove_overlay'])
  205. ####
  206. if a_on == 1 and own['a_but'] == False and pause_state == 0:
  207. if own['loop_play'] == 1:
  208. own['loop_play'] = 0
  209. else:
  210. own['loop_play'] = 1
  211. if rLR > .05 and own["playback"]:
  212. act = cont.actuators["replayCam"]
  213. if rLR > .07:
  214. act.dLoc = [ .06, 0.0, 0.0]
  215. else:
  216. act.dLoc = [ .03, 0.0, 0.0]
  217. #cont.deactivate(own.actuators['Camera'])
  218. cont.activate(own.actuators['replayCam'])
  219. #print("move")
  220. elif rLR < -.05 and own["playback"]:
  221. act = cont.actuators["replayCam"]
  222. if rLR < -.07:
  223. act.dLoc = [ -.06, 0.0, 0.0]
  224. else:
  225. act.dLoc = [ -.03, 0.0, 0.0]
  226. #cont.deactivate(own.actuators['Camera'])
  227. #act.damping = 6
  228. cont.activate(own.actuators['replayCam'])
  229. #print("move")
  230. else:
  231. #pass
  232. cont.deactivate(own.actuators['replayCam'])
  233. #cont.activate(own.actuators['Camera'])
  234. #print("back state: ", own['back_state'], "last_back_but: ", own['last_back_but'], "back_but :", own['back_but'])
  235. #integer
  236. #
  237. #0 = +X axis
  238. #
  239. #1 = +Y axis
  240. #
  241. #2 = +Z axis
  242. #
  243. #3 = -X axis
  244. #
  245. #4 = -Y axis
  246. #
  247. #5 = -Z axis
  248. # if rLR > .05 and own["playback"]:
  249. # if own['last_rtsBut'] == True and rtsBut == False:
  250. # if replay_cam_axis == 0:
  251. # replay_cam_axis = 1
  252. # elif replay_cam_axis == 1:
  253. # replay_cam_axis = 3
  254. # elif replay_cam_axis == 3 :
  255. # replay_cam_axis = 4
  256. # elif replay_cam_axis == 4:
  257. # replay_cam_axis = 0
  258. # cam.axis = replay_cam_axis
  259. # cont.activate(cam)
  260. # print("set replay_cam_axis: ", replay_cam_axis)
  261. # own['replay_cam_axis'] = replay_cam_axis
  262. if own['last_ltsBut'] == True and ltsBut == False and own['playback']:
  263. # get camera named SecurityCam
  264. if own['camnum'] == 1:
  265. own['camnum'] = 2
  266. elif own['camnum'] == 0:
  267. own['camnum'] = 1
  268. elif own['camnum'] == 2:
  269. own['camnum'] = 0
  270. if own['last_rtsBut'] == True and rtsBut == False and own['playback']:
  271. # get camera named SecurityCam
  272. if "replay_HUD" in scene_list:
  273. cont.activate(own.actuators['remove_hud'])
  274. else:
  275. cont.activate(own.actuators['add_hud'])
  276. if own['camnum'] == 1 and own['playback']:
  277. scene.active_camera = followcam
  278. #################
  279. camspeed1 = .04 #.015
  280. camspeed2 = .1 #.055
  281. camrot1 = .02 #.005
  282. camrot2 = .04 #.02
  283. # perc = (lUD * 100 * (10 / 80)) *2
  284. # perc = round(perc,2)
  285. # print(perc)
  286. # perc = .025 * perc
  287. # newUD = (lUD * .1) * 5
  288. # if lUD > .0005 or lUD < -.0005:
  289. # camspeed1 = abs(perc)
  290. # camspeed2 = abs(perc)
  291. #up
  292. if lUD < -0.080:
  293. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  294. cont.activate(followcam.actuators["up"])
  295. print("fastup")
  296. else:
  297. cont.deactivate(followcam.actuators["up"])
  298. # #down
  299. if lUD > .080:
  300. followcam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  301. cont.activate(followcam.actuators["down"])
  302. else:
  303. cont.deactivate(followcam.actuators["down"])
  304. # #left
  305. if lLR < -0.080:
  306. followcam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  307. cont.activate(followcam.actuators["left"])
  308. else:
  309. cont.deactivate(followcam.actuators["left"])
  310. # #right
  311. if lLR > 0.080:
  312. followcam.actuators["right"].dLoc = [camspeed2, 0, 0]
  313. cont.activate(followcam.actuators["right"])
  314. else:
  315. cont.deactivate(followcam.actuators["right"])
  316. #up
  317. if rUD < -0.080:
  318. followcam.actuators["rotup"].dLoc = [0, 0, camrot2]
  319. cont.activate(followcam.actuators["rotup"])
  320. #print("uppppppppppppppppppppppppppp")
  321. else:
  322. cont.deactivate(followcam.actuators["rotup"])
  323. # #down
  324. if rUD > .080:
  325. followcam.actuators["rotdown"].dLoc = [0, 0, -camrot2]
  326. cont.activate(followcam.actuators["rotdown"])
  327. else:
  328. cont.deactivate(followcam.actuators["rotdown"])
  329. # #left
  330. if rLR < -0.080:
  331. followcam.actuators["rotleft"].dRot = [0, 0, camrot2]
  332. cont.activate(followcam.actuators["rotleft"])
  333. else:
  334. cont.deactivate(followcam.actuators["rotleft"])
  335. # #right
  336. if rLR > 0.080:
  337. followcam.actuators["rotright"].dRot = [0, 0, -camrot2]
  338. cont.activate(followcam.actuators["rotright"])
  339. else:
  340. cont.deactivate(followcam.actuators["rotright"])
  341. #*********************************************
  342. if lUD > -0.080 and lUD < -0.030:
  343. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  344. cont.activate(followcam.actuators["up"])
  345. #print(lUD)
  346. else:
  347. cont.deactivate(followcam.actuators["up"])
  348. # #down
  349. if lUD < .080 and lUD > .03:
  350. followcam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  351. cont.activate(followcam.actuators["down"])
  352. else:
  353. cont.deactivate(followcam.actuators["down"])
  354. # #left
  355. if lLR > -0.080 and lLR < -0.030:
  356. followcam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  357. cont.activate(followcam.actuators["left"])
  358. else:
  359. cont.deactivate(followcam.actuators["left"])
  360. # #right
  361. if lLR < .080 and lLR > .03:
  362. followcam.actuators["right"].dLoc = [camspeed1, 0, 0]
  363. cont.activate(followcam.actuators["right"])
  364. else:
  365. cont.deactivate(followcam.actuators["right"])
  366. #up
  367. if rUD > -0.080 and rUD < -0.030:
  368. followcam.actuators["rotup"].dRot = [camrot1, 0, 0]
  369. cont.activate(followcam.actuators["rotup"])
  370. else:
  371. cont.deactivate(followcam.actuators["rotup"])
  372. # #down
  373. if rUD < .080 and rUD > .03:
  374. followcam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  375. cont.activate(followcam.actuators["rotdown"])
  376. else:
  377. cont.deactivate(followcam.actuators["rotdown"])
  378. # #left
  379. if rLR > -0.080 and rLR < -0.030:
  380. followcam.actuators["rotleft"].dRot = [0, 0, camrot1]
  381. cont.activate(followcam.actuators["rotleft"])
  382. else:
  383. cont.deactivate(followcam.actuators["rotleft"])
  384. # #right
  385. if rLR < .080 and rLR > .03:
  386. followcam.actuators["rotright"].dRot = [0, 0, -camrot1]
  387. cont.activate(followcam.actuators["rotright"])
  388. else:
  389. cont.deactivate(followcam.actuators["rotright"])
  390. #################
  391. if own['camnum'] == 2 and own['playback']:
  392. scene.active_camera = freecam
  393. #act = freecam.actuators[
  394. camspeed1 = .015
  395. camspeed2 = .055
  396. camrot1 = .005
  397. camrot2 = .02
  398. #up
  399. if lUD < -0.080:
  400. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  401. cont.activate(freecam.actuators["up"])
  402. #print("fastup")
  403. else:
  404. cont.deactivate(freecam.actuators["up"])
  405. # #down
  406. if lUD > .080:
  407. freecam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  408. cont.activate(freecam.actuators["down"])
  409. else:
  410. cont.deactivate(freecam.actuators["down"])
  411. # #left
  412. if lLR < -0.080:
  413. freecam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  414. cont.activate(freecam.actuators["left"])
  415. else:
  416. cont.deactivate(freecam.actuators["left"])
  417. # #right
  418. if lLR > 0.080:
  419. freecam.actuators["right"].dLoc = [camspeed2, 0, 0]
  420. cont.activate(freecam.actuators["right"])
  421. else:
  422. cont.deactivate(freecam.actuators["right"])
  423. #up
  424. if rUD < -0.080:
  425. freecam.actuators["rotup"].dRot = [camrot2, 0, 0]
  426. cont.activate(freecam.actuators["rotup"])
  427. else:
  428. cont.deactivate(freecam.actuators["rotup"])
  429. # #down
  430. if rUD > .080:
  431. freecam.actuators["rotdown"].dRot = [-camrot2, 0, 0]
  432. cont.activate(freecam.actuators["rotdown"])
  433. else:
  434. cont.deactivate(freecam.actuators["rotdown"])
  435. # #left
  436. if rLR < -0.080:
  437. freecam.actuators["rotleft"].dRot = [0, 0, camrot2]
  438. cont.activate(freecam.actuators["rotleft"])
  439. else:
  440. cont.deactivate(freecam.actuators["rotleft"])
  441. # #right
  442. if rLR > 0.080:
  443. freecam.actuators["rotright"].dRot = [0, 0, -camrot2]
  444. cont.activate(freecam.actuators["rotright"])
  445. else:
  446. cont.deactivate(freecam.actuators["rotright"])
  447. #*********************************************
  448. if lUD > -0.080 and lUD < -0.030:
  449. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  450. cont.activate(freecam.actuators["up"])
  451. #print(lUD)
  452. else:
  453. cont.deactivate(freecam.actuators["up"])
  454. # #down
  455. if lUD < .080 and lUD > .03:
  456. freecam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  457. cont.activate(freecam.actuators["down"])
  458. else:
  459. cont.deactivate(freecam.actuators["down"])
  460. # #left
  461. if lLR > -0.080 and lLR < -0.030:
  462. freecam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  463. cont.activate(freecam.actuators["left"])
  464. else:
  465. cont.deactivate(freecam.actuators["left"])
  466. # #right
  467. if lLR < .080 and lLR > .03:
  468. freecam.actuators["right"].dLoc = [camspeed1, 0, 0]
  469. cont.activate(freecam.actuators["right"])
  470. else:
  471. cont.deactivate(freecam.actuators["right"])
  472. #up
  473. if rUD > -0.080 and rUD < -0.030:
  474. freecam.actuators["rotup"].dRot = [camrot1, 0, 0]
  475. cont.activate(freecam.actuators["rotup"])
  476. else:
  477. cont.deactivate(freecam.actuators["rotup"])
  478. # #down
  479. if rUD < .080 and rUD > .03:
  480. freecam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  481. cont.activate(freecam.actuators["rotdown"])
  482. else:
  483. cont.deactivate(freecam.actuators["rotdown"])
  484. # #left
  485. if rLR > -0.080 and rLR < -0.030:
  486. freecam.actuators["rotleft"].dRot = [0, 0, camrot1]
  487. cont.activate(freecam.actuators["rotleft"])
  488. else:
  489. cont.deactivate(freecam.actuators["rotleft"])
  490. # #right
  491. if rLR < .080 and rLR > .03:
  492. freecam.actuators["rotright"].dRot = [0, 0, -camrot1]
  493. cont.activate(freecam.actuators["rotright"])
  494. else:
  495. cont.deactivate(freecam.actuators["rotright"])
  496. #print('doing the keyframe stuff')
  497. anim_length = dict['replay_record_length']
  498. def clock(freecam, inc):
  499. pass
  500. def transLength(freecam, keyframes, id, kl):
  501. if id != 0:
  502. num = keyframes[id] - keyframes[(id-1)]
  503. else:
  504. tn = anim_length - keyframes[kl]
  505. num = tn + keyframes[0]
  506. freecam['last_position'] = kl
  507. return num
  508. def getProgress(freecam):
  509. if freecam['cur_key'] != freecam['last_key']:
  510. print('new key!')
  511. freecam['pg'] = 0
  512. else:
  513. num = own['objIndex'] - own['last_objIndex']
  514. #print(num)
  515. #freecam['clock'] += num
  516. #print(num)
  517. if num > 4:
  518. num = 2
  519. if num < -4:
  520. num = -2
  521. #print('-------************num is biiig')
  522. freecam['pg'] += num
  523. freecam['last_key'] = freecam['cur_key']
  524. def draw_keys(keyframes, dict):
  525. scene_list = bge.logic.getSceneList()
  526. if 'replay_HUD' in scene_list:
  527. hud = scene_list['replay_HUD']
  528. ph = hud.objects['Circle']
  529. for x in hud.objects:
  530. if 'keyframe' in x:
  531. x.endObject()
  532. for y in keyframes:
  533. place = (y / round((dict['replay_record_length']), 4) * 1000)
  534. print('action frame', place)
  535. added = hud.addObject('kf', ph)
  536. added.scaling = [1.25,1,1]
  537. added.playAction("replay_playhead", place, place, layer=1, play_mode=1, speed=0)
  538. else:
  539. print('no hud scene')
  540. keyframes = dict['rp_keyframes']
  541. positions = dict['rp_positions']
  542. orientations = dict['rp_orientations']
  543. if 'inited' not in freecam:
  544. freecam['inited'] = True
  545. freecam['clock'] = 0
  546. freecam['cur_key'] = 0
  547. freecam['last_key'] = -1
  548. freecam['cur_length'] = 0
  549. freecam['pg'] = 0
  550. freecam['last_position'] = 0
  551. freecam['playback'] = True
  552. if len(positions) > 1:
  553. kl = len(keyframes) - 1
  554. freecam['cur_length'] = transLength(freecam, keyframes, freecam['cur_key'], kl)
  555. getProgress(freecam)
  556. skip = False
  557. if own["objIndex"] > keyframes[kl]:
  558. skip = True
  559. #skip = False
  560. #print('skipping')
  561. if freecam['cur_key'] != 0:
  562. if keyframes[(freecam['cur_key'] - 1)] > own['objIndex']:
  563. freecam['cur_key'] -= 1
  564. freecam['last_position'] -= 1
  565. if freecam['last_position'] == -1:
  566. freecam['last_position'] = keyframes.len() - 1
  567. print('backwards')
  568. if keyframes[freecam['cur_key']] > own["objIndex"]:
  569. pass
  570. else:
  571. if skip == False:
  572. try:
  573. freecam['last_position'] = freecam['cur_key']
  574. freecam['cur_key'] += 1
  575. temp = keyframes[freecam['cur_key']]
  576. if freecam['cur_key'] != 0:
  577. freecam['pg'] = 0
  578. print('setting pg to 0')
  579. except:
  580. print('excepting')
  581. freecam['cur_key'] = 0
  582. freecam['last_position'] = kl
  583. freecam['pg'] = 0
  584. time = abs(round(freecam['pg'] / freecam['cur_length'], 6) )
  585. if own['objIndex'] != own['last_objIndex']:
  586. freecam.worldPosition = (positions[freecam['last_position']].lerp(positions[freecam['cur_key']], time))
  587. freecam.worldOrientation = (orientations[freecam['last_position']].lerp(orientations[freecam['cur_key']], time))
  588. #print(positions)
  589. #print(positions[freecam['last_position']], positions[freecam['cur_key']])
  590. #print('cur_key', freecam['cur_key'], freecam['last_position'], 'time: ', own["objIndex"], freecam['cur_length'], freecam['pg'], time)
  591. else:
  592. pass
  593. #print('not enough keys')
  594. if dict['xBut'] == 1 and dict['last_xBut'] == 0:
  595. print('chekcing for keyframe on', own['objIndex'])
  596. if len(keyframes) > 1:
  597. close = min(keyframes, key=lambda x:abs(x-own['objIndex']))
  598. keys_away = abs(close - own['objIndex'])
  599. else:
  600. close = None
  601. keys_away = 100000
  602. print('--', close, keys_away)
  603. if keys_away < 60:
  604. print('index already exists')
  605. ind = keyframes.index(close)
  606. positions.pop(ind)
  607. orientations.pop(ind)
  608. keyframes.pop(ind)
  609. dict['rp_keyframes'] = keyframes
  610. dict['rp_positions'] = positions
  611. dict['rp_orientations'] = orientations
  612. if freecam['cur_key'] != 0:
  613. freecam['cur_key'] -= 1
  614. else:
  615. freecam['cur_key'] = len(keyframes) -1
  616. draw_keys(keyframes, dict)
  617. else:
  618. keyframes.append(own['objIndex'])
  619. positions.append(freecam.worldPosition.copy())
  620. orientations.append(freecam.worldOrientation.copy())
  621. tk = keyframes
  622. z = [x for _,x in sorted(zip(keyframes, positions))]
  623. v = [y for _,y in sorted(zip(tk, orientations))]
  624. positions = z
  625. orientations = v
  626. keyframes.sort()
  627. print('added keyframe on', own['objIndex'])
  628. dict['rp_keyframes'] = keyframes
  629. if own['objIndex'] in positions:
  630. freecam['cur_key'] = positions.index(own['objIndex'])
  631. # freecam['cur_length'] = freecam['cur_key']
  632. # try:
  633. # freecam['last_position'] = positions.index(own['objIndex']) -1
  634. # except:
  635. # freecam['last_position'] = len(positions) - 1
  636. dict['rp_keyframes'] = keyframes
  637. dict['rp_positions'] = positions
  638. dict['rp_orientations'] = orientations
  639. draw_keys(keyframes, dict)
  640. #print('lp', dict['temp_list'])
  641. ########################################
  642. if own['camnum'] == 0:
  643. cam = camList["Camera.003"]
  644. scene.active_camera = cam
  645. dict['rp_keyframes'] = []
  646. dict['rp_positions'] = []
  647. dict['rp_orientations'] = []
  648. freecam['cur_key'] = 0
  649. if dict['npause'] == False:
  650. freecam.worldOrientation = cam.worldOrientation
  651. valueIndex = own['valueIndex']
  652. n = (valueIndex / recording_cutoff) * 1000
  653. n = int(round(n))
  654. #n = 10
  655. #print("n: ", n, "--", valueIndex, recording_cutoff)
  656. #print(valueIndex, 'valueIndex from Manager.py', dict['frame'])
  657. #dict = logic.globalDict #Get the global dictionary
  658. dict['playhead'] = n
  659. own['last_back_but'] = own['back_but']
  660. own['back_but'] = back_on
  661. own['last_a_but'] = own['a_but']
  662. own['a_but'] = a_on
  663. own['last_ltsBut'] = ltsBut
  664. own['last_rtsBut'] = rtsBut
  665. own['last_playback'] = own['playback']
  666. own['last_objIndex'] = own['objIndex']
  667. dict['playback'] = own['playback']
  668. # if own["playback"] == True:
  669. # la = 10
  670. # p = []
  671. # it = 0
  672. # while it < la:
  673. # if dict['p1'].isPlayingAction(it):
  674. # p.append(it)
  675. # it += 1
  676. # print(p)