-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_game.py
153 lines (136 loc) · 4.27 KB
/
run_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# pyright: reportUnusedImport=false
# The launching script needs to be Python 2.X compatible so that it can tell people to upgrade ;)
from __future__ import print_function
import os
import shlex
import subprocess
import sys
import time
from pathlib import Path
if sys.version_info[0] > 2:
from typing import List
raw_input = input
missing_deps_text = ''
missing_deps = [] # type: List[str]
if sys.version_info[:2] < (3, 9):
print('Python 3.9 or later is required to run this game.')
raw_input('Press ENTER to exit...')
sys.exit(1)
has_pygame_20 = True
try:
import pygame
except ModuleNotFoundError:
has_pygame_20 = False
else:
import pygame.version
if pygame.version.vernum[:2] < (2, 0):
has_pygame_20 = False
if not has_pygame_20:
missing_deps_text += ' - Pygame 2.0 or later (pygame>=2.0)\n'
missing_deps.append('pygame>=2.0')
has_janus = True
try:
import janus
except ModuleNotFoundError:
has_janus = False
if not has_janus:
missing_deps_text += ' - janus (janus)\n'
missing_deps.append('janus')
has_colorama = True
try:
import colorama
except ModuleNotFoundError:
has_colorama = False
if not has_colorama:
missing_deps_text += ' - Colorama (colorama)\n'
missing_deps.append('colorama')
has_cryptography = True
try:
import cryptography
except ModuleNotFoundError:
has_cryptography = False
if not has_cryptography:
missing_deps_text += ' - Cryptography (cryptography)\n'
missing_deps.append('cryptography')
has_aiohttp = True
try:
import aiohttp
except ModuleNotFoundError:
has_aiohttp = False
if not has_aiohttp:
missing_deps_text += ' - Asynchronous HTTP (aiohttp)\n'
missing_deps.append('aiohttp')
has_zxcvbn = True
try:
import zxcvbn
except ModuleNotFoundError:
has_zxcvbn = False
if not has_zxcvbn:
missing_deps_text += ' - Password strength checker (zxcvbn)\n'
missing_deps.append('zxcvbn')
has_aiofiles = True
try:
import aiofiles
except ModuleNotFoundError:
has_aiofiles = False
if not has_aiofiles:
missing_deps_text += ' - Asynchronous files (aiofiles)\n'
missing_deps.append('aiofiles')
has_opensimplex = True
try:
import opensimplex
except ModuleNotFoundError:
has_opensimplex = False
if not has_opensimplex:
missing_deps_text += ' - OpenSimplex Noise (opensimplex)\n'
missing_deps.append('opensimplex')
has_humanize = True
try:
import humanize
except ModuleNotFoundError:
has_humanize = False
if not has_humanize:
missing_deps_text += ' - Humanizer (humanize)\n'
missing_deps.append('humanize')
has_typing_extensions_410 = True
try:
from typing_extensions import Never, Self
except ImportError:
has_typing_extensions_410 = False
if not has_typing_extensions_410:
missing_deps_text += ' - typing_extensions 4.1.0 or later (typing_extensions>=4.1.0)\n'
missing_deps.append('typing_extensions>=4.1.0')
if missing_deps:
print('You appear to be missing the following requirements for this game to run:')
print(missing_deps_text, end='')
yes = input('Would you like to install them? [Y/n] ')
if not yes or yes[0].lower() == 'y':
args = [sys.executable, '-m', 'pip', 'install', '-U'] + missing_deps
print(shlex.join(args))
result = subprocess.run(args)
if result.returncode != 0:
print('Install failed with return code', result.returncode)
sys.exit(1)
else:
print('Installation cancelled.')
sys.exit(0)
GAME_DIR = Path(__file__).parent
if GAME_DIR.is_file() and os.path.splitext(GAME_DIR)[1].lower() == '.pyz':
# Extract files from PYZ
date_for_refresh = GAME_DIR.stat().st_mtime
import zipfile
with zipfile.ZipFile(GAME_DIR, 'r') as zfp:
print('Extracting files from PYZ...')
start = time.perf_counter()
files_list = [
f for f in zfp.namelist()
if f.startswith('assets/') or f.startswith('and_beyond/')
if not os.path.exists(f) or os.path.getmtime(f) <= date_for_refresh
]
zfp.extractall(members=files_list)
end = time.perf_counter()
print('Extracted', len(files_list), 'files from PYZ in', end - start, 'seconds')
if '--debug' in sys.argv:
print('Extracted:', files_list)
sys.path.insert(0, '.')
import and_beyond.client.main