/
_pictures.dm
191 lines (179 loc) · 5.56 KB
/
_pictures.dm
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/datum/picture
var/picture_name = "picture"
var/picture_desc = "This is a picture."
/// List of weakrefs pointing at mobs that appear in this photo
var/list/mobs_seen = list()
/// List of weakrefs pointing at dead mobs that appear in this photo
var/list/dead_seen = list()
var/caption
var/icon/picture_image
var/icon/picture_icon
var/psize_x = 96
var/psize_y = 96
var/has_blueprints = FALSE
var/logpath //If the picture has been logged this is the path.
var/id //this var is NOT protected because the worst you can do with this that you couldn't do otherwise is overwrite photos, and photos aren't going to be used as attack logs/investigations anytime soon.
///Was this image capable of seeing ghosts?
var/see_ghosts = CAMERA_NO_GHOSTS
/datum/picture/New(name, desc, mobs_spotted, dead_spotted, image, icon, size_x, size_y, bp, caption_, autogenerate_icon, can_see_ghosts)
if(!isnull(name))
picture_name = name
if(!isnull(desc))
picture_desc = desc
if(!isnull(mobs_spotted))
for(var/mob/seen as anything in mobs_spotted)
mobs_seen += WEAKREF(seen)
if(!isnull(dead_spotted))
for(var/mob/seen as anything in dead_spotted)
dead_seen += WEAKREF(seen)
if(!isnull(image))
picture_image = image
if(!isnull(icon))
picture_icon = icon
if(!isnull(psize_x))
psize_x = size_x
if(!isnull(psize_y))
psize_y = size_y
if(!isnull(bp))
has_blueprints = bp
if(!isnull(caption_))
caption = caption_
if(autogenerate_icon && !picture_icon && picture_image)
regenerate_small_icon()
if(can_see_ghosts)
see_ghosts = can_see_ghosts
/datum/picture/proc/get_small_icon(iconstate)
if(!picture_icon)
regenerate_small_icon(iconstate)
return picture_icon
/datum/picture/proc/regenerate_small_icon(iconstate)
if(!picture_image)
return
var/icon/small_img = icon(picture_image)
var/icon/ic = icon('icons/obj/items_and_weapons.dmi', iconstate ? iconstate :"photo")
small_img.Scale(8, 8)
ic.Blend(small_img,ICON_OVERLAY, 13, 13)
picture_icon = ic
/datum/picture/serialize_list(list/options)
. = list()
.["id"] = id
.["desc"] = picture_desc
.["name"] = picture_name
.["caption"] = caption
.["pixel_size_x"] = psize_x
.["pixel_size_y"] = psize_y
.["blueprints"] = has_blueprints
.["logpath"] = logpath
/datum/picture/deserialize_list(list/input, list/options)
if(!input["logpath"] || !fexists(input["logpath"]) || !input["id"] || !input["pixel_size_x"] || !input["pixel_size_y"])
return
picture_image = icon(file(input["logpath"]))
logpath = input["logpath"]
id = input["id"]
psize_x = input["pixel_size_x"]
psize_y = input["pixel_size_y"]
if(input["blueprints"])
has_blueprints = input["blueprints"]
if(input["caption"])
caption = input["caption"]
if(input["desc"])
picture_desc = input["desc"]
if(input["name"])
picture_name = input["name"]
return src
/proc/load_photo_from_disk(id, location)
var/datum/picture/P = load_picture_from_disk(id)
if(istype(P))
var/obj/item/photo/old/p = new(location, P)
return p
/proc/load_picture_from_disk(id)
var/pathstring = log_path_from_picture_ID(id)
if(!pathstring)
return
var/path = file(pathstring)
if(!fexists(path))
return
var/dir_index = findlasttext(pathstring, "/")
var/dir = copytext(pathstring, 1, dir_index)
var/json_path = file("[dir]/metadata.json")
if(!fexists(json_path))
return
var/list/json = json_decode(file2text(json_path))
if(!json[id])
return
var/datum/picture/P = new
// Old photos were saved as, and I shit you not, encoded JSON strings.
if (istext(json[id]))
P.deserialize_json(json[id])
else
P.deserialize_list(json[id])
return P
/proc/log_path_from_picture_ID(id)
if(!istext(id))
return
. = "data/picture_logs/"
var/list/data = splittext(id, "_")
if(data.len < 3)
return null
var/mode = data[1]
switch(mode)
if("L")
if(data.len < 5)
return null
var/timestamp = data[2]
var/year = copytext_char(timestamp, 1, 5)
var/month = copytext_char(timestamp, 5, 7)
var/day = copytext_char(timestamp, 7, 9)
var/round = data[4]
. += "[year]/[month]/[day]/round-[round]"
if("O")
var/list/path = data.Copy(2, data.len)
. += path.Join("")
else
return null
var/n = data[data.len]
. += "/[n].png"
//BE VERY CAREFUL WITH THIS PROC, TO AVOID DUPLICATION.
/datum/picture/proc/log_to_file()
if(!picture_image)
return
if(!CONFIG_GET(flag/log_pictures))
return
if(logpath)
return //we're already logged
var/number = GLOB.picture_logging_id++
var/finalpath = "[GLOB.picture_log_directory]/[number].png"
fcopy(icon(picture_image, dir = SOUTH, frame = 1), finalpath)
logpath = finalpath
id = "[GLOB.picture_logging_prefix][number]"
var/jsonpath = "[GLOB.picture_log_directory]/metadata.json"
jsonpath = file(jsonpath)
var/list/json
if(fexists(jsonpath))
json = json_decode(file2text(jsonpath))
fdel(jsonpath)
else
json = list()
json[id] = serialize_list()
WRITE_FILE(jsonpath, json_encode(json))
/datum/picture/proc/Copy(greyscale = FALSE, cropx = 0, cropy = 0)
var/datum/picture/P = new
P.picture_name = picture_name
P.picture_desc = picture_desc
if(picture_image)
P.picture_image = icon(picture_image) //Copy, not reference.
if(picture_icon)
P.picture_icon = icon(picture_icon)
P.psize_x = psize_x - cropx * 2
P.psize_y = psize_y - cropy * 2
P.has_blueprints = has_blueprints
if(greyscale)
if(picture_image)
P.picture_image.MapColors(rgb(77,77,77), rgb(150,150,150), rgb(28,28,28), rgb(0,0,0))
if(picture_icon)
P.picture_icon.MapColors(rgb(77,77,77), rgb(150,150,150), rgb(28,28,28), rgb(0,0,0))
if(cropx || cropy)
if(picture_image)
P.picture_image.Crop(cropx, cropy, psize_x - cropx, psize_y - cropy)
P.regenerate_small_icon()
return P