Esempio n. 1
0
def load_game(g, s):
    g_id = g['id']
    opt = s['options']
    try:
        starting_player = g['options']['startingPlayer']
    except KeyError:
        starting_player = opt['startingPlayer']
    num = opt['numPlayers']
    var_eff = None
    if num == 2:
        var_eff = session.query(Variant.eff_2p).filter(
            Variant.variant == opt['variantName']).scalar()
    elif num in [3, 4]:
        var_eff = session.query(Variant.eff_34p).filter(
            Variant.variant == opt['variantName']).scalar()
    elif num == 5:
        var_eff = session.query(Variant.eff_5p).filter(
            Variant.variant == opt['variantName']).scalar()
    elif num == 6:
        var_eff = session.query(Variant.eff_6p).filter(
            Variant.variant == opt['variantName']).scalar()
    game = Game(g_id, opt['numPlayers'], g['players'], starting_player,
                opt['variantID'], opt['variantName'], opt['timed'],
                opt['timeBase'], opt['timePerTurn'], opt['speedrun'],
                opt['cardCycle'], opt['deckPlays'], opt['emptyClues'],
                opt['oneExtraCard'], opt['oneLessCard'], opt['allOrNothing'],
                opt['detrimentalCharacters'], s['score'], s['numTurns'],
                s['endCondition'], s['datetimeStarted'], s['datetimeFinished'],
                s['numGamesOnThisSeed'], s['tags'], g['seed'], var_eff)
    session.add(game)
    return game
Esempio n. 2
0
def load_notes(g):
    g_id = g['id']
    try:
        game_notes = g['notes']
        for i in range(len(game_notes)):
            player_notes = PlayerNotes(g_id, g['players'][i], game_notes[i])
            session.add(player_notes)
    except KeyError:
        return
Esempio n. 3
0
def load_game_empty(g):
    g_id = g['id']
    try:
        starting_player = g['options']['startingPlayer']
    except KeyError:
        starting_player = None
    game = Game(g_id, None, g['players'], starting_player, *[None] * 20,
                g['seed'], None)
    session.add(game)
Esempio n. 4
0
def load_deck(g):
    deck = g['deck']
    deck_res = session.query(Card) \
        .filter(Card.seed == g['seed'])\
        .all()
    if len(deck_res) != 0:
        return deck_res
    deck_res = []
    for i in range(len(deck)):
        card = Card(g['seed'], i, deck[i]['suitIndex'], deck[i]['rank'])
        session.add(card)
        deck_res.append(card)
    return deck_res
Esempio n. 5
0
def create_clue(action, colors, game_id, num_players, players_mod,
                players_orig):
    # color
    if action.action_type == 2:
        value = colors[action.value]
    # rank
    else:
        value = action.value
    clue = Clue(action.turn + 1, game_id, value,
                'color' if action.action_type == 2 else 'rank',
                players_mod[action.turn % num_players],
                players_orig[action.target])
    session.add(clue)
Esempio n. 6
0
def load_actions(g):
    g_id = g['id']
    actions = g['actions']
    actions_res = []
    for i in range(len(actions)):
        action = GameAction(
            g_id,
            i,
            actions[i]['type'],
            actions[i]['target'],
            actions[i]['value'],
        )
        session.add(action)
        actions_res.append(action)
    return actions_res
Esempio n. 7
0
def load_tags(s):
    for user_tag in s['users_tags']:
        items = list(user_tag.items())
        user, tag = items[0][0], items[0][1]
        tag = Tag(s['id'], user, tag)
        session.add(tag)
Esempio n. 8
0
def add_slot(card_action, turn, slot):
    movement = Slot(card_action.game_id, card_action.card_index, turn, slot)
    session.add(movement)
    return movement
Esempio n. 9
0
def load_player(player):
    session.add(Player(player))
Esempio n. 10
0
def load_card_action_empty(deck, game_id, suits):
    for card in deck:
        new_card_action = CardAction(card.card_index, game_id,
                                     suits[card.suit_index], card.rank,
                                     *[None] * 4)
        session.add(new_card_action)
Esempio n. 11
0
def load_variant(variant, variant_id):
    var = Variant(variant_id, variant, *[None] * 14)
    session.add(var)