Arkkodan / DreamVsDream

GNU General Public License v3.0
4 stars 0 forks source link

Idea: Use a common serialization format to store configuration files #1

Closed Arkkodan closed 3 years ago

Arkkodan commented 3 years ago

.ubu "script" files are used for a variety of purposes such as loading resources, setting up scenes and stages, and creating characters. However, I would call these "configuration" files rather than script files because they are meant to be read by the programs. Currently, the Parser class, as used in Compiler, DvD, and Sprtool, is exclusively used to read .ubu files in their native format, which I believe was made for Dream vs. Dream.

I suggest migrating these .ubu files into a different serialization format (e.g. XML, JSON, YAML, etc.) since they can contain everything .ubu files contain, are widely supported (third-party libraries and schemas), and can extend the capabilities of these configuration files.

Consider the following .ubu file for the stage, yn_balcony:

BGM intro, loop
THUMBNAIL thumbnail

IMAGE_B 0.0, 0
IMAGE_B tv_blank, 0.6, 1
IMAGE_B tv_test, 0.6, 2
IMAGE_B tv_eyeball, 0.6, 3
IMAGE_B tv_kalimba1, 0.6, 4
IMAGE_B tv_kalimba2, 0.6, 5
IMAGE_B bg, 1

IMAGE_A fg, 1
IMAGE_A fg2, 1

//Height from bottom of stage that chars will stand on
HEIGHT 40
//Width from center of stage to one side
WIDTH 320
//Absolute width/height of stage
WIDTH_ABS 640
HEIGHT_ABS 960

Here is a mockup for a .json file containing the same information (with some expressive liberty):

{
    "music": {
        "intro": "intro",
        "loop": "loop"
    },
    "thumbnail": "thumbnail",
    "imageBehind": [
        {
            "file": "0.0",
            "parallax": 0
        },
        {
            "file": "tv_blank",
            "parallax": 0.6,
            "round": 1
        },
        {
            "file": "tv_test",
            "parallax": 0.6,
            "round": 2
        },
        {
            "file": "tv_eyeball",
            "parallax": 0.6,
            "round": 3
        },
        {
            "file": "tv_kalimba1",
            "parallax": 0.6,
            "round": 4
        },
        {
            "file": "tv_kalimba2",
            "parallax": 0.6,
            "round": 5
        },
        {
            "file": "bg",
            "parallax": 1
        }
    ],
    "imageAhead": [
        {
            "file": "fg",
            "parallax": 1
        },
        {
            "file": "fg2",
            "parallax": 1
        }
    ],
    "entity": {
        "ground": 40,
        "bounds": 320
    },
    "camera": {
        "width": 640,
        "height": 960
    }
}

In particular, I am thinking about using JSON while eventually deprecating the .ubu files.

Arkkodan commented 3 years ago

I will go ahead with trying to replace .ubu with .json as I believe there are significant benefits:

Adding a JSON library does create another dependency that has to be supported, both by CMake, generating more targets, and by programmers, who have to learn how to use the library. I plan on deprecating support for .ubu files until some time later when I'll drop support.

If successful, I'll write a program that converts the files. A future plan is a resource manager for DvD, allowing for loading/unloading more or less resources,

Arkkodan commented 3 years ago

I made UBU2JSON, a program that converts ubu files into JSON format. Progress can be seen in the feature/json branch, https://github.com/Arkkodan/DreamVsDream/tree/a9d442cc4051e64319dafcbcfa94d33bf39991c2. I will not merge it with the develop branch until the feature gets to the point where it becomes useful:

Until then, this issue should not be closed.

Since I plan on deprecating ubu files, I will either concurrently support both ubu and JSON or allow a fallback. Eventually, support for ubu files may be completely dropped.

Arkkodan commented 3 years ago

For the purposes of DvD, I have replaced parsing ubu files with the new JSON files as well as making some JSON schemas. Although not complete, I think that at this current state, it improves upon the old system.

I have merged this onto the develop branch and will close this issue. However, note that the JSON migration and resource manager are still incomplete.