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.

SortData.py 20KB

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