ajanata / PretendYoureXyzzy

A web clone of the card game Cards Against Humanity.
https://pretendyoure.xyz/zy
BSD 2-Clause "Simplified" License
1.24k stars 396 forks source link

Cardcast replacement #241

Open devgianlu opened 4 years ago

devgianlu commented 4 years ago

This PR aims to replace the functionality provided by the dead CardCast website. See #240

Play with custom decks at https://pyx.gianlu.xyz/ZY/.

TODO:

JSON template:

{
  "name": "name of the deck",
  "description": "I actually don't see this in my example files, so... remove references to it?",
  "watermark": "AB123",
  "calls": [
    {
      "text": [
        "",
        " and ",
        " are the next hit comedy duo."
      ]
    },
    {
      "text": [
        "What's that smell?",
        ""
      ]
    }
  ],
  "responses": [
    {
      "text": [
        "The biggest, blackest dick."
      ]
    },
    {
      "text": [
        "Two midgets shitting in a box."
      ]
    }
  ]
}
devgianlu commented 4 years ago

Four commands are now available (could be changed to buttons):

I've intentionally kept the Cardcast JSON format to allow for some kind of retro-compatibility if someone had downloaded his decks.

The main two problems are:

We could easy cache the URLs, but not the JSON. I was thinking to use some digest like MD5 to check if we already have the exact same content, or maybe that's not even that useful. My app would probably benefit from this as I'd allow the user to create custom decks without uploading them.

devgianlu commented 4 years ago

I've removed the two add commands and added some buttons in the game options. I am going to make a better list of the custom sets so that commands are not needed anymore (this way we don't have to show the user the deck id which is just a number).

The hash method is not working reliably for caching because of newlines and formatting stuff so we need an alternative to identify if two decks are identical. We would need to parse the content and then compute the hash after it has been "normalized" (something like https://github.com/fraunhoferfokus/JSum) which is a bit more expensive in terms of computing, but I don't think it'll be an issue.

I was also thinking that we probably don't need the server to fetch URLs, we could let the user send the JSON (fetching on the client). The only downside is that of the hash mentioned above.

@ajanata Let me know what you think.

devgianlu commented 4 years ago

Daily update...

I've fixed the caching issue with bencode. I've added some UI elements to list the custom decks and allow to remove them with a button press.

I'd say this is almost complete.

devgianlu commented 4 years ago

@ajanata Have you been able to take a look at this?

Tibladar commented 4 years ago

Don't know how it looks for you, but here the 'Custom Card Sets' prevents the use of the buttons regardless of browser or monitor resolution. Tested on pyx.gianlu.xyz. broken

devgianlu commented 4 years ago

@Tibladar It's fine on 1600x900 and 1920x1080, but I suppose I can address in some way.

devgianlu commented 4 years ago

Should be good now.

Tibladar commented 4 years ago

Should be good now.

Yep, working fine. png

Sopel97 commented 3 years ago

a converter from xyzzy metrics csv format to this json format:

import os
import json
import html

rootdir = "csv"

def process_file(path, filename):
    filename_parts = filename.split('.')
    name = filename_parts[0]
    json_filename = '.'.join(filename_parts[:-1]) + '.json'
    doc = dict()
    doc['name'] = name
    doc['description'] = 'no description'
    doc['watermark'] = name
    with open(path, 'r', encoding='utf-8') as infile:
        with open('json/' + json_filename, 'w', encoding='utf-8') as outfile:
            calls = []
            responses = []
            for line in infile:
                line = html.unescape(line)
                parts = line.split(',')
                wb = parts[0]
                text = ','.join(parts[1:-2])
                if wb == 'white':
                    responses.append(text)
                else:
                    calls.append(text)

            doc['calls'] = []
            doc['responses'] = []
            for call in calls:
                parts = call.split('____')
                if len(parts) > 1:
                    doc['calls'].append({ 'text' : parts })
            for response in responses:
                doc['responses'].append({ 'text' : [response] })

            outfile.write(json.dumps(doc, sort_keys=True, indent=4))

for subdir, dirs, files in os.walk(rootdir):
    for file in files:
        filepath = subdir + os.sep + file

        if filepath.endswith(".csv"):
            process_file(filepath, file)

script in .convert.py, csvs in csv/*.csv, produces json files in json/*.json

KrishanPatel001 commented 3 years ago

Getting this error whenever I'm trying to upload a JSON deck. Error: Cannot find custom deck with the given ID or URL or invalid JSON was provided.

devgianlu commented 3 years ago

Getting this error whenever I'm trying to upload a JSON deck. Error: Cannot find custom deck with the given ID or URL or invalid JSON was provided.

@silverkey5 Can you post the URL or JSON you tried to use?

KrishanPatel001 commented 3 years ago

{

{ "calls": [ { "text": [ "Ashido's secret passion is ", "." ] }, { "text": [ "Dear Midoriya, I'm having issues with ", " and would like some advice." ] }, { "text": [ "For Mr. Compress's next trick, he will pull ", " out of ", "!" ] }, { "text": [ "In his farewell speech, All Might warned young heroes about the dangers of ", "." ] }, { "text": [ "Bakugou masturbates to ", "." ] }, { "text": [ "Dabi ate ", " for dinner." ] } ], "description": "no description", "name": "test", "responses": [], "watermark": "test" } }<

I've also tried uploading this to a URL, but when I used the /addurl command it said it was an invalid command https://api.jsonbin.io/b/60b3d22692af611956f6a26c/1

devgianlu commented 3 years ago

@silverkey5 The watermark must be all uppercase.

KrishanPatel001 commented 3 years ago

{ "name": "testDeck", "description": "bnha stuff", "watermark": "BNHA", "calls": [ { "text": [ "Ashido's secret passion is ", "." ] }, { "text": [ "Dear Midoriya, I'm having issues with ", " and would like some advice." ] }, { "text": [ "For Mr. Compress's next trick, he will pull ", " out of ", "!" ] }, { "text": [ "In his farewell speech, All Might warned young heroes about the dangers of ", "." ] }, { "text": [ "Bakugou masturbates to ", "." ] }, { "text": [ "Dabi ate ", " for dinner." ] } ]

}

It still returns the same error message

devgianlu commented 3 years ago

It must also be 5 characters long.

KrishanPatel001 commented 3 years ago

...im just dumb lol thank you so much!

adripo commented 2 years ago

Any update on this?