PretendYoureXyzzy icon indicating copy to clipboard operation
PretendYoureXyzzy copied to clipboard

Cardcast replacement

Open devgianlu opened this issue 4 years ago • 17 comments

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:

  • [x] Remove old CardCast code
  • [x] Add ability to upload JSON to load deck
  • [x] Add ability to download JSON from website to load deck
  • [x] Watermark
  • [x] Add custom decks list inside game options
  • [x] Add the ability to remove decks from the list
  • [x] Remove custom decks in chat code
  • [x] Add hostname filter (to protect the server IP)
  • [x] Cache downloaded decks
  • [x] Show custom decks from game list
  • [ ] Update wiki and instructions

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 avatar May 17 '20 09:05 devgianlu

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

  • /addcustomdeck_json: Adds a deck from the JSON provided (must change to file upload)
  • /addcustomdeck_url: Adds a deck from an URL
  • /removecustomdeck: Remove a deck with the given ID
  • /listcustomdecks: List available decks

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:

  • The watermark, which could be simply given by the JSON
  • Caching

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 avatar May 17 '20 11:05 devgianlu

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 avatar May 21 '20 16:05 devgianlu

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 avatar May 22 '20 18:05 devgianlu

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

devgianlu avatar Jun 21 '20 12:06 devgianlu

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

Tibladar avatar Jul 26 '20 12:07 Tibladar

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

devgianlu avatar Jul 26 '20 13:07 devgianlu

Should be good now.

devgianlu avatar Jul 26 '20 13:07 devgianlu

Should be good now.

Yep, working fine. png

Tibladar avatar Jul 30 '20 08:07 Tibladar

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

Sopel97 avatar Jan 06 '21 20:01 Sopel97

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.

KrishanPatel001 avatar May 30 '21 18:05 KrishanPatel001

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?

devgianlu avatar May 31 '21 06:05 devgianlu

{

{ "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

KrishanPatel001 avatar May 31 '21 17:05 KrishanPatel001

@silverkey5 The watermark must be all uppercase.

devgianlu avatar May 31 '21 17:05 devgianlu

{ "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

KrishanPatel001 avatar May 31 '21 17:05 KrishanPatel001

It must also be 5 characters long.

devgianlu avatar May 31 '21 17:05 devgianlu

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

KrishanPatel001 avatar May 31 '21 17:05 KrishanPatel001

Any update on this?

adripo avatar Dec 16 '21 01:12 adripo