invent-framework / invent

Express yourself with code.
https://invent-framework.github.io/
Apache License 2.0
109 stars 12 forks source link

Changing default file format to YAML instead of JSON #9

Closed mlongval closed 1 year ago

mlongval commented 4 years ago

Hello,

Your project is interesting. I would suggest that you change the default file format for the adventure text to YAML. Is is a LOT easier for a human to parse, and it is extremly easy to convert to JSON.

Here is your original adventure in YAML format.

---

# Adafruit's Create Your Own Adventure
# Modify this file to create a new adventure 

# This is a YAML port of the JSON data file. With upgrades. 
# (YAML allows lots of comments for humans) 

# Start card 
- background: page01.bmp
  buttons:              # yaml allows inline comments 
  - label: OK I'm in 
    target: inn
    # the following text is on 2 lines without the need for quotes. 
  text: Welcome adventurer. Your adventure begins, as many do, in Ye Olde Inn.
        We wish you well in your adventure. Find the treasure and try not to die.
  text_color: '0x000001'
  title: start

# The inn 
- background: page01.bmp
  buttons:
  - label: Stay
    target: inn
  - label: Go!
    target: cave entrance
  sound: ./pub.wav
  sound_repeat: 'True'
  text: This is a peaceful, happy inn with plentiful drink, tasty food, and friendly
    staff. We accept VISA or MasterCard. 
  text_color: '0x000001'
  title: inn

# The entrance to the cave  
- background: page01.bmp
  buttons:
  - label: Enter
    target: entry
  - label: Run
    target: inn
  sound: ./cave.wav
  sound_repeat: 'True'
  text: There is a dark cave in the hillside before you. You are obviously going
      to enter here. 
  text_color: '0x000001'
  title: cave entrance

# Enter the cave 1
- background: page01.bmp
  buttons:
  - label: Next
    target: side opening
  sound: cave.wav
  sound_repeat: 'True'
  text: You are in a dark, narrow tunnel. It smells musty and dank. 
  text_color: '0x000001'
  title: entry

# side opening
- background: page01.bmp
  buttons:
  - label: Continue
    target: skeleton room
  - label: Side T.
    target: treasure room
  sound: cave.wav
  sound_repeat: 'True'
  text: You are in a small room, one tunnel leads ahead and another to the side. Do
      you continue on or explore the side tunnel? (hint ---> side tunnel) 
  text_color: '0x000001'
  title: side opening

# Treasure room
- background: page01.bmp
  buttons:
  - label: Next
    target: maze 1
  sound: cave.wav
  sound_repeat: 'True'
  text: There is a pile of treasure here. Congratulations!
  text_color: '0x000001'
  title: treasure room

# Skeleton room 
- background: page01.bmp
  buttons:
  - label: Next
    target: maze 2
  sound: cave.wav
  sound_repeat: 'True'
  text: There is a skeleton on the floor. From the items around it, it seems to be
    that of an unfortunate adventurer. (or it's you caught in a time loop...) 
  text_color: '0x000001'
  title: skeleton room

# Maze room 
- background: page01.bmp
  buttons:
  - label: Left
    target: maze 3
  - label: Right
    target: maze 2
  sound: cave.wav
  sound_repeat: 'True'
  text: There are passages to the left and right.
  text_color: '0x000001'
  title: maze 1

# Maze room 2
- background: page01.bmp
  buttons:
  - label: Left
    target: maze 1
  - label: Right
    target: maze 4
  sound: cave.wav
  sound_repeat: 'True'
  text: There are passages to the left and right.
  text_color: '0x000001'
  title: maze 2

# Maze room 3 
- background: page01.bmp
  buttons:
  - label: Left
    target: maze 5
  - label: Right
    target: maze 2
  sound: cave.wav
  sound_repeat: 'True'
  text: There are passages to the left and right.
  text_color: '0x000001'
  title: maze 3

# maze room 4
- background: page01.bmp
  buttons:
  - label: Left
    target: maze 1
  - label: Right
    target: maze 6
  sound: cave.wav
  sound_repeat: 'True'
  text: There are passages to the left and right.
  text_color: '0x000001'
  title: maze 4

# maze room 5 
- background: page01.bmp
  buttons:
  - label: Left
    target: maze 4
  - label: Right
    target: creaking
  sound: cave.wav
  sound_repeat: 'True'
  text: There are passages to the left and right.
  text_color: '0x000001'
  title: maze 5

# maze 6
- background: page01.bmp
  buttons:
  - label: Left
    target: creaking
  - label: Right
    target: maze 3
  sound: cave.wav
  sound_repeat: 'True'
  text: There are passages to the left and right.
  text_color: '0x000001'
  title: maze 6

# creaking 
- background: page01.bmp
  buttons:
  - label: Cont.
    target: bridge room 1
  - label: Go back
    target: inn
  sound: creak.wav
  sound_repeat: 'True'
  text: You hear an ominuous creaking from around the corner
  text_color: '0x000001'
  title: creaking

# Bridge room 
- background: page01.bmp
  buttons:
  - label: Cont.
    target: bridge room 2
  sound: creak.wav
  sound_repeat: 'True'
  text: There is a creaking, rickity wooded bridge leading across a gaping chasm.
  text_color: '0x000001'
  title: bridge room 1

# Bridge room 2
- background: page01.bmp
  buttons:
  - label: Treasure!
    target: die
  - label: Leave
    target: inn
  sound: creak.wav
  sound_repeat: 'True'
  text: At the other end is a large treasure chest. Good luck getting that out
      of here. There is also a short tunnel with daylight at the end.
  text_color: '0x000001'
  title: bridge room 2
- background: page01.bmp
  buttons:
  - label: Next
    target: inn
  sound: scream.wav
  text: The bridge gives way and you fall to a painful death.
      ... you knew it was comin' Bye!
  text_color: '0x000001'
  title: die

Here are example conversion scripts:

#! python3
# j2y.py
# invoke as:  j2y.py < infile.json > oufile.yaml

import sys
import json
import ruamel.yaml as yaml

json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)

Here is the reverse:

#! python3
# invoke as: y2j.py < infile.yaml > outfile.json
import sys
import json
import ruamel.yaml as yaml

yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)

What do you think?

ntoll commented 4 years ago

Hi @mlongval,

This sounds like a great idea..! You're right about YAML being "kinder" on human eyes. I think it would be best if PyperCard supported both formats (and so loading the data could just read the file-extension to work out which is being used). Folks then get a choice. Sound like a plan..?

N.

ntoll commented 1 year ago

Closing this since we're re-writing PyperCard on top of PyScript and (as yet), no specification schema has yet been decided (but it's likely to be able to us various serialization formats like json or yaml). :+1: