Files
Bubberstation/code/modules/library/lib_machines.dm
LemonInTheDark 4b4e9dff1d Wallening [IDB IGNORE] [MDB IGNORE] (#85491)
## What's going on here

Kept you waitin huh!

This pr resprites most all walls, windows and other "wall adjacent"
things to a 3/4th perspective, technical term is "tall" walls (we are
very smart).

If you're trying to understand the technical details here, much of the
"rendering tech" is built off the idea of split-vis. Basically, split a
sprite up and render it on adjacent turfs, to prevent seeing "through"
walls/doors, and to support seeing "edges" without actually seeing the
atom itself.

Most of the rest of it is pipelining done to accommodate how icons are
cut.

## Path To Merge

Almost* all sprites and code is done at this point. 
There are some things missing both on and off the bounty list, but that
will be the case forever unless we force upstream (you guys) to stop
adding new shit that doesn't fit the style.
I plan on accepting and integrating prs to the current working repo
<https://github.com/wall-nerds/wallening> up until a merge, to make
contribution simpler and allow things like bounties to close out more
easily

This pr is quite bulky, even stripping away map changes it's maybe 7000
LOC (We have a few maps that were modified with UpdatePaths, I am also
tentatively pring our test map, for future use.)
This may inhibit proper review, although that is part of why I am
willing to make it despite my perfectionism. Apologies in advance.

Due to the perspective shift, a lot of mapping work is going to need to
be done at some point. This comes in varying levels of priority. Many
wallmounts are offset by hand, some are stuck in the wall/basically
cannot be placed on the east/west/north edges of walls (posters), some
just don't look great good in their current position.

Tests are currently a minor bit yorked, I thought it was more important
to get this up then to clean them fully.

## What does it look like?


![dreamseeker_hBsU6wCu91](https://github.com/user-attachments/assets/5392fa3b-60f6-40ea-876f-e686f25f996a)

![dreamseeker_CTiK0Je5iR](https://github.com/user-attachments/assets/1aee23bd-a5ec-4679-b094-d044401b7222)

![dreamseeker_HYkS1Q9GRq](https://github.com/user-attachments/assets/bad8844b-3179-4856-8684-f912e14e844a)

![dreamseeker_Pa18tgyKYp](https://github.com/user-attachments/assets/c2e1d222-9e5c-4500-8829-dd065428644a)

![dreamseeker_BfOBwS2mjH](https://github.com/user-attachments/assets/7dc51153-111d-4b17-93c3-8389daa6b60b)

![dreamseeker_iJazOumiMQ](https://github.com/user-attachments/assets/5837e203-3865-4f60-854e-62b4875c6b99)

## Credits

<details>
<summary>Historical Mumbojumbo</summary>

I am gonna do my best to document how this project came to be. I am
operating off third party info and half remembered details, so if I'm
wrong please yell at me.

This project started sometime in late 2020, as a product of Rohesie
trying to integrate and make easier work from Mojave Sun (A recently
defunct fallout server) with /tg/.

Mojave Sun (Apparently this was LITERALLY JUST infrared baron, that man
is insane) was working with tall walls, IE walls that are 48px tall
instead of the normal 32. This was I THINK done based off a technical
prototype from aao7 proving A it was possible and B it didn't look like
dogwater.

This alongside oranges begging the art team for 3/4th walls (he meant
TGMC style) lead to Rohesie bringing on contributors from general /tg/,
including actionninja who would eventually take over as technical lead
and Kryson, who would define /tg/'s version of the artstyle. Much of the
formative aspects of this project are their work.

The project was coming along pretty well for a few months, but ran into
serious technical issues with `SIDE_MAP`, a byond map_format that allows
for simpler 3/4th rendering.
Due to BULLSHIT I will not detail here, the map format caused issues
both at random with flickering and heavily with multiz.

Concurrent with this, action stepped down after hacking out the
rendering tech and starting work on an icon cutter that would allow for
simpler icon generation, leaving ninjanomnom to manage the project.

Some time passed, and the project stalled out due to the technical
issues. Eventually I built a test case for the issues we had with
`SIDE_MAP` and convinced lummox jr (byond's developer) to explain how
the fuckin thing actually worked. This understanding made the project
theoretically possible, but did not resolve the problems with multi-z.
Resolving those required a full rework of how rendering like, worked. I
(alongside tattle) took over project development from ninjanomnom at
this time, and started work on Plane Cube (#69115), which when finished
would finally make the project technically feasible.

The time between then and now has been slow, progressive work. Many many
artists and technical folks have dumped their time into this (as you can
see from the credits). I will get into this more below but I would like
to explicitly thank (in no particular order) tattle, draco, arcanemusic,
actionninja, imaginos, viro and kylerace for keeping the project alive
in this time period. I would have curled up into a ball and died if I
had to do this all myself, your help has been indispensable.

</details>

<details>
<summary>Detailed Credits</summary>

Deep apologies if I have forgotten someone (I am sure I have, if someone
is you please contact me). I've done my best to collate from the git
log/my memory.

Thanks to (In no particular order):
Raccoff: Being funny to bully, creating threshold decals for airlocks
aa07: (I think) inspiring the project
ActionNinja: Laying the technical rock we build off, supporting me
despite byond trying to kill him, building the icon cutter that makes
this possible
ArcaneMusic: Artistic and technical work spanning from the project's
start to literally today, being a constant of motivation and positivity.
I can't list all the stuff he's done
Armhulen: Key rendering work (he's the reason thindows render right), an
upbeat personality and a kick in the ass. Love you arm
Azlan: Damn cool sprites, consistently
Ben10Omintrix: You know ben showed up just to make basic mobs work, he's
just fuckin like that man
BigBimmer: A large amount of bounty work, alongside just like, throwing
shit around. An absolute joy to work with
Capsandi: Plaques, blastdoors, artistic work early on
CapybaraExtravagante: Rendering work on wall frames
Draco: SO MUCH STUFF. Much of the spritework done over the past two
years is his, constantly engaged and will take on anything. I would have
given up if not for you
Floyd: Early rendering work, so early I don't even know the details.
Enjoy freedom brother
Imaginos16: A guiding hand through the middle years, handled much of the
sprite review and contribution for a good bit there
Iamgoofball: A dedication to detail and aesthetic goals, spends a lot of
effort dissecting feedback with a focus on making things as good as they
can be at the jump
Infrared: Part of the impetus for the project, made all the xenomorph
stuff in the MS style
Jacquerel: A bunch of little upkeep/technical things, has done so much
sprite gruntwork (WHY ARE THERE SO MANY PAINTING TYPES)
Justice12354: Solved a bunch of error sprites (and worked out how to
actually make prs to the project) Thanks bro!
Kryson: Built the artstyle of the project, carrying on for years even
when it was technically dying, only stopping to casually beat cancer. So
much of our style and art is Kryson
KylerAce: Handled annoying technical stuff for me, built window frame
logic and fully got rid of grilles.
LemonInTheDark: Rendering dirtywork, project management and just so much
fucking time in dreammaker editing sprites
Meyhazah: Table buttons, brass windows and alll the old style doors
Mothblocks: Has provided constant support, gave me a deadline and
motivation, erased worries about "it not being done", gave just SO much
money to fill in the critical holes in sprites. Thanks moth
MTandi: Contributed art despite his own blackjack and hookers club
opening right down the road, I'm sorry I rolled over some of your
sprites man I wish we had finished earlier
Ninjanomnomnom: Consulted on gags issues, kept things alive through some
truly shit times
oranges: This is his fault
Rohesie: Organized the effort, did much of the initial like, proof of
concept stuff. I hope you're doin well whatever you're up to.
san7890: Consulting on mapper UX/design problems, being my pet mapper
Senefi: Offsetting items with a focus on detail/the more unused
canidates
SimplyLogan: Detailed map work and mapper feedback, personally very kind
even if we end up talking past each other sometimes. Thank you!
SpaceSmithers: Just like, random mapping support out of nowhere, and
bein a straight up cool dude
Tattle: A bunch of misc project management stuff, organizing the
discord, managing the test server, dealing with all the mapping bullshit
for me, being my backup in case of bus. I know you think you didn't do
much but your presence and work have been a great help
Thunder12345: Came out of nowhere and just so much of the random
bounties, I'm kind of upset about how much we paid him
Time-Green: I hooked him in by fucking with stuff he made and now he's
just doin shit, thanks for helping out man!
Twaticus: Provided artistic feedback and authority for my poor feeble
coder brain, believed in the project for YEARS, was a constant source of
❤️ and affirmation
unit0016: I have no god damn idea who she is, popped out of nowhere on
the github one day and dealt with a bunch of annoying
rendering/refactoring. Godspeed random furry thank you for all your
effort and issue reports
Viro: A bunch of detailed spriting moving towards 3/4ths, both on and
off the wallening fork. If anyone believed this project would be done,
it was viro
Wallem: Artistic review and consultation, was my go-to guy for a long
time when the other two spritetainers were inactive
Waltermeldon: Cracked out a bunch of rendering work, he's the reason
windows look like not dogwater. Alongside floyd and action spent a TON
of time speaking to lummox/unearthing how byond rendering worked trying
to make this thing happen
ZephyrTFA: Added directional airlock helpers, dealt with a big fuckin
bugaboo that was living in my brain like it was nothing. Love you
brother

And finally:
The Mojave Sun development team. They provided a testbed for the idea,
committed hundreds and hundreds of hours to the artstyle, and were a
large reason we caught issues early enough to meaningfully deal with
them. Your work is a testament to what longterm effort and deep detailed
care produce. I hope you're doing well whatever you're up to. Go out
with a bang!
</details>

## Changelog
🆑 Raccoff, aa07, ActionNinja, ArcaneMusic, Armhulen, Azlan,
Ben10Omintrix, BigBimmer, Capsandi, CapybaraExtravagante, Draco, Floyd,
Iamgoofball, Imaginos16, Infrared, Jacquerel, Justice12354, Kryson,
KylerAce, LemonInTheDark, Meyhazah, Mothblocks, MTandi, Ninjanomnom,
oranges, Rohesie, Runi-c, san7890, Senefi, SimplyLogan, SomeAngryMiner,
SpaceSmithers, Tattle, Thunder12345, Time-Green, Twaticus, unit0016,
Viro, Waltermeldon, ZephyrTFA with thanks to the Mojave Sun team!
add: Resprites or offsets almost all "tall" objects in the game to match
a 3/4ths perspective
add: Bunch of rendering mumbo jumbo to make said 3/4ths perspective work
/🆑

---------

Co-authored-by: Jacquerel <hnevard@gmail.com>
Co-authored-by: san7890 <the@san7890.com>
Co-authored-by: = <stewartareid@outlook.com>
Co-authored-by: Capsandi <dansullycc@gmail.com>
Co-authored-by: ArcaneMusic <hero12290@aol.com>
Co-authored-by: tattle <66640614+dragomagol@users.noreply.github.com>
Co-authored-by: SomeAngryMiner <53237389+SomeAngryMiner@users.noreply.github.com>
Co-authored-by: KylerAce <kylerlumpkin1@gmail.com>
Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com>
Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com>
Co-authored-by: lessthanthree <83487515+lessthnthree@users.noreply.github.com>
Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
Co-authored-by: Runi-c <5150427+Runi-c@users.noreply.github.com>
Co-authored-by: Roryl-c <5150427+Roryl-c@users.noreply.github.com>
Co-authored-by: tattle <article.disaster@gmail.com>
Co-authored-by: Senefi <20830349+Peliex@users.noreply.github.com>
Co-authored-by: Justice <42555530+Justice12354@users.noreply.github.com>
Co-authored-by: BluBerry016 <50649185+unit0016@users.noreply.github.com>
Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com>
Co-authored-by: Emmett Gaines <ninjanomnom@gmail.com>
Co-authored-by: Rob Bailey <github@criticalaction.net>
Co-authored-by: MMMiracles <lolaccount1@hotmail.com>
2024-08-14 09:07:45 +00:00

860 lines
30 KiB
Plaintext

/* Library Machines
*
* Contains:
* Borrowbook datum
* Library Public Computer
* Book Info datum
* Library Computer
* Library Scanner
* Book Binder
*/
GLOBAL_VAR_INIT(library_table_modified, 0)
/// Increments every time WE update the library db table, causes all existing consoles to repull when they next check
/proc/library_updated()
GLOB.library_table_modified = (GLOB.library_table_modified + 1) % (SHORT_REAL_LIMIT - 1)
/*
* Library Public Computer
*/
/obj/machinery/computer/libraryconsole
name = "library visitor console"
icon_state = "oldcomp"
icon_screen = "library"
icon_keyboard = null
circuit = /obj/item/circuitboard/computer/libraryconsole
desc = "Checked out books MUST be returned on time."
anchored_tabletop_offset = 8
///The current book id we're searching for
var/book_id = null
///The current title we're searching for
var/title = ""
///The category we're searching for
var/category = ""
///The author we're searching for
var/author = ""
///The results of our last query
var/list/page_content = list()
///The the total pages last we checked
var/page_count = 0
///The page of our current query
var/search_page = 0
///Can we connect to the db?
var/can_connect = FALSE
///A hash of the last search we did, prevents spam in a different way then the cooldown
var/last_search_hash = ""
///Have the search params changed at all since the last search?
var/params_changed = FALSE
///Are we currently sending a db request for books?
var/sending_request = FALSE
///Prevents spamming requests, acts as a second layer of protection against spam
COOLDOWN_DECLARE(db_request_cooldown)
///Interface name for the ui_interact call for different subtypes.
var/interface_type = "LibraryVisitor"
/obj/machinery/computer/libraryconsole/Initialize(mapload)
. = ..()
category = DEFAULT_SEARCH_CATAGORY
INVOKE_ASYNC(src, PROC_REF(update_db_info))
/obj/machinery/computer/libraryconsole/ui_interact(mob/user, datum/tgui/ui)
. = ..()
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, interface_type)
ui.open()
/obj/machinery/computer/libraryconsole/ui_data(mob/user)
var/list/data = list()
data["can_db_request"] = can_db_request()
data["search_categories"] = SSlibrary.search_categories
data["category"] = category
data["author"] = author
data["title"] = title
data["book_id"] = book_id
data["page_count"] = page_count + 1 //Increase these by one so it looks like we're not indexing at 0
data["our_page"] = search_page + 1
data["pages"] = page_content
data["can_connect"] = can_connect
data["params_changed"] = params_changed
return data
/obj/machinery/computer/libraryconsole/ui_act(action, params)
. = ..()
if(.)
return
switch(action)
if("set_search_id")
var/newid = text2num(params["id"])
if(newid != book_id)
params_changed = TRUE
book_id = newid
return TRUE
if("set_search_title")
var/newtitle = params["title"]
if(newtitle != title)
params_changed = TRUE
title = newtitle
return TRUE
if("set_search_category")
var/newcategory = params["category"]
if(!(newcategory in SSlibrary.search_categories)) //Nice try
newcategory = DEFAULT_SEARCH_CATAGORY
if(newcategory != category)
params_changed = TRUE
category = newcategory
return TRUE
if("set_search_author")
var/newauthor = params["author"]
if(newauthor != author)
params_changed = TRUE
author = newauthor
return TRUE
if("search")
if(!prevent_db_spam())
say("Database cables refreshing. Please wait a moment.")
return
INVOKE_ASYNC(src, PROC_REF(update_db_info))
return TRUE
if("switch_page")
if(!prevent_db_spam())
say("Database cables refreshing. Please wait a moment.")
return
search_page = sanitize_page_input(params["page"], search_page, page_count)
INVOKE_ASYNC(src, PROC_REF(update_db_info))
return TRUE
if("clear_data") //The cap just walked in on your browsing, quick! delete it!
if(!prevent_db_spam())
say("Database cables refreshing. Please wait a moment.")
return
title = initial(title)
author = initial(author)
category = DEFAULT_SEARCH_CATAGORY
search_page = 0
INVOKE_ASYNC(src, PROC_REF(update_db_info))
return TRUE
///Checks if the machine is alloweed to make another db request yet. TRUE if so, FALSE otherwise
/obj/machinery/computer/libraryconsole/proc/prevent_db_spam()
var/allowed = can_db_request()
if(!allowed)
return FALSE
COOLDOWN_START(src, db_request_cooldown, 1 SECONDS)
return TRUE
/obj/machinery/computer/libraryconsole/proc/can_db_request()
if(sending_request) //Absolutely not
return FALSE
if(!COOLDOWN_FINISHED(src, db_request_cooldown))
return FALSE
return TRUE
///Returns a santized page input, so converted from num/text to num, and properly maxed
/obj/machinery/computer/libraryconsole/proc/sanitize_page_input(input, default, max)
input = convert_ambiguous_input(input, default + 1) // + 1 to invert the below reasons
//We expect the search page to be one greater then it should be, because we're lying about indexing at 1
return clamp(input - 1, 0, max)
///Takes input that could either be a number, or a string that represents a number and returns a number
/obj/machinery/computer/libraryconsole/proc/convert_ambiguous_input(input, default)
if(isnum(input))
return input
if(!istext(input))
return default
var/hidden_number = text2num(input)
if(!isnum(hidden_number))
return default
return hidden_number
/obj/machinery/computer/libraryconsole/proc/update_db_info()
if(!has_anything_changed()) //You're not allowed to make the same search twice, waste of resources
return
if (!SSdbcore.Connect())
can_connect = FALSE
page_count = 0
page_content = list()
return
can_connect = TRUE
params_changed = FALSE
last_search_hash = hash_search_info()
update_page_count()
update_page_contents()
SStgui.update_uis(src) //We need to do this because we sleep here, so we've gotta update manually
//Returns true if there's been an update worth refreshing our pages for, false otherwise
/obj/machinery/computer/libraryconsole/proc/has_anything_changed()
if(last_search_hash == hash_search_info())
return FALSE
return TRUE
/obj/machinery/computer/libraryconsole/proc/hash_search_info()
return "[GLOB.library_table_modified]-[book_id]-[title]-[author]-[category]-[search_page]-[page_count]"
/obj/machinery/computer/libraryconsole/proc/update_page_contents()
if(sending_request) //Final defense against nerds spamming db requests
return
sending_request = TRUE
search_page = clamp(search_page, 0, page_count)
var/datum/db_query/query_library_list_books = SSdbcore.NewQuery({"
SELECT author, title, category, id
FROM [format_table_name("library")]
WHERE isnull(deleted)
AND author LIKE CONCAT('%',:author,'%')
AND title LIKE CONCAT('%',:title,'%')
AND (:category = 'Any' OR category = :category)
[book_id ? "AND id LIKE CONCAT('%', :book_id, '%')" : ""]
ORDER BY id DESC
LIMIT :skip, :take
"}, list("author" = author, "title" = title, "book_id" = book_id, "category" = category, "skip" = BOOKS_PER_PAGE * search_page, "take" = BOOKS_PER_PAGE))
var/query_succeeded = query_library_list_books.Execute()
sending_request = FALSE
page_content.Cut()
if(!query_succeeded)
qdel(query_library_list_books)
return
while(query_library_list_books.NextRow())
page_content += list(list(
"author" = html_decode(query_library_list_books.item[1]),
"title" = html_decode(query_library_list_books.item[2]),
"category" = query_library_list_books.item[3],
"id" = query_library_list_books.item[4]
))
qdel(query_library_list_books)
/obj/machinery/computer/libraryconsole/proc/update_page_count()
var/bookcount = 0
var/datum/db_query/query_library_count_books = SSdbcore.NewQuery({"
SELECT COUNT(id) FROM [format_table_name("library")]
WHERE isnull(deleted)
AND author LIKE CONCAT('%',:author,'%')
AND title LIKE CONCAT('%',:title,'%')
AND (:category = 'Any' OR category = :category)
[book_id ? "AND id LIKE CONCAT('%', :book_id, '%')" : ""]
"}, list("author" = author, "title" = title, "book_id" = book_id, "category" = category))
if(!query_library_count_books.warn_execute())
qdel(query_library_count_books)
return
if(query_library_count_books.NextRow())
bookcount = text2num(query_library_count_books.item[1])
qdel(query_library_count_books)
page_count = round(max(bookcount - 1, 0) / BOOKS_PER_PAGE) //This is just floor()
search_page = clamp(search_page, 0, page_count)
/*
* Borrowbook datum
*/
/datum/borrowbook // Datum used to keep track of who has borrowed what when and for how long.
var/datum/book_info/book_data
var/loanedto
var/checkout
var/duedate
#define PRINTER_COOLDOWN (6 SECONDS)
#define NEWSCASTER_COOLDOWN (10 SECONDS)
#define LIBRARY_NEWSFEED "Nanotrasen Book Club"
//The different states the computer can be in, only send the info we need yeah?
#define LIBRARY_INVENTORY 1
#define LIBRARY_CHECKOUT 2
#define LIBRARY_ARCHIVE 3
#define LIBRARY_UPLOAD 4
#define LIBRARY_PRINT 5
#define LIBRARY_TOP_SNEAKY 6
#define MIN_LIBRARY LIBRARY_INVENTORY
#define MAX_LIBRARY LIBRARY_TOP_SNEAKY
/*
* Library Computer
* After 860 days, it's finally a buildable computer.
*/
// TODO: Make this an actual /obj/machinery/computer that can be crafted from circuit boards and such
// It is August 22nd, 2012... This TODO has already been here for months.. I wonder how long it'll last before someone does something about it.
// It's December 25th, 2014, and this is STILL here, and it's STILL relevant. Kill me
/obj/machinery/computer/libraryconsole/bookmanagement
name = "book inventory management console"
desc = "Librarian's command station."
verb_say = "beeps"
verb_ask = "beeps"
verb_exclaim = "beeps"
pass_flags = PASSTABLE
icon_state = "oldcomp"
icon_screen = "library"
icon_keyboard = null
circuit = /obj/item/circuitboard/computer/libraryconsole
interface_type = "LibraryConsole"
///Can spawn secret lore item
var/can_spawn_lore = TRUE
///The screen we're currently on, sent to the ui
var/screen_state = LIBRARY_INVENTORY
///Should we show the buttons required for changing screens?
var/show_dropdown = TRUE
///List of checked out books, /datum/borrowbook
var/list/checkouts = list()
///The current max amount of checkout pages allowed
var/checkout_page_count = 0
///The current page we're on in the checkout listing
var/checkout_page = 0
///List of book info datums to display to the user as our "inventory"
var/list/inventory = list()
///The current max amount of inventory pages allowed
var/inventory_page_count = 0
///The current page we're on in the inventory
var/inventory_page = 0
///Should we load our inventory from the bookselves in our area?
var/dynamic_inv_load = FALSE
///Book scanner that will be used when uploading books to the Archive
var/datum/weakref/scanner
///Our cooldown on using the printer
COOLDOWN_DECLARE(printer_cooldown)
///Our cooldown on publishing books to the newscaster's "book club" channel
COOLDOWN_DECLARE(newscaster_cooldown)
/obj/machinery/computer/libraryconsole/bookmanagement/Initialize(mapload)
. = ..()
if(mapload)
dynamic_inv_load = TRUE //Only load in stuff if we were placed during mapload
/obj/machinery/computer/libraryconsole/bookmanagement/ui_static_data(mob/user)
var/list/data = list()
data["inventory"] = list()
var/inventory_len = length(inventory)
if(inventory_len)
for(var/id in ((INVENTORY_PER_PAGE * inventory_page) + 1) to min(INVENTORY_PER_PAGE * (inventory_page + 1), inventory_len))
var/book_ref = inventory[id]
var/datum/book_info/info = inventory[book_ref]
data["inventory"] += list(list(
"id" = id,
"ref" = book_ref,
"title" = info.get_title(),
"author" = info.get_author(),
))
data["has_inventory"] = !!inventory_len
data["inventory_page"] = inventory_page + 1
data["inventory_page_count"] = inventory_page_count + 1
return data
/obj/machinery/computer/libraryconsole/bookmanagement/ui_data(mob/user)
var/list/data = list()
data["can_db_request"] = can_db_request()
data["screen_state"] = screen_state
data["show_dropdown"] = show_dropdown
data["display_lore"] = (obj_flags & EMAGGED && can_spawn_lore)
if(dynamic_inv_load) //Time to load those area books in
dynamic_inv_load = FALSE
load_nearby_books()
switch(screen_state)
if(LIBRARY_CHECKOUT)
data["checkouts"] = list()
var/checkout_len = length(checkouts)
if(checkout_len)
for(var/id in ((CHECKOUTS_PER_PAGE * checkout_page) + 1) to min(CHECKOUTS_PER_PAGE * (checkout_page + 1), checkout_len))
var/checkout_ref = checkouts[id]
var/datum/borrowbook/loan = checkouts[checkout_ref]
var/timedue = (loan.duedate - world.time) / (1 MINUTES)
timedue = max(round(timedue, 0.1), 0)
data["checkouts"] += list(list(
"id" = id,
"ref" = checkout_ref,
"borrower" = loan.loanedto || "N/A",
"overdue" = (timedue <= 0),
"due_in_minutes" = timedue,
"title" = loan.book_data.get_title(),
"author" = loan.book_data.get_author(),
))
data["has_checkout"] = !!checkout_len
data["checkout_page"] = checkout_page + 1
data["checkout_page_count"] = checkout_page_count + 1
//Copypasta from the visitor console
if(LIBRARY_ARCHIVE)
data |= ..() //I am so sorry
if(LIBRARY_UPLOAD)
data["upload_categories"] = SSlibrary.upload_categories
data["default_category"] = DEFAULT_UPLOAD_CATAGORY
var/obj/machinery/libraryscanner/scan = get_scanner()
data["has_scanner"] = !!(scan)
data["has_cache"] = !!(scan?.cache)
data["cooldown_string"] = "[DisplayTimeText(COOLDOWN_TIMELEFT(src, newscaster_cooldown))]"
data["active_newscaster_cooldown"] = COOLDOWN_FINISHED(src, newscaster_cooldown)
if(scan?.cache)
data["cache_title"] = scan.cache.get_title()
data["cache_author"] = scan.cache.get_author()
data["cache_content"] = scan.cache.get_content()
if(LIBRARY_PRINT)
data["deity"] = GLOB.deity || DEFAULT_DEITY
var/reigion = GLOB.religion || DEFAULT_RELIGION
data["religion"] = reigion
var/bible_name = GLOB.bible_name
if(!bible_name)
bible_name = DEFAULT_BIBLE_REPLACE(reigion)
data["bible_name"] = bible_name
data["bible_sprite"] = "display-[GLOB.bible_icon_state || "bible"]"
data["posters"] = list()
for(var/poster_name in SSlibrary.printable_posters)
data["posters"] += poster_name
return data
/obj/machinery/computer/libraryconsole/bookmanagement/ui_assets(mob/user)
return list(get_asset_datum(/datum/asset/spritesheet/bibles))
/obj/machinery/computer/libraryconsole/bookmanagement/proc/load_nearby_books()
for(var/datum/book_info/book as anything in SSlibrary.get_area_books(get_area(src)))
inventory[ref(book)] = book
inventory_update()
/obj/machinery/computer/libraryconsole/bookmanagement/proc/get_scanner(viewrange)
if(scanner)
var/obj/machinery/libraryscanner/potential_scanner = scanner.resolve()
if(potential_scanner)
return potential_scanner
scanner = null
for(var/obj/machinery/libraryscanner/foundya in range(viewrange, get_turf(src)))
scanner = WEAKREF(foundya)
return foundya
/obj/machinery/computer/libraryconsole/bookmanagement/ui_act(action, params)
//The parent call takes care of stuff like searching, don't forget about that yeah?
. = ..()
if(.)
return
switch(action)
if("set_screen")
var/window = params["screen_index"]
set_screen_state(window)
return TRUE
if("toggle_dropdown")
show_dropdown = !show_dropdown
return TRUE
if("inventory_remove")
var/id = params["book_id"]
inventory -= id
inventory_update()
return TRUE
if("switch_inventory_page")
inventory_page = sanitize_page_input(params["page"], inventory_page, inventory_page_count)
inventory_update()
return TRUE
if("checkout")
var/list/available = list()
for(var/id in inventory)
var/datum/book_info/book_infos = inventory[id]
available[book_infos.title] = book_infos
var/book_name = params["book_name"]
if(QDELETED(src) || !book_name)
return
var/datum/book_info/book_info = available[book_name]
if(!istype(book_info))
return
var/datum/borrowbook/loan = new /datum/borrowbook
var/loan_to = copytext(sanitize(params["loaned_to"]), 1, MAX_NAME_LEN)
var/checkoutperiod = max(params["checkout_time"], 1)
loan.book_data = book_info.return_copy()
loan.loanedto = loan_to
loan.checkout = world.time
loan.duedate = world.time + (checkoutperiod MINUTES)
checkouts[ref(loan)] = loan
checkout_update()
return TRUE
if("checkin")
var/id = params["checked_out_id"]
checkouts -= id
checkout_update()
return TRUE
if("switch_checkout_page")
checkout_page = sanitize_page_input(params["page"], checkout_page, checkout_page_count)
checkout_update()
return TRUE
if("set_cache_title")
var/obj/machinery/libraryscanner/scan = get_scanner()
if(scan?.cache && params["title"])
scan.cache.set_title(params["title"])
return TRUE
if("set_cache_author")
var/obj/machinery/libraryscanner/scan = get_scanner()
if(scan?.cache && params["author"])
scan.cache.set_author(params["author"])
return TRUE
if("upload")
if(!prevent_db_spam())
say("Database cables refreshing. Please wait a moment.")
return
var/upload_category = params["category"]
if(!(upload_category in SSlibrary.upload_categories)) //Nice try
upload_category = DEFAULT_UPLOAD_CATAGORY
INVOKE_ASYNC(src, PROC_REF(upload_from_scanner), upload_category)
return TRUE
if("news_post")
// We grey out the button UI-side, but let's just be safe to guard against spammy spammers.
if(!COOLDOWN_FINISHED(src, newscaster_cooldown))
say("Not enough time has passed since the last news post. Please wait.")
return
if(!GLOB.news_network)
say("No news network found on station. Aborting.")
var/channelexists = FALSE
for(var/datum/feed_channel/feed in GLOB.news_network.network_channels)
if(feed.channel_name == LIBRARY_NEWSFEED)
channelexists = TRUE
break
if(!channelexists)
GLOB.news_network.create_feed_channel(LIBRARY_NEWSFEED, "Library", "The official station book club!", null)
var/obj/machinery/libraryscanner/scan = get_scanner()
if(!scan)
say("No nearby scanner detected. Aborting.")
return
GLOB.news_network.submit_article(scan.cache.content, "[scan.cache.author]: [scan.cache.title]", LIBRARY_NEWSFEED, null)
say("Upload complete. Your uploaded title is now available on station newscasters.")
COOLDOWN_START(src, newscaster_cooldown, NEWSCASTER_COOLDOWN)
return TRUE
if("print_book")
var/id = params["book_id"]
attempt_print(CALLBACK(src, PROC_REF(print_book), id))
return TRUE
if("print_bible")
attempt_print(CALLBACK(src, PROC_REF(print_bible)))
return TRUE
if("print_poster")
var/poster_name = params["poster_name"]
attempt_print(CALLBACK(src, PROC_REF(print_poster), poster_name))
return TRUE
if("lore_spawn")
if(obj_flags & EMAGGED && can_spawn_lore)
print_forbidden_lore(usr)
set_screen_state(MIN_LIBRARY)
return TRUE
if("lore_deny")
if(obj_flags & EMAGGED && can_spawn_lore)
shun_the_corp(usr)
set_screen_state(MIN_LIBRARY)
return TRUE
/obj/machinery/computer/libraryconsole/bookmanagement/attackby(obj/item/weapon, mob/user, params)
if(!istype(weapon, /obj/item/barcodescanner))
return ..()
var/obj/item/barcodescanner/scanner = weapon
if(scanner.computer_ref?.resolve() == src)
balloon_alert(user, "already connected!")
return
scanner.computer_ref = WEAKREF(src)
balloon_alert(user, "scanner connected")
audible_message(span_hear("[src] lets out a low, short blip."))
/obj/machinery/computer/libraryconsole/bookmanagement/emag_act(mob/user, obj/item/card/emag/emag_card)
if(!density || obj_flags & EMAGGED)
return FALSE
obj_flags |= EMAGGED
balloon_alert(user, "forbidden knowledge unlocked")
return TRUE
/obj/machinery/computer/libraryconsole/bookmanagement/proc/set_screen_state(new_state)
screen_state = clamp(new_state, MIN_LIBRARY, MAX_LIBRARY)
/obj/machinery/computer/libraryconsole/bookmanagement/proc/inventory_update()
inventory_page_count = round(max(length(inventory) - 1, 0) / INVENTORY_PER_PAGE) //This is just floor()
inventory_page = clamp(inventory_page, 0, inventory_page_count)
/obj/machinery/computer/libraryconsole/bookmanagement/proc/checkout_update()
checkout_page_count = round(max(length(checkouts) - 1, 0) / CHECKOUTS_PER_PAGE) //This is just floor()
checkout_page = clamp(checkout_page, 0, checkout_page_count)
/obj/machinery/computer/libraryconsole/bookmanagement/proc/print_forbidden_lore(mob/user)
can_spawn_lore = FALSE
new /obj/item/melee/cultblade/dagger(get_turf(src))
to_chat(user, span_warning("Your sanity barely endures the seconds spent in the vault's browsing window. The only thing to remind you of this when you stop browsing is a sinister dagger sitting on the desk. You don't even remember where it came from..."))
user.visible_message(span_warning("[user] stares at the blank screen for a few moments, [user.p_their()] expression frozen in fear. When [user.p_they()] finally awaken[user.p_s()] from it, [user.p_they()] look[user.p_s()] a lot older."), vision_distance = 2)
if(ishuman(user))
var/mob/living/carbon/human/fool = user
fool.age = clamp(fool.age + 10, AGE_MIN, AGE_MAX) //Fuck you
/obj/machinery/computer/libraryconsole/bookmanagement/proc/shun_the_corp(mob/user)
can_spawn_lore = FALSE
to_chat(user, span_warning("You click off the page in a rush, and the machine hums back to normal, the tab gone..."))
/obj/machinery/computer/libraryconsole/bookmanagement/proc/upload_from_scanner(upload_category)
var/obj/machinery/libraryscanner/scan = get_scanner()
if(!scan)
say("No nearby scanner detected.")
return
if(!scan.cache)
say("No cached book found. Aborting upload.")
return
if (!SSdbcore.Connect())
say("Connection to Archive has been severed. Aborting.")
return
var/datum/book_info/book = scan.cache
if(!book.title)
say("No title detected. Aborting")
return
if(!book.author)
say("No author detected. Aborting")
return
if(!book.content)
say("No content detected. Aborting")
return
var/msg = "has uploaded the book titled [book.title], [length(book.content)] signs"
var/datum/db_query/query_library_upload = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("library")] (author, title, content, category, ckey, datetime, round_id_created)
VALUES (:author, :title, :content, :category, :ckey, Now(), :round_id)
"}, list("title" = book.title, "author" = book.author, "content" = book.content, "category" = upload_category, "ckey" = usr.ckey, "round_id" = GLOB.round_id))
if(!query_library_upload.Execute())
qdel(query_library_upload)
say("Database error encountered uploading to Archive")
return
usr.log_message(msg, LOG_GAME)
qdel(query_library_upload)
library_updated()
say("Upload Complete. Uploaded title will be available for printing in a moment")
update_db_info()
/// Call this proc to attempt a print. It will return false if the print failed, true otherwise, longside some ux
/// Accepts a callback to call when the print "finishes"
/obj/machinery/computer/libraryconsole/bookmanagement/proc/attempt_print(datum/callback/call_after)
if(!COOLDOWN_FINISHED(src, printer_cooldown))
say("Printer currently unavailable, please wait a moment.")
return FALSE
COOLDOWN_START(src, printer_cooldown, PRINTER_COOLDOWN)
playsound(src, 'sound/machines/printer.ogg', 50)
addtimer(call_after, 4.1 SECONDS)
return TRUE
/obj/machinery/computer/libraryconsole/bookmanagement/proc/print_bible()
var/obj/item/book/bible/holy_book = new(loc)
if(!GLOB.bible_icon_state || !GLOB.bible_inhand_icon_state)
return
holy_book.icon_state = GLOB.bible_icon_state
holy_book.inhand_icon_state = GLOB.bible_inhand_icon_state
holy_book.name = GLOB.bible_name
holy_book.deity_name = GLOB.deity
/obj/machinery/computer/libraryconsole/bookmanagement/proc/print_poster(poster_name)
var/poster_type = SSlibrary.printable_posters[poster_name]
if(!poster_type)
return
new /obj/item/poster(loc, new poster_type)
/obj/machinery/computer/libraryconsole/bookmanagement/proc/print_book(id)
if (!SSdbcore.Connect())
say("Connection to Archive has been severed. Aborting.")
can_connect = FALSE
return
var/datum/db_query/query_library_print = SSdbcore.NewQuery(
"SELECT * FROM [format_table_name("library")] WHERE id=:id AND isnull(deleted)",
list("id" = id)
)
if(!query_library_print.Execute())
qdel(query_library_print)
say("PRINTER ERROR! Failed to print document (0x0000000F)")
return
while(query_library_print.NextRow())
var/author = query_library_print.item[2]
var/title = query_library_print.item[3]
var/content = query_library_print.item[4]
if(!QDELETED(src))
var/obj/item/book/printed_book = new(get_turf(src))
printed_book.name = "Book: [title]"
printed_book.book_data = new()
var/datum/book_info/fill = printed_book.book_data
fill.set_title(title, trusted = TRUE)
fill.set_author(author, trusted = TRUE)
fill.set_content(content, trusted = TRUE)
printed_book.gen_random_icon_state()
visible_message(span_notice("[src]'s printer hums as it produces a completely bound book. How did it do that?"))
log_paper("[key_name(usr)] has printed \"[title]\" (id: [id]) by [author] from a book management console.")
break
qdel(query_library_print)
/*
* Library Scanner
*/
/obj/machinery/libraryscanner
name = "scanner control interface"
icon = 'icons/obj/service/library.dmi'
icon_state = "bigscanner"
desc = "It's an industrial strength book scanner. Perfect!"
circuit = /obj/item/circuitboard/machine/libraryscanner
density = TRUE
var/obj/item/book/held_book
///Our scanned-in book
var/datum/book_info/cache
/obj/machinery/libraryscanner/screwdriver_act(mob/living/user, obj/item/tool)
. = ..()
if(default_deconstruction_screwdriver(user, "bigscanner2", "bigscanner", tool))
return ITEM_INTERACT_SUCCESS
/obj/machinery/libraryscanner/crowbar_act(mob/living/user, obj/item/tool)
. = ..()
if(default_deconstruction_crowbar(tool))
return ITEM_INTERACT_SUCCESS
/obj/machinery/libraryscanner/Destroy()
held_book = null
cache = null
return ..()
/obj/machinery/libraryscanner/attackby(obj/hitby, mob/user, params)
if(istype(hitby, /obj/item/book))
user.transferItemToLoc(hitby, src)
if(held_book)
user.put_in_hands(held_book)
held_book = hitby
playsound(src, 'sound/machines/eject.ogg', 70)
return TRUE
return ..()
/obj/machinery/libraryscanner/Exited(atom/movable/gone, direction)
. = ..()
if(gone == held_book)
held_book = null
/obj/machinery/libraryscanner/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "LibraryScanner")
ui.open()
/obj/machinery/libraryscanner/ui_data()
var/list/data = list()
var/list/cached_info = list()
data["has_book"] = !!held_book
data["has_cache"] = !!cache
if(cache)
cached_info["title"] = cache.get_title()
cached_info["author"] = cache.get_author()
data["book"] = cached_info
return data
/obj/machinery/libraryscanner/ui_act(action, params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
switch(action)
if("scan")
if(cache?.compare(held_book.book_data))
say("This book is already in my internal cache")
return
cache = held_book.book_data.return_copy()
flick("bigscanner1", src)
playsound(src, 'sound/machines/scanner.ogg', vol = 50, vary = TRUE)
return TRUE
if("clear")
cache = null
return TRUE
if("eject")
ui.user.put_in_hands(held_book)
playsound(src, 'sound/machines/eject.ogg', 70)
return TRUE
/*
* Book binder
*/
/obj/machinery/bookbinder
SET_BASE_VISUAL_PIXEL(0, DEPTH_OFFSET)
name = "book binder"
icon = 'icons/obj/service/library.dmi'
icon_state = "binder"
desc = "Only intended for binding paper products."
circuit = /obj/item/circuitboard/machine/bookbinder
density = TRUE
/// Are we currently binding a book?
var/busy = FALSE
/// Name of the author for the book, set by scanning your ID.
var/scanned_name
/obj/machinery/bookbinder/screwdriver_act(mob/living/user, obj/item/tool)
. = ..()
if(default_deconstruction_screwdriver(user, "binder2", "binder", tool))
return ITEM_INTERACT_SUCCESS
/obj/machinery/bookbinder/crowbar_act(mob/living/user, obj/item/tool)
. = ..()
if(default_deconstruction_crowbar(tool))
return ITEM_INTERACT_SUCCESS
/obj/machinery/bookbinder/attackby(obj/hitby, mob/user, params)
if(istype(hitby, /obj/item/paper))
prebind_book(user, hitby)
return TRUE
if(isidcard(hitby))
var/obj/item/card/id/idcard = hitby
scanned_name = idcard.registered_name
balloon_alert(user, "scanned")
return TRUE
return ..()
/obj/machinery/bookbinder/proc/prebind_book(mob/user, obj/item/paper/draw_from)
if(machine_stat)
return
if(busy)
to_chat(user, span_warning("The book binder is busy. Please wait for completion of previous operation."))
return
if(!scanned_name)
scanned_name = "unknown author"
say("No ID detected. Please scan your ID if you would like to be credited for this book. Otherwise please enter your paper again.")
return
if(!user.transferItemToLoc(draw_from, src))
return
user.visible_message(span_notice("[user] loads some paper into [src]."), span_notice("You load some paper into [src]."))
audible_message(span_hear("[src] begins to hum as it warms up its printing drums."))
busy = TRUE
playsound(src, 'sound/machines/printer.ogg', 50)
flick("binder1", src)
addtimer(CALLBACK(src, PROC_REF(bind_book), draw_from), 4.1 SECONDS)
/obj/machinery/bookbinder/proc/bind_book(obj/item/paper/draw_from)
busy = FALSE
if(!draw_from) //What the fuck did you do
return
if(machine_stat)
draw_from.forceMove(drop_location())
return
visible_message(span_notice("[src] whirs as it prints and binds a new book."))
var/obj/item/book/bound_book = new(loc)
bound_book.book_data.set_content_using_paper(draw_from)
bound_book.book_data.set_author(scanned_name, trusted = FALSE)
bound_book.name = "Print Job #" + "[rand(100, 999)]"
bound_book.gen_random_icon_state()
scanned_name = null
qdel(draw_from)
#undef LIBRARY_ARCHIVE
#undef LIBRARY_CHECKOUT
#undef LIBRARY_INVENTORY
#undef LIBRARY_NEWSFEED
#undef LIBRARY_PRINT
#undef LIBRARY_TOP_SNEAKY
#undef LIBRARY_UPLOAD
#undef MAX_LIBRARY
#undef MIN_LIBRARY
#undef NEWSCASTER_COOLDOWN
#undef PRINTER_COOLDOWN