Files
vgstation13/code/modules/html_interface/href_multipart_handler.dm
ShiftyRail d66a3da9d5 Custom painting revival (#31563)
* First steps. Template and some BYOND-side work

* Change of plans, fuck NanoUI, we html_interface nao.
Canvas painting code moved to it's own .dm, .tmpl split into .tpml and .js.
You can use a pen on a canvas to start drawing, can't save your drawing yet but it loads whatever data was already in there.
So far so good.

* Tweaks nanotrasen.css cause it SUCKS.
Link buttons behave like shared.css', and text inputs look better (that border had no business being so thick).
TODO: Check the MSGS' _UI cause it had a button input that looked like ass because of the CSS applying to all inputs

* UI and UI code overhaul. Topic receives data.
TODO: clean up UI code, It's a mess. paintTool.js should probably get split up further, separate the painting from the blending modes or something.

* Sanity, saving, description, and href-multi integration

* Yay, procastrination. Also, split UI and Topic logic into reusable datum separate from object, and some more sanity.
I really should get to the "display the painting in-game" part at some point

* IT WORKS! Paintings are showing up in game.

* Crayons! And pens and color and stuff

* Soap to clean/blank, and moving "Title" before "Author" on UI

* Couple fixes

* Paint brushes! Icons may need replacing, specially inhands

* Cyan paint bucket. UPDATE WIKI: SUPPLY PACKS

* Container fix. Picking a human's blood color as paint is funny, but weird

* Can't quite remember what I was up to last time, moved files to their own folder on /module I guess. Just, getting my stuff out there for a PR

* Supply crate and Eneocho's glass idea

* fugg

* Color transparency and movement throttling

* Hair dye spray cans.
Outperformed by rainbow crayons, those get two colors on top of the picker. Should implement brush size to give them an actual advantage. Maybe stronger paint?

* Fixes a couple oopsies after rebasing to (as of writing) current Bleeding Edge

* new icons

* .dme

* Palette

Co-authored-by: JellyVeggie2 <78439377+jellyveggie2@users.noreply.github.com>
2021-12-12 14:33:51 -06:00

79 lines
2.8 KiB
Plaintext

/*
* ==== HREF multipart handler ====
* For situations where your Topic() link exceeds the browser's ~2000 character limit and ends up ignored
*
* Give your atom a handler, specifying said atom as the handler's parent on New(), and have your atom's Topic() be redirected to
* the handler if the href contains the 'multipart=1' parameter.
* An example would look like this:
*
* /obj/foo
* var/datum/href_multipart_handler/mp_handler
*
* /obj/foo/New()
* ..()
* mp_handler = new /datum/href_multipart_handler(src)
* ...
*
* /obj/foo/Topic(href, href_list)
* if (href_list["multipart"])
* mp_handler.Topic(href, href_list)
* else
*
* On your UI's headers, import href_multipart_handler.js and have your submit link pass it's href through 'HREFmultipartHandler()'
* (See '/code/modules/html_interface/href_multipart_handler.js' for more info)
*
*
* == How it works ==
* As explained, the parent atom's Topic() receives a multipart request that is redirected to this handler.
*
* This request contains the following parameters:
* - src: As with all Topic() links, specifies the object that'll handle the request
* - multipart: Specifies that this is a multipart request. Will always be '1'
* - multipart-total: Specifies how many more requests to expect
* - multipart-number: Specifies which part this is, so that all parts may be reassembled in order
* - multipart-content: The actual payload, percent encoded. The parameters you were trying to send but had to be sliced up.
*
* Each part's multipart-content is stored in an array, sorted by multipart-number as there's a risk parts may arrive out of order. Once
* all parts have been received the array's contents are pieced together, decoded, and used to call the parent atom's Topic().
*
*/
/datum/href_multipart_handler
var/atom/parent
var/list/parts
/datum/href_multipart_handler/New(parent)
..()
src.parent = parent
/datum/href_multipart_handler/Destroy()
..()
parent = null
parts = null
/datum/href_multipart_handler/proc/set_parent(parent)
src.parent = parent
/datum/href_multipart_handler/Topic(href, href_list)
if(href_list["multipart"])
// Initialize the list to the size specified by 'multipart-total'
if (!parts)
parts = new /list(text2num(href_list["multipart-total"]))
// Store the part we've received
parts[text2num(href_list["multipart-number"])] = href_list["multipart-content"]
// Check wether we've received all parts
var/complete = 1
for (var/i = 1; i <= parts.len && complete; i++)
complete = complete && parts[i]
// If we've received the complete set, piece it all together and pass the resulting parameters back to our parent object's Topic()
if (complete)
var/content = "";
for (var/c in parts)
content += c
content = url_decode(content)
parts = null
parent.Topic(content, params2list(content))