-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.py
104 lines (81 loc) · 3.55 KB
/
launcher.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
# Try to bypass DPI scaling on Windows to preserve pixel-perfect scaling
# Switching displays with different scales may cause Windows to scale this anyway
try:
import ctypes
ctypes.windll.user32.SetProcessDPIAware()
except ImportError:
pass
# Configure debug logging
from widebrim.madhatter.common import NamedLogger
NamedLogger.SHOW_CRITICAL = True
NamedLogger.SHOW_IMPORTANT = True
NamedLogger.SHOW_UNIMPORTANT = False
import pygame
from widebrim.engine.state.manager.collective import Layton2CollectiveState
from widebrim.engine.state.clock import AltClock
from widebrim.engine.state.enum_mode import GAMEMODES
from widebrim.engine.const import LANGUAGES
from widebrim.engine.config import TIME_FRAMERATE
from widebrim.engine_ext.state_game import ScreenCollectionGameModeSpawner
from widebrim.engine.convenience import initDisplay
from widebrim.engine.custom_events import ENGINE_SKIP_CLOCK
from widebrim.engine_ext.rom import applyPygameBannerTweaks
from widebrim.engine_ext.utils import cleanTempFolder
from traceback import print_exc
def play(rootHandler : ScreenCollectionGameModeSpawner, state : Layton2CollectiveState):
applyPygameBannerTweaks(state.getFileAccessor())
isActive = True
gameDisplay = initDisplay()
gameClockDelta = 0
gameClock = AltClock()
gameClockInterval = 1 / TIME_FRAMERATE
timeClockInterval = gameClockInterval * 1000
enableSpeedModifier = False
while isActive:
rootHandler.update(gameClockDelta)
rootHandler.draw(gameDisplay)
pygame.display.update()
bypassClock = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
isActive = False
rootHandler.doOnPygameQuit()
elif event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.MOUSEBUTTONUP or event.type == pygame.MOUSEMOTION:
rootHandler.handleTouchEvent(event)
elif event.type == pygame.KEYDOWN and event.key == pygame.K_TAB:
enableSpeedModifier = True
elif event.type == pygame.KEYUP and event.key == pygame.K_TAB:
enableSpeedModifier = False
elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
rootHandler.handleKeyboardEvent(event)
elif event.type == ENGINE_SKIP_CLOCK:
bypassClock = True
gameClockDelta = gameClock.tick(gameClockInterval)
if bypassClock:
gameClockDelta = timeClockInterval
if gameClockDelta / timeClockInterval > 1.25:
gameClockDelta = timeClockInterval
if enableSpeedModifier:
gameClockDelta *= 4
pygame.display.quit()
pygame.quit()
debugState = Layton2CollectiveState(language=LANGUAGES.English)
debugHandler = ScreenCollectionGameModeSpawner(debugState)
# Enter the game under Reset state, as if booting up for first time
debugState.setGameMode(GAMEMODES.Reset)
try:
play(debugHandler, debugState)
except Exception as e:
pygame.display.quit()
pygame.quit()
print("widebrim has crashed!")
print(debugState.getGameMode(), debugState.getEventId(), debugState.getMovieNum(), debugState.saveSlot.roomIndex)
print("\nStack Trace:")
print_exc()
print("\nPlease report this information to the widebrim project at https://github.com/bullbin/widebrim.")
try:
debugHandler.doOnPygameQuit()
except Exception as f:
print_exc()
input("\nExecution will now end, close the terminal or press ENTER to stop...")
cleanTempFolder()