--- a/main.py +++ b/main.py @@ -8,6 +8,17 @@ from os import path from random import randint +# FredyGames: the web player keeps this folder in the browser (IndexedDB), so the best scores survive; on the +# desktop it does not exist and the scores stay in ./scores.json as before. On the web the Q key (quit) is turned +# off too: quitting only freezes the page. +WEB_SAVE_DIR = '/saves/arkaway' + + +def scores_file(): + if path.isdir(WEB_SAVE_DIR): + return path.join(WEB_SAVE_DIR, 'scores.json') + return 'scores.json' + def centerText(text, posy, color): '''Centra un texto en pantalla''' @@ -49,7 +60,7 @@ pyxel.init(globals.SCREEN_W, globals.SCREEN_H, title="Arkaway", display_scale=3, capture_scale=3, capture_sec=20, - quit_key=pyxel.KEY_Q) + quit_key=(pyxel.KEY_NONE if path.isdir(WEB_SAVE_DIR) else pyxel.KEY_Q)) pyxel.load('assets.pyxres') pyxel.run(self.update, self.draw) @@ -283,13 +294,13 @@ self.ball.cur_map = globals.cur_map def saveScore(self): - with open('scores.json', 'w') as save: + with open(scores_file(), 'w') as save: json.dump(self.best_score, save, sort_keys=True, indent=4) save.close() def getScore(self): try: - with open('scores.json', 'r') as f: + with open(scores_file(), 'r') as f: self.best_score = json.load(f) except FileNotFoundError: self.best_score = {