Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Saludame.activity/utilities.py
blob: 104c80236a621f1d78b025a1e8dd98534e0011cd (plain)
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
# -*- coding: utf-8 -*-

import gui
import pygame
import os
import effects

def get_accept_button(container, rect, text, cb_click=None, cb_over=None, cb_out=None):
    background = pygame.image.load("assets/windows/dialog_button.png").convert()
    return gui.TextButton2(container, rect, 1, text, 24, pygame.Color("#397b7e"), background, cb_click, cb_over, cb_out)
    
def change_color(surface, old_color, new_color):
    # No funciona en pygame 1.8.0
    i = 0
    palette = surface.get_palette()
    for color in palette:
       if color == old_color:
           surface.set_palette_at(i, get_color_tuple(new_color))
       i += 1

def get_color_tuple(color):
    if isinstance(color, tuple):
        return color[0:3]
    elif isinstance(color, pygame.Color):
        return (color.r, color.g, color.b)
    else:
        color = pygame.Color(color)
        return get_color_tuple(color)

# Fonts - creates an alias for the get_font function
get_font = gui.get_font

# Paths controls
def check_directory(directory):
    try:
        print directory
        os.listdir(directory)
        return True
    except OSError:
        return False
    
def check_image(image_path):
    try:
        print image_path
        pygame.image.load(image_path)
        return True
    except:
        return False
    
def verify_path(action, game_manager):
    if isinstance(action.effect, effects.Effect): # If the action has effects on bars
        if action.kid_animation_path: # and has a kid animation path
            return check_directory("%s/%s/%s" % (action.kid_animation_path, game_manager.character.sex, game_manager.character.clothes)) # check animation directory (action_path/sex/clothes)
        else:
            return True
            
    if isinstance(action.effect, effects.ClothesEffect): # If the action has clothes effects
        return check_directory("%s/%s/%s" % (game_manager.character.mood.kid_animation_path, game_manager.character.sex, action.effect.clothes_id))
        
    if isinstance(action.effect, effects.LocationEffect): # If the action has location effects
        return check_image(game_manager.environments_dictionary[action.effect.place_id + "_" + game_manager.current_weather].background_path)
        
    return True