Path
This commit is contained in:
parent
a1ea7572f1
commit
d29d269588
@ -17,7 +17,7 @@ terminis [level]
|
|||||||
|
|
||||||
You can change keys by editing:
|
You can change keys by editing:
|
||||||
* `%appdata%\Terminis\config.cfg` on Windows
|
* `%appdata%\Terminis\config.cfg` on Windows
|
||||||
* `~/.local/share/Terminis/config.cfg` on Linux
|
* `$XDG_CONFIG_HOME/Terminis/config.cfg` or `~/.config/Terminis/config.cfg` on Linux
|
||||||
|
|
||||||
Acceptable values:
|
Acceptable values:
|
||||||
* printable characters (`q`, `*`, ` `...)
|
* printable characters (`q`, `*`, ` `...)
|
||||||
|
@ -14,15 +14,15 @@ import time
|
|||||||
import os
|
import os
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
|
DIR_NAME = "Terminis"
|
||||||
WIN_DIR = "~/Appdata/Roaming/Terminis/"
|
|
||||||
LINUX_DIR = "~/.local/share/"
|
|
||||||
|
|
||||||
|
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
dir_path = os.path.expanduser(WIN_DIR)
|
DATA_PATH = os.environ.get("appdata", os.path.expanduser("~\Appdata\Roaming"))
|
||||||
|
CONFIG_PATH = DATA_PATH
|
||||||
else:
|
else:
|
||||||
dir_path = os.path.expanduser(LINUX_DIR)
|
DATA_PATH = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
|
||||||
|
CONFIG_PATH = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
|
||||||
|
DATA_PATH = os.path.join(DATA_PATH, DIR_NAME)
|
||||||
|
CONFIG_PATH = os.path.join(CONFIG_PATH, DIR_NAME)
|
||||||
|
|
||||||
|
|
||||||
class Rotation:
|
class Rotation:
|
||||||
@ -413,7 +413,7 @@ class Stats(Window):
|
|||||||
LINES_CLEARED_NAMES = ("", "SINGLE", "DOUBLE", "TRIPLE", "TETRIS")
|
LINES_CLEARED_NAMES = ("", "SINGLE", "DOUBLE", "TRIPLE", "TETRIS")
|
||||||
TITLE = "STATS"
|
TITLE = "STATS"
|
||||||
FILE_NAME = ".high_score"
|
FILE_NAME = ".high_score"
|
||||||
file_path = os.path.join(dir_path, FILE_NAME)
|
FILE_PATH = os.path.join(DATA_PATH, FILE_NAME)
|
||||||
|
|
||||||
def __init__(self, game, width, height, begin_x, begin_y, level):
|
def __init__(self, game, width, height, begin_x, begin_y, level):
|
||||||
self.game = game
|
self.game = game
|
||||||
@ -430,7 +430,7 @@ class Stats(Window):
|
|||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
try:
|
try:
|
||||||
with open(self.file_path, "r") as f:
|
with open(self.FILE_PATH, "r") as f:
|
||||||
self.high_score = int(f.read())
|
self.high_score = int(f.read())
|
||||||
except:
|
except:
|
||||||
self.high_score = 0
|
self.high_score = 0
|
||||||
@ -497,9 +497,11 @@ class Stats(Window):
|
|||||||
else:
|
else:
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
if not os.path.exists(DATA_PATH):
|
||||||
|
os.mkdir(DATA_PATH)
|
||||||
try:
|
try:
|
||||||
with open(self.file_path, mode='w') as f:
|
with open(self.FILE_PATH, mode='w') as f:
|
||||||
f.write(str(self.high_score))
|
f.write(str(self.high_score))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("High score could not be saved:")
|
print("High score could not be saved:")
|
||||||
@ -509,7 +511,7 @@ class Stats(Window):
|
|||||||
class Config(Window, configparser.SafeConfigParser):
|
class Config(Window, configparser.SafeConfigParser):
|
||||||
TITLE = "CONTROLS"
|
TITLE = "CONTROLS"
|
||||||
FILE_NAME = "config.cfg"
|
FILE_NAME = "config.cfg"
|
||||||
file_path = os.path.join(dir_path, FILE_NAME)
|
FILE_PATH = os.path.join(CONFIG_PATH, FILE_NAME)
|
||||||
|
|
||||||
def __init__(self, width, height, begin_x, begin_y):
|
def __init__(self, width, height, begin_x, begin_y):
|
||||||
configparser.SafeConfigParser.__init__(self)
|
configparser.SafeConfigParser.__init__(self)
|
||||||
@ -524,16 +526,18 @@ class Config(Window, configparser.SafeConfigParser):
|
|||||||
self.set("CONTROLS", "HOLD", "h")
|
self.set("CONTROLS", "HOLD", "h")
|
||||||
self.set("CONTROLS", "PAUSE", "p")
|
self.set("CONTROLS", "PAUSE", "p")
|
||||||
self.set("CONTROLS", "QUIT", "q")
|
self.set("CONTROLS", "QUIT", "q")
|
||||||
if os.path.exists(self.file_path):
|
if os.path.exists(self.FILE_PATH):
|
||||||
self.read(self.file_path)
|
self.read(self.FILE_PATH)
|
||||||
for action, key in self.items("CONTROLS"):
|
for action, key in self.items("CONTROLS"):
|
||||||
if key == "":
|
if key == "":
|
||||||
self.set("CONTROLS", action, " ")
|
self.set("CONTROLS", action, " ")
|
||||||
else:
|
else:
|
||||||
|
if not os.path.exists(CONFIG_PATH):
|
||||||
|
os.mkdir(CONFIG_PATH)
|
||||||
try:
|
try:
|
||||||
with open(self.file_path, 'w') as f:
|
with open(self.FILE_PATH, 'w') as f:
|
||||||
f.write(
|
f.write(
|
||||||
"""# Acceptable values are printable characters ("q", "*"...) and curses's constants name starting with "KEY_"
|
"""# Acceptable values are printable characters ("q", "*", " "...) and curses's constants name starting with "KEY_"
|
||||||
# See https://docs.python.org/3/library/curses.html?highlight=curses#constants
|
# See https://docs.python.org/3/library/curses.html?highlight=curses#constants
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -705,11 +709,6 @@ def main():
|
|||||||
else:
|
else:
|
||||||
level = 1
|
level = 1
|
||||||
|
|
||||||
try:
|
|
||||||
os.mkdir(dir_path)
|
|
||||||
except FileExistsError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
with Screen() as scr:
|
with Screen() as scr:
|
||||||
game = Game(scr, level)
|
game = Game(scr, level)
|
||||||
game.play()
|
game.play()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user