Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cardcast replacement #241

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

devgianlu
Copy link
Contributor

@devgianlu devgianlu commented May 17, 2020

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:

  • Remove old CardCast code
  • Add ability to upload JSON to load deck
  • Add ability to download JSON from website to load deck
  • Watermark
  • Add custom decks list inside game options
  • Add the ability to remove decks from the list
  • Remove custom decks in chat code
  • Add hostname filter (to protect the server IP)
  • Cache downloaded decks
  • 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
Copy link
Contributor Author

devgianlu commented May 17, 2020

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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 devgianlu marked this pull request as ready for review May 23, 2020 10:00
…eplacement

# Conflicts:
#	src/main/java/net/socialgamer/cah/CahModule.java
#	src/main/java/net/socialgamer/cah/cardcast/CardcastModule.java
#	src/main/java/net/socialgamer/cah/data/Game.java
@@ -70,7 +69,7 @@
*/
private static final long VALID_SET_CACHE_LIFETIME = TimeUnit.MINUTES.toMillis(15);

private static final AtomicInteger cardIdCounter = new AtomicInteger(-(GameOptions.MAX_BLANK_CARD_LIMIT + 1));
private static final AtomicInteger cardIdCounter = new AtomicInteger(Integer.MIN_VALUE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this to count from the bottom up because the number of blank cards can be changed with the server running.

@ajanata ajanata mentioned this pull request Jun 5, 2020
@devgianlu
Copy link
Contributor Author

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

@devgianlu devgianlu mentioned this pull request Jul 5, 2020
@Tibladar
Copy link

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
Copy link
Contributor Author

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

@devgianlu
Copy link
Contributor Author

Should be good now.

@Tibladar
Copy link

Tibladar commented Jul 30, 2020

Should be good now.

Yep, working fine.
png

@Sopel97
Copy link

Sopel97 commented Jan 6, 2021

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
Copy link

KrishanPatel001 commented May 30, 2021

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
Copy link
Contributor Author

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
Copy link

KrishanPatel001 commented May 31, 2021

{

{
"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
Copy link
Contributor Author

@silverkey5 The watermark must be all uppercase.

@KrishanPatel001
Copy link

{
"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
Copy link
Contributor Author

It must also be 5 characters long.

@KrishanPatel001
Copy link

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

@adripo
Copy link

adripo commented Dec 16, 2021

Any update on this?

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.

5 participants