/
portrait.rpy
131 lines (109 loc) · 4.97 KB
/
portrait.rpy
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# The MIT License (MIT)
#
# Copyright 2022 Erik Juárez-Guerrero <https://github.com/Moshibit>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
init python:
def image_history_callback(entry):
tag = entry.image_tag
# Constants
IMAGE_DIRECTORY = "gui/history/"
IMAGE_PREFIX = "history"
IMAGE_EXTENSION = ".png"
# None when the character is not assigned an image tag.
if tag is None:
entry.image = None
return
# create the image property on the entry object.
if tag == "generic":
entry.image = "{}{} generic{}".format(IMAGE_DIRECTORY, IMAGE_PREFIX,IMAGE_EXTENSION)
return
if tag == "generic_girl":
entry.image = "{}{} generic girl{}".format(IMAGE_DIRECTORY, IMAGE_PREFIX,IMAGE_EXTENSION)
return
if tag == "generic_boy":
entry.image = "{}{} generic boy{}".format(IMAGE_DIRECTORY, IMAGE_PREFIX,IMAGE_EXTENSION)
return
# get the attributes of the current image
attributes = renpy.get_attributes(tag) # attribute tuple
# handling None atrributes
if attributes is not None:
attributes = " ".join(attributes) # the tuple is now a string
else:
attributes = ""
# get the image to show, choose only one:
# * uncomment next line if you want the same image every time
# image_string = "{}{} {}{}".format(IMAGE_DIRECTORY, IMAGE_PREFIX, tag, IMAGE_EXTENSION)
# * or uncomment next line if you want the image to match the current attributes
image_string = "{}{} {} {}{}".format(IMAGE_DIRECTORY, IMAGE_PREFIX, tag, attributes, IMAGE_EXTENSION)
# handling missing images
if renpy.exists(image_string) == False:
if config.developer:
image_string = "{}{} missing{}".format(IMAGE_DIRECTORY, IMAGE_PREFIX,IMAGE_EXTENSION)
else:
image_string = None
# create the image property on the entry object
entry.image = image_string
return
def layeredimage_history_callback(entry):
tag = entry.image_tag
# Constants
IMAGE_PREFIX = "history"
# None when the character is not assigned an image tag.
if tag is None:
entry.image = None
return
# create the image property on the entry object.
if tag == "generic":
entry.image = "{} generic".format(IMAGE_PREFIX)
return
if tag == "generic_girl":
entry.image = "{} generic girl".format(IMAGE_PREFIX)
return
if tag == "generic_boy":
entry.image = "{} generic boy".format(IMAGE_PREFIX)
return
# get the attributes of the current image
attributes = renpy.get_attributes(tag) # attribute tuple
# handling missing images
check = []
for attribute in attributes:
check.append(attribute in renpy.get_ordered_image_attributes(tag))
if not all(check):
if config.developer:
layered_image = "{} missing".format(IMAGE_PREFIX)
else:
layered_image = None
entry.image = layered_image
return
# handling None atrributes
if attributes is not None:
attributes = " ".join(attributes) # the tuple is now a string
else:
attributes = ""
# get the image to show
layered_image = "{} {} {}".format(IMAGE_PREFIX, tag, attributes)
# create the image property on the entry object
entry.image = layered_image
return
# append the callback function to the configuration variable
# uncomment only one of the following two lines:
config.history_callbacks.append(image_history_callback)
#config.history_callbacks.append(layeredimage_history_callback)