massive refactoring to switch from camelCase to snake_case:

historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.

However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.

To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.

This is a massive change, and may result in some bugs.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -48,7 +48,7 @@ class QuickTarotGame(object):
self.to_show = []
self.state = None
def resetRound(self):
def reset_round(self):
"""Reset the game's variables to be reatty to start the next round"""
del self.selected[:]
del self.hand[:]
@ -57,14 +57,14 @@ class QuickTarotGame(object):
for pl in self.played:
self.played[pl] = None
def getPlayerLocation(self, nick):
def get_player_location(self, nick):
"""return player location (top,bottom,left or right)"""
for location in ["top", "left", "bottom", "right"]:
if getattr(self, "%s_nick" % location) == nick:
return location
assert False
def loadCards(self):
def load_cards(self):
"""Load all the cards in memory
@param dir: directory where the PNG files are"""
self.cards = {}
@ -77,7 +77,7 @@ class QuickTarotGame(object):
self.cards["carreau"] = {} # diamond
self.cards["trefle"] = {} # club
def tarotGameNewHandler(self, hand):
def tarot_game_new_handler(self, hand):
"""Start a new game, with given hand"""
assert len(self.hand) == 0
for suit, value in hand:
@ -85,12 +85,12 @@ class QuickTarotGame(object):
self.hand.sort()
self.state = "init"
def tarotGameChooseContratHandler(self, xml_data):
def tarot_game_choose_contrat_handler(self, xml_data):
"""Called when the player as to select his contrat
@param xml_data: SàT xml representation of the form"""
raise NotImplementedError
def tarotGameShowCardsHandler(self, game_stage, cards, data):
def tarot_game_show_cards_handler(self, game_stage, cards, data):
"""Display cards in the middle of the game (to show for e.g. chien ou poignée)"""
self.to_show = []
for suit, value in cards:
@ -100,14 +100,14 @@ class QuickTarotGame(object):
else:
self.state = "chien"
def tarotGameYourTurnHandler(self):
def tarot_game_your_turn_handler(self):
"""Called when we have to play :)"""
if self.state == "chien":
self.to_show = []
self.state = "play"
self.__fakePlay()
self.__fake_play()
def __fakePlay(self):
def __fake_play(self):
"""Convenience method for stupid autoplay
/!\ don't forgot to comment any interactive dialog for invalid card"""
if self._autoplay == None:
@ -115,21 +115,21 @@ class QuickTarotGame(object):
if self._autoplay >= len(self.hand):
self._autoplay = 0
card = self.hand[self._autoplay]
self.parent.host.bridge.tarotGamePlayCards(
self.parent.host.bridge.tarot_game_play_cards(
self.player_nick, self.referee, [(card.suit, card.value)], self.parent.profile
)
del self.hand[self._autoplay]
self.state = "wait"
self._autoplay += 1
def tarotGameScoreHandler(self, xml_data, winners, loosers):
def tarot_game_score_handler(self, xml_data, winners, loosers):
"""Called at the end of a game
@param xml_data: SàT xml representation of the scores
@param winners: list of winners' nicks
@param loosers: list of loosers' nicks"""
raise NotImplementedError
def tarotGameCardsPlayedHandler(self, player, cards):
def tarot_game_cards_played_handler(self, player, cards):
"""A card has been played by player"""
if self.to_show:
self.to_show = []
@ -141,7 +141,7 @@ class QuickTarotGame(object):
pl_cards.append(self.cards[suit, value])
self.played[player] = pl_cards[0]
def tarotGameInvalidCardsHandler(self, phase, played_cards, invalid_cards):
def tarot_game_invalid_cards_handler(self, phase, played_cards, invalid_cards):
"""Invalid cards have been played
@param phase: phase of the game
@param played_cards: all the cards played
@ -158,4 +158,4 @@ class QuickTarotGame(object):
self.hand.append(self.cards[suit, value])
self.hand.sort()
self.__fakePlay()
self.__fake_play()