|
1 | | -///For sending images to the UI with base 64 |
2 | | -/datum/data/ui_image |
| 1 | +///Holding info for UI elements |
| 2 | +/datum/data/cart_item |
| 3 | + ///Amount of item in contents |
| 4 | + var/amount = null |
| 5 | + ///Item's type path |
| 6 | + var/type_path = null |
3 | 7 | ///Image to be shown in UI |
4 | 8 | var/image = null |
5 | 9 |
|
6 | | -//Thanks hedgehog1029 for the help on this |
7 | | -/datum/data/ui_image/New(obj/item/I) |
| 10 | +//Thanks hedgehog1029 for the help on base64 icon |
| 11 | +/datum/data/cart_item/New(obj/item/I) |
| 12 | + name = I.name |
| 13 | + amount = 1 |
| 14 | + type_path = I.type |
8 | 15 | var/icon/icon = icon(I.icon, I.icon_state, SOUTH, 1) |
9 | 16 | image = icon2base64(icon) |
10 | 17 |
|
|
57 | 64 | data["storage"] = list() |
58 | 65 |
|
59 | 66 | //Make sure food_ui_list has desired contents |
60 | | - //This, combined with the find_amount() bellow, allow parmesan cheese to show in the UI after maturing |
61 | | - for(var/obj/list_element in contents) |
| 67 | + //This, along with contents check for food_ui_list, allows parmesan cheese to show in the UI after maturing |
| 68 | + var/in_list |
| 69 | + for(var/obj/item/content_item in contents) |
| 70 | + in_list = FALSE |
62 | 71 | //Only check food items |
63 | | - if(istype(list_element, /obj/item/reagent_containers/food)) |
64 | | - //Add to list if not already in it |
65 | | - if(!LAZYFIND(food_ui_list, list_element.type)) |
66 | | - LAZYADD(food_ui_list, list_element.type) |
| 72 | + if(istype(content_item, /obj/item/reagent_containers/food/snacks)) |
| 73 | + //Loop through all datums in ui list to check if item is in the UI |
| 74 | + for(var/datum/data/cart_item/item in food_ui_list) |
| 75 | + if(item.type_path == content_item.type) |
| 76 | + in_list = TRUE |
| 77 | + break |
| 78 | + //If not already in food_ui_list, add to it |
| 79 | + if(!in_list) |
| 80 | + LAZYADD(food_ui_list, new /datum/data/cart_item(content_item)) |
67 | 81 |
|
68 | | - |
69 | 82 | //Loop through food list for data to send to food tab |
70 | | - for(var/item_detail in food_ui_list) |
| 83 | + for(var/datum/data/cart_item/item_detail in food_ui_list) |
| 84 | + in_list = FALSE |
71 | 85 | //If none are found in contents, remove from list and move on to next element |
72 | | - if(find_amount(item_detail) == 0) |
| 86 | + for(var/obj/content_item in contents) |
| 87 | + if(content_item.type == item_detail.type_path) |
| 88 | + in_list = TRUE |
| 89 | + if(!in_list) |
73 | 90 | LAZYREMOVE(food_ui_list, item_detail) |
74 | | - continue |
| 91 | + break |
75 | 92 |
|
76 | 93 | //Create needed list and variable for geting data for UI |
77 | 94 | var/list/details = list() |
78 | | - var/obj/item/reagent_containers/food/item = new item_detail |
79 | 95 |
|
80 | 96 | //Get information for UI |
81 | | - details["name"] = item.name |
82 | | - details["quantity"] = find_amount(item) |
83 | | - details["type_path"] = item.type |
| 97 | + details["name"] = item_detail.name |
| 98 | + details["quantity"] = item_detail.amount |
| 99 | + details["type_path"] = item_detail.type_path |
84 | 100 |
|
85 | 101 | //Get an image for the UI |
86 | | - var/datum/data/ui_image/ui_image = new /datum/data/ui_image(item) |
87 | | - details["image"] = ui_image.image |
| 102 | + details["image"] = item_detail.image |
88 | 103 |
|
89 | 104 | //Add to food list |
90 | 105 | data["food"] += list(details) |
91 | 106 |
|
92 | | - //Delete instances to prevent server being overrun by spoopy ghost items |
93 | | - qdel(item) |
94 | | - qdel(ui_image) |
95 | | - |
96 | 107 | //Loop through drink list for data to send to cart's reagent storage tab |
97 | 108 | for(var/datum/reagent/drink in reagents.reagent_list) |
98 | 109 | var/list/details = list() |
|
206 | 217 | ..() |
207 | 218 |
|
208 | 219 | /obj/machinery/food_cart/proc/dispense_item(received_item, mob/user = usr) |
209 | | - //Make a variable for checking amount of item |
210 | | - var/obj/item/reagent_containers/food/ui_item = new received_item |
211 | | - |
212 | | - //If the vat has some of the desired item, dispense it |
213 | | - if(find_amount(ui_item) > 0) |
214 | | - //Select the last(most recent) of desired item |
215 | | - var/obj/item/reagent_containers/food/snacks/dispensed_item = LAZYACCESS(contents, last_index(ui_item)) |
216 | | - //Move it into the user's hands or drop it on the floor |
217 | | - user.put_in_hands(dispensed_item) |
218 | | - user.visible_message(span_notice("[user] dispenses [dispensed_item.name] from [src]."), span_notice("You dispense [dispensed_item.name] from [src].")) |
219 | | - playsound(src, dispense_sound, 25, TRUE, extrarange = -3) |
220 | | - //If the last one was dispenced, remove from UI |
221 | | - if(!find_amount(ui_item)) |
222 | | - LAZYREMOVE(food_ui_list, received_item) |
| 220 | + //Get list item for recieved_item |
| 221 | + var/datum/data/cart_item/ui_item = null |
| 222 | + for(var/datum/data/cart_item/item in food_ui_list) |
| 223 | + if(received_item == item.type_path) |
| 224 | + ui_item = item |
| 225 | + break |
| 226 | + //Continue if ui_item is not null |
| 227 | + if(ui_item) |
| 228 | + //If the vat has some of the desired item, dispense it |
| 229 | + if(ui_item.amount > 0) |
| 230 | + //Select the last(most recent) of desired item |
| 231 | + var/obj/item/reagent_containers/food/snacks/dispensed_item = LAZYACCESS(contents, last_index(ui_item.type_path)) |
| 232 | + //Decrease amount by 1 |
| 233 | + ui_item.amount -= 1 |
| 234 | + //Move it into the user's hands or drop it on the floor |
| 235 | + user.put_in_hands(dispensed_item) |
| 236 | + user.visible_message(span_notice("[user] dispenses [dispensed_item.name] from [src]."), span_notice("You dispense [dispensed_item.name] from [src].")) |
| 237 | + playsound(src, dispense_sound, 25, TRUE, extrarange = -3) |
| 238 | + //If the last one was dispenced, remove from UI |
| 239 | + if(ui_item.amount == 0) |
| 240 | + LAZYREMOVE(food_ui_list, ui_item) |
| 241 | + else |
| 242 | + //Incase the UI buttons are slow to disable themselves |
| 243 | + user.balloon_alert(user, "All out!") |
223 | 244 | else |
224 | | - //Incase the UI buttons are slow to disable themselves |
225 | 245 | user.balloon_alert(user, "All out!") |
226 | 246 |
|
227 | | - //Delete instance |
228 | | - qdel(ui_item) |
229 | | - |
230 | 247 | /obj/machinery/food_cart/proc/storage_single(obj/item/target_item, mob/user = usr) |
231 | 248 | //Check if there is room, subtract by 1 since the cart's reagent container is added to its contents |
232 | 249 | if(contents.len - 1 < contents_capacity) |
233 | | - //If item's typepath is not already in food_ui_list, add it |
234 | | - if(!LAZYFIND(food_ui_list, target_item.type)) |
235 | | - LAZYADD(food_ui_list, target_item.type) |
| 250 | + //If item is not already in food_ui_list, add it |
| 251 | + var/in_list = FALSE |
| 252 | + for(var/datum/data/cart_item/item in food_ui_list) |
| 253 | + if(item.type_path == target_item.type) |
| 254 | + //Increment amount by 1 |
| 255 | + item.amount += 1 |
| 256 | + //Set in_list to true and end loop |
| 257 | + in_list = TRUE |
| 258 | + break |
| 259 | + if(!in_list) |
| 260 | + LAZYADD(food_ui_list, new /datum/data/cart_item(target_item)) |
236 | 261 | //Move item to content |
237 | 262 | target_item.forceMove(src) |
238 | 263 | user.visible_message(span_notice("[user] inserts [target_item] into [src]."), span_notice("You insert [target_item] into [src].")) |
|
258 | 283 | else |
259 | 284 | user.balloon_alert(user, "No Drinking Glasses!") |
260 | 285 |
|
261 | | -/obj/machinery/food_cart/proc/find_amount(obj/item/counting_item, target_name = null, list/target_list = null) |
262 | | - var/amount = 0 |
263 | | - |
264 | | - //If target_list is null, search contents for type paths |
265 | | - if(!target_list) |
266 | | - //Loop through contents, counting every instance of the given target |
267 | | - for(var/obj/item/list_item in contents) |
268 | | - if(list_item.type == counting_item.type) |
269 | | - amount += 1 |
270 | | - //Else, search target_list |
271 | | - else |
272 | | - for(var/list_item in target_list) |
273 | | - if(list_item == target_name) |
274 | | - amount += 1 |
275 | | - |
276 | | - return amount |
277 | | - |
278 | 286 | /obj/machinery/food_cart/proc/last_index(obj/item/search_item) |
279 | 287 | var/obj/item/reagent_containers/food/snacks/item_index = null |
280 | 288 |
|
|
0 commit comments