Compare commits
10 Commits
bf3392236a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
4d32ff6f5a
|
|||
| dee653ca31 | |||
| 32aa61533c | |||
| 214edfbe3a | |||
| 1b84249f47 | |||
| 89241c2939 | |||
| 77406db737 | |||
| f324848c19 | |||
| 48bd8126a5 | |||
| 1cbf9ef2af |
111
__main__.py
111
__main__.py
@ -7,13 +7,11 @@ import attr
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# TODO: Auto install game requirements
|
# TODO: Add Discord rich presence
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
log = logging.getLogger('PainJamLauncher')
|
log = logging.getLogger('PainJamLauncher')
|
||||||
|
|
||||||
print(sys.executable)
|
|
||||||
|
|
||||||
# Store the current working directory
|
# Store the current working directory
|
||||||
# This is used to revert the cd change
|
# This is used to revert the cd change
|
||||||
originalCWD = os.getcwd()
|
originalCWD = os.getcwd()
|
||||||
@ -24,6 +22,7 @@ parser.add_argument('-sw', '--width', type=int, default=1280)
|
|||||||
parser.add_argument('-sh', '--height', type=int, default=720)
|
parser.add_argument('-sh', '--height', type=int, default=720)
|
||||||
parser.add_argument('-fps', '--fpsCap', type=int, default=60)
|
parser.add_argument('-fps', '--fpsCap', type=int, default=60)
|
||||||
parser.add_argument('-f', '--fullscreen', action='store_true')
|
parser.add_argument('-f', '--fullscreen', action='store_true')
|
||||||
|
parser.add_argument('gameID', nargs='?', type=str, default=None)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
@ -54,46 +53,78 @@ for path in os.listdir('../'):
|
|||||||
|
|
||||||
log.debug(f'Loaded game {gameID}')
|
log.debug(f'Loaded game {gameID}')
|
||||||
|
|
||||||
|
|
||||||
screen = pygame.display.set_mode((args.width, args.height))
|
|
||||||
gameSurface = pygame.Surface(screen.size)
|
|
||||||
|
|
||||||
run = True
|
|
||||||
currentGame = None
|
|
||||||
|
|
||||||
def loadGame(game):
|
|
||||||
# Set the current working directory
|
|
||||||
# to the base path of the game
|
|
||||||
os.chdir(game.path)
|
|
||||||
spec = importlib.util.spec_from_file_location(game.id, os.path.join(game.path, 'game.py'))
|
|
||||||
foo = importlib.util.module_from_spec(spec)
|
|
||||||
spec.loader.exec_module(foo)
|
|
||||||
return foo.Game(gameSurface)
|
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
currentGame = loadGame(games['russianRoulette'])
|
# I'm sorry, I prefer object-oriented programming. So sue me.
|
||||||
|
class Launcher:
|
||||||
|
def __init__(self):
|
||||||
|
# The primary display.
|
||||||
|
self.screen = pygame.display.set_mode((args.width, args.height))
|
||||||
|
# The surface that the games render to.
|
||||||
|
self.gameSurface = pygame.Surface(self.screen.size)
|
||||||
|
# The current Game object. None means no game is running
|
||||||
|
self.currentGame = None
|
||||||
|
self.clock = pygame.time.Clock()
|
||||||
|
# Is the launcher running (including if a game is running).
|
||||||
|
self.running = True
|
||||||
|
|
||||||
while run:
|
pygame.display.set_caption('Pain Jam Launcher')
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
def loadGame(self, game):
|
||||||
# If there's no game running
|
# Set the current working directory
|
||||||
if currentGame == None:
|
# to the base path of the game.
|
||||||
# Exit the launcher
|
os.chdir(game.path)
|
||||||
run = False
|
# Load the games game.py file.
|
||||||
# Otherwise
|
spec = importlib.util.spec_from_file_location(game.id, os.path.join(game.path, 'game.py'))
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
# Initialise the games Game class, then set the
|
||||||
|
# current game to that.
|
||||||
|
self.currentGame = module.Game(self.gameSurface)
|
||||||
|
# Set the window title to the games name
|
||||||
|
pygame.display.set_caption(game.name)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if self.gameRunning:
|
||||||
|
self.currentGame._onEvent(event)
|
||||||
|
|
||||||
|
# CTRL+ESC
|
||||||
|
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE and event.mod == 64):
|
||||||
|
# Close the game.
|
||||||
|
# TODO: Fade out game?
|
||||||
|
self.currentGame.close()
|
||||||
|
self.currentGame = None
|
||||||
|
os.chdir(originalCWD)
|
||||||
|
pygame.display.set_caption('Pain Jam Launcher')
|
||||||
|
# If we launched directly into a game
|
||||||
|
if args.gameID is not None:
|
||||||
|
# Exit the launcher when we exit the game
|
||||||
|
self.running = False
|
||||||
else:
|
else:
|
||||||
# Close the game
|
if event.type == pygame.QUIT:
|
||||||
# TODO: Fade out game?
|
# Exit the launcher.
|
||||||
currentGame.close()
|
self.running = False
|
||||||
currentgame = None
|
elif event.type == pygame.KEYDOWN:
|
||||||
os.chdir(originalCWD)
|
if event.key == pygame.K_1:
|
||||||
|
self.loadGame(games['russianRoulette'])
|
||||||
|
|
||||||
if currentGame != None:
|
if self.gameRunning:
|
||||||
currentGame.onEvent(event)
|
self.currentGame._update()
|
||||||
|
self.screen.blit(self.currentGame._surf, (0, 0))
|
||||||
if currentGame != None:
|
else:
|
||||||
currentGame.update()
|
self.screen.fill((0, 0, 0))
|
||||||
screen.blit(currentGame.surf, (0, 0))
|
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
self.clock.tick(args.fpsCap)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def gameRunning(self):
|
||||||
|
return self.currentGame is not None
|
||||||
|
|
||||||
|
launcher = Launcher()
|
||||||
|
if args.gameID is not None:
|
||||||
|
launcher.loadGame(games[args.gameID])
|
||||||
|
while launcher.running:
|
||||||
|
launcher.update()
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
pygame-ce
|
pygame-ce
|
||||||
|
pishock
|
||||||
attrs
|
attrs
|
||||||
11
setup.py
11
setup.py
@ -65,4 +65,13 @@ for path in os.listdir('../'):
|
|||||||
print(f'{path} does not have a requirements.txt, skipping...')
|
print(f'{path} does not have a requirements.txt, skipping...')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
installRequirements(requirementsPath)
|
installRequirements(requirementsPath)
|
||||||
|
|
||||||
|
if os.path.isfile('../players.json'):
|
||||||
|
newPlayerJSON = inputYN(f'player.json already exists, would you like to overwrite it? (y/n) > ')
|
||||||
|
else:
|
||||||
|
newPlayerJSON = True
|
||||||
|
|
||||||
|
if newPlayerJSON:
|
||||||
|
print(f'---------- Copying example players.json ----------')
|
||||||
|
shutil.copyfile('../NoPELib/players.json', '../players.json')
|
||||||
Reference in New Issue
Block a user