Skip to content

Commit

Permalink
scene names as folder names
Browse files Browse the repository at this point in the history
  • Loading branch information
Mekire committed Jul 10, 2015
1 parent c562a67 commit 3aeb0f4
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 61 deletions.
2 changes: 1 addition & 1 deletion data/components/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class GameButton(Button):
font = prepare.FONTS["Saniretro"]

def __init__(self, pos, game, call, *groups, **kwargs):
path = os.path.join(".", "data", "states", "games", game)
path = os.path.join(".", "data", "states", game)
try:
image = pg.image.load(os.path.join(path, "image.png")).convert()
except pg.error:
Expand Down
19 changes: 5 additions & 14 deletions data/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,18 @@ def auto_discovery(self, scene_folder=None):
"""
if scene_folder is None:
scene_folder = os.path.join(".", "data", "states")

exclude_endings = (".py", ".pyc", "__pycache__")
for folder in os.listdir(scene_folder):
if any(folder.endswith(end) for end in exclude_endings):
continue

state = self.load_state_from_path(folder)
self.register_state(state)
self.register_state(state, folder)

def register_state(self, state):
try:
name = state.name
except AttributeError:
print('state {} is missing class name'.format(state))
raise AttributeError

if name in self.state_dict:
print('Duplicate state detected: {}'.format(name))
def register_state(self, state, folder):
if folder in self.state_dict:
print('Duplicate state detected: {}'.format(folder))
raise RuntimeError

self.state_dict[name] = state
self.state_dict[folder] = state

@property
def saved_stats_are_available(self):
Expand Down
2 changes: 1 addition & 1 deletion data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
run_it.auto_discovery()

# default state
default_state = "SNAKESPLASH"
default_state = "snake_splash"

straight = prepare.ARGS['straight']
state = straight if straight else default_state
Expand Down
4 changes: 2 additions & 2 deletions data/states/atm/atm_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class ATMScreen(data.state.State):
Uses a state system to handle the different ATM screens.
"""
name = 'ATMSCREEN'
name = "atm"

def __init__(self):
super(ATMScreen, self).__init__()
self.use_music_handler = False
self.screen_rect = pg.Rect((0, 0), prepare.RENDER_SIZE)
self.next = "LOBBYSCREEN"
self.next = "lobby"
self.states = {"MAINMENU": ATMMenu(),
"DEPOSIT": DepositScreen(),
"WITHDRAWAL": WithdrawalScreen(),
Expand Down
2 changes: 1 addition & 1 deletion data/states/baccarat/baccarat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Baccarat(TableGame):
a considerable amount of variation on the stated rules, so artistic license
was taken in determining what the rules should be.
"""
name = 'Baccarat'
name = "baccarat"
variation = "mini"
show_in_lobby = True
collect_stats = True
Expand Down
2 changes: 1 addition & 1 deletion data/states/baccarat/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def do_quit(self, *args):
"""
self.cash_out()
self.done = True
self.next = 'LOBBYSCREEN'
self.next = 'lobby'

def cash_in(self):
"""Change player's cash to chips
Expand Down
8 changes: 4 additions & 4 deletions data/states/bingo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class Bingo(statemachine.StateMachine):
"""State to represent a bing game"""
name = 'Bingo'
name = "bingo"
show_in_lobby = True

def __init__(self):
Expand Down Expand Up @@ -117,7 +117,7 @@ def get_event(self, event, scale=(1,1)):
sys.exit()
else:
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"
elif event.type in (pg.MOUSEBUTTONDOWN, pg.MOUSEMOTION):
#
self.ui.process_events(event, scale)
Expand All @@ -127,7 +127,7 @@ def get_event(self, event, scale=(1,1)):
elif event.type == pg.KEYUP:
if event.key == pg.K_ESCAPE:
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"
elif event.key == pg.K_SPACE:
self.next_chip(None, None)
elif event.key == pg.K_m:
Expand All @@ -141,7 +141,7 @@ def return_to_lobby(self, arg):
"""Return to the lobby screen"""
self.game_started = False
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"
self.casino_player.set('_last squares', self.cards.get_card_numbers())
self.casino_player.cash = self.money_display.amount
self.casino_player.increase_time('time played', time.time() - self.time_started)
Expand Down
4 changes: 2 additions & 2 deletions data/states/blackjack/blackjack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Blackjack(data.state.State):
back into cash before returning to the lobby.
"""
show_in_lobby = True
name = 'Blackjack'
name = 'blackjack'

def __init__(self):
super(Blackjack, self).__init__()
Expand Down Expand Up @@ -64,7 +64,7 @@ def leave_state(self):
"""Prepare to exit game and return to lobby screen."""
self.cash_out_player()
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"

def get_event(self, event, scale):
self.state.get_event(event, scale)
Expand Down
6 changes: 3 additions & 3 deletions data/states/craps/craps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Craps(data.state.State):
show_in_lobby = True
name = 'Craps'
name = 'craps'

def __init__(self):
super(Craps, self).__init__()
Expand Down Expand Up @@ -78,7 +78,7 @@ def make_buttons(self, screen_rect):

def back_to_lobby(self, *args):
self.game_started = False
self.next = "LOBBYSCREEN"
self.next = "lobby"
self.done = True

def debug_roll(self, id, text):
Expand Down Expand Up @@ -123,7 +123,7 @@ def get_event(self, event, scale=(1,1)):
if event.type == pg.QUIT:
#self.cash_out_player()
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"
elif event.type == pg.VIDEORESIZE:
self.set_table()
self.buttons.get_event(event)
Expand Down
4 changes: 2 additions & 2 deletions data/states/credits/credits_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class CreditsScreen(data.state.State):
"""
This is the main state governing the credits screen.
"""
name = 'CREDITSSCREEN'
name = 'credits'

def __init__(self):
super(CreditsScreen, self).__init__()
self.screen = pg.Rect((0, 0), prepare.RENDER_SIZE)
self.next = "LOBBYSCREEN"
self.next = "lobby"
self.font = prepare.FONTS["Saniretro"]
self.dev_names = DEVELOPERS
self.artist_names = ARTISTS
Expand Down
4 changes: 2 additions & 2 deletions data/states/guts/guts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Guts(data.state.State):
show_in_lobby = True
name = 'Guts'
name = 'guts'

def __init__(self):
super(Guts, self).__init__()
Expand Down Expand Up @@ -100,7 +100,7 @@ def update_stats(self):

def back_to_lobby(self, *args):
self.persist["casino_player"].cash = self.player.cash
self.next = "LOBBYSCREEN"
self.next = "lobby"
self.done = True

def get_event(self, event, scale):
Expand Down
6 changes: 3 additions & 3 deletions data/states/keno/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class Keno(data.state.State):
"""Class to represent a casino game."""
show_in_lobby = True
name = 'Keno'
name = 'keno'

def __init__(self):
super(Keno, self).__init__()
Expand Down Expand Up @@ -245,7 +245,7 @@ def result(self, spot, hit):
def back_to_lobby(self, *args):
self.game_started = False
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"

def startup(self, current_time, persistent):
"""This method will be called each time the state resumes."""
Expand Down Expand Up @@ -273,7 +273,7 @@ def get_event(self, event, scale=(1,1)):
"""
if event.type == pg.QUIT and not self.alert:
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"
elif event.type == pg.MOUSEBUTTONDOWN and not self.alert:
#Use tools.scaled_mouse_pos(scale, event.pos) for correct mouse
#position relative to the pygame window size.
Expand Down
8 changes: 4 additions & 4 deletions data/states/lobby/lobby_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LobbyScreen(data.state.State):
which game they want to play or view their game statistics. This is also
the exit point for the game.
"""
name = 'LOBBYSCREEN'
name = "lobby"
per_page = 6

def __init__(self):
Expand Down Expand Up @@ -92,18 +92,18 @@ def make_navigation_buttons(self, screen_rect):
def make_main_buttons(self, screen_rect):
buttons = ButtonGroup()
pos = (9, screen_rect.bottom-(NeonButton.height+11))
NeonButton(pos, "Credits", self.change_state, "CREDITSSCREEN", buttons)
NeonButton(pos, "Credits", self.change_state, "credits", buttons)
pos = (screen_rect.right-(NeonButton.width+10),
screen_rect.bottom-(NeonButton.height+11))
NeonButton(pos, "Stats", self.change_state, "STATSMENU", buttons)
NeonButton(pos, "Stats", self.change_state, "stats_menu", buttons)
pos = (screen_rect.centerx-(NeonButton.width//2),
screen_rect.bottom-(NeonButton.height+11))
NeonButton(pos, "Exit", self.exit_game, None,
buttons, bindings=[pg.K_ESCAPE])
rect_style = (screen_rect.left, screen_rect.top, 150, 95)
Button(rect_style, buttons, idle_image=prepare.GFX["atm_dim"],
hover_image=prepare.GFX["atm_bright"],
call=self.change_state, args="ATMSCREEN")
call=self.change_state, args="atm")
return buttons

def scroll_page(self, mag):
Expand Down
4 changes: 2 additions & 2 deletions data/states/pachinko/pachinko.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Pachinko(data.state.State):
"""Pachinko game."""
show_in_lobby = True
name = 'Pachinko'
name = 'pachinko'

# hack related to game states that do not finish
did_startup = False
Expand Down Expand Up @@ -123,7 +123,7 @@ def initialize_stats():
def goto_lobby(self):
self.cash_out()
self.done = True
self.next = 'LOBBYSCREEN'
self.next = 'lobby'

def on_jackpot(self, *args):
self.casino_player.stats["Pachinko"]["jackpots"] += 1
Expand Down
4 changes: 2 additions & 2 deletions data/states/slots/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Slots(data.state.State):
show_in_lobby = True
name = 'Slots'
name = 'slots'

def __init__(self):
super(Slots, self).__init__()
Expand Down Expand Up @@ -44,7 +44,7 @@ def make_buttons(self, screen_rect):
return buttons

def back_to_lobby(self, *args):
self.next = "LOBBYSCREEN"
self.next = "lobby"
self.done = True

def startup(self, current_time, persistent):
Expand Down
5 changes: 2 additions & 3 deletions data/states/snake_splash/snake_splash.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@


class SnakeSplash(data.state.State):
"""Class to represent a casino game."""
name = 'SNAKESPLASH'
name = "snake_splash"

def __init__(self):
super(SnakeSplash, self).__init__()
self.next = "TITLESCREEN"
self.next = "title_screen"
self.screen_rect = pg.Rect((0, 0), prepare.RENDER_SIZE)
self.image = prepare.GFX["snakesign"]
self.on = False
Expand Down
8 changes: 4 additions & 4 deletions data/states/stats_menu/stats_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StatsMenu(data.state.State):
This state allows the player to choose which game's stats they
want to view or return to the lobby.
"""
name = 'STATSMENU'
name = "stats_menu"

def __init__(self):
super(StatsMenu, self).__init__()
Expand Down Expand Up @@ -69,11 +69,11 @@ def make_buttons(self, games, screen_rect, col=2):

def back_to_lobby(self, *args):
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"

def view_game_stats(self, game):
self.persist["current_game_stats"] = game
self.next = "STATSSCREEN"
self.next = "stats_screen"
self.done = True

def startup(self, current_time, persistent):
Expand All @@ -90,7 +90,7 @@ def startup(self, current_time, persistent):
def get_event(self, event, scale=(1,1)):
if event.type == pg.QUIT:
self.done = True
self.next = "LOBBYSCREEN"
self.next = "lobby"
self.buttons.get_event(event)

def draw(self, surface):
Expand Down
11 changes: 6 additions & 5 deletions data/states/stats_screen/stats_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

class StatsScreen(data.state.State):
"""This state displays the player's statistics for a
particular game."""
name = 'STATSSCREEN'
particular game.
"""
name = "stats_screen"

def __init__(self):
super(StatsScreen, self).__init__()
Expand All @@ -22,9 +23,9 @@ def make_buttons(self, screen_rect):
buttons = ButtonGroup()
x,y = (screen_rect.centerx-(NeonButton.width//2)-170,
screen_rect.bottom-(NeonButton.height+10))
NeonButton((x,y), "Lobby", self.back_to_x, "LOBBYSCREEN", buttons)
NeonButton((x,y), "Lobby", self.back_to_x, "lobby", buttons)
x = screen_rect.centerx-(NeonButton.width//2)+170
NeonButton((x,y), "Back", self.back_to_x, "STATSMENU",
NeonButton((x,y), "Back", self.back_to_x, "stats_menu",
buttons, bindings=[pg.K_ESCAPE])
return buttons

Expand Down Expand Up @@ -56,7 +57,7 @@ def startup(self, current_time, persistent):

def get_event(self, event, scale=(1,1)):
if event.type == pg.QUIT:
self.back_to_x("LOBBYSCREEN")
self.back_to_x("lobby")
self.buttons.get_event(event)

def draw(self, surface):
Expand Down
5 changes: 2 additions & 3 deletions data/states/title_screen/title_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TitleScreen(data.state.State):
Initial state of the game. Introduces the game and lets user load a
saved game if there's one present.
"""
name = 'TITLESCREEN'
name = "title_screen"

def __init__(self):
super(TitleScreen, self).__init__()
Expand Down Expand Up @@ -84,8 +84,7 @@ def make_buttons(self):
def load_or_new(self, try_to_load_data):
if try_to_load_data:
self.persist = self.controller.load_persist_from_disk()

self.next = 'LOBBYSCREEN'
self.next = "lobby"
self.done = True

def get_event(self, event, scale):
Expand Down
Loading

0 comments on commit 3aeb0f4

Please sign in to comment.