Skip to content

Save generated loadout to URL and allow loading it from there#1

Open
cb109 wants to merge 1 commit intoGrafKnusprig:masterfrom
cb109:share-loadout
Open

Save generated loadout to URL and allow loading it from there#1
cb109 wants to merge 1 commit intoGrafKnusprig:masterfrom
cb109:share-loadout

Conversation

@cb109
Copy link

@cb109 cb109 commented Feb 14, 2022

Nice loadout randomizer, love the slotmachine effect :) 👋

I thought about using this with a friend to get some loadout inspirations, but not being able to share is a bit of a bummer. I did a quick prototype of how that could work by mapping the generated loadout to a URL that can be shared:

  • Loadout is stored as ?loadout=... query parameter.
  • Reloading the page will try to load the loadout from the URL if possible, meaning the URL can be copied and shared with friends.
  • If the value cannot be parsed correctly (e.g. someone has copied only some part of it), a new loadout will be generated instead.
  • Pressing the Go button will always generate a new loadout and update the URL.
  • Since we are actually navigating by changing the URL, we can go backwards with the browser to see recent loadouts or even bookmark them.

Let me know if this is something that you can think of adding, and what I could modify to make that easier. No worries if you don't like it, it was fun to build anyway!

Cheers

Loadout is stored as ?loadout=... query parameter. Reloading the page
will load the loadout from that if possible, meaning the URL can be
copied and shared with friends for them to see the same loadout. If the
value cannot be parsed correctly (e.g. someone has copied only some part
of it), a new loadout will be generated instead. Pressing the Go button
will always generate a new loadout.
@GrafKnusprig
Copy link
Owner

Nice to hear that you like the randomizer :)

I kind of like the idea and will take a closer look.

  • The parameter:

    • First of all it would be necessary to give every weapon and item an id. [0 .. 191]
    • The goal is to keep the URL short since we have 14 slots to encode.
    • I would use a custom "kind-of-base64" encription for the query string and convert every item id into a 2 digit base 64 number, by using a-z, A-Z, 0-9 and "-_". This way it will be much shorter than just concatenating the ids.
    • There is room for optimization, but this way we get a 28 digit parameter and that should be short enough.
    • For example: ".../Randomizer.html?l=0124h3Ue4D5H7E38diHNwi13S45E" would encode a whole loadout.
    • Dual wield is a flag in the randomizer. Since it can only appear on the weapon slots, we could just make the first two base 64 digits the weapons and add another character to set dual. Or another approach would be to add a fixed number before converting.
  • Randomizer workflow:

    • The workflow has to be changed.
    • A new loadout is generated, but not immediately shown.
    • Instead a new URL is made from the generated loadout, which will then be forwarded to.
    • Every "Go" will load a new page.
  • User settings:

    • The URL would be independent from the user settings:
    • The settings only affect the generating of the URL.
    • If another url is opened, the settings are not checked.

I am a little busy at the moment, but I will definitely give this a try. :)
Have a nice day and happy hunting!

@cb109
Copy link
Author

cb109 commented Feb 17, 2022

Yes that sounds like an improvement over my just-dump-it-all approach :D It will also be more resilient to changes of the internally used dataset, aka URLs won't break as likely if used as bookmarks 👍

See you in the bayou 🤠

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants