Animated-Java / animated-java

A Blockbench plugin that makes complex animation a breeze in Minecraft: Java Edition.
Other
159 stars 26 forks source link

[FR] Refactor Keyframe Data Structure for Simplified Parsing and Consistency #242

Closed Dearliet closed 2 months ago

Dearliet commented 2 months ago

Current Format:

[
  {
    "channel": "rotation",
    "data_points": [
      {
        "x": "0",
        "y": "0",
        "z": "0"
      },
      {
        "x": "0",
        "y": "2",
        "z": "0"
      }
    ]
  },
  {
    "channel": "position",
    "data_points": [
      {
        "x": "0",
        "y": "12",
        "z": "3"
      }
    ]
  },
  {
    "channel": "command",
    "data_points": [
      {
        "commands": "/say hi",
        "execute_condition": "",
        "repeat": false,
        "repeat_frequency": 1
      }
    ]
  },
  {
    "channel": "variant",
    "data_points": [
      {
        "variant": "e9fff953-e4bc-3879-4376-cf29c402492d",
        "execute_condition": ""
      }
    ]
  }
]

Proposed Format:

[
  {
    "channel": "rotation",
    "data_point": {
      "x": ["0", "0"],
      "y": ["0", "2"],
      "z": ["0", "0"]
    }
  },
  {
    "channel": "position",
    "data_point": {
      "x": ["0", "0"],
      "y": ["12", "12"],
      "z": ["3", "3"]
    }
  },
  {
    "channel": "command",
    "data_point": {
      "commands": "/say hi",
      "execute_condition": "",
      "repeat": false,
      "repeat_frequency": 1
    }
  },
  {
    "channel": "variant",
    "data_point": {
      "variant": "e9fff953-e4bc-3879-4376-cf29c402492d",
      "execute_condition": ""
    }
  }
]

Further Simplified Alternative:

[
  {
    "channel": "rotation",
    "x": ["0", "0"],
    "y": ["0", "2"],
    "z": ["0", "0"]
  },
  {
    "channel": "position",
    "x": ["0", "0"],
    "y": ["12", "12"],
    "z": ["3", "3"]
  },
  {
    "channel": "command",
    "commands": "/say hi",
    "execute_condition": "",
    "repeat": false,
    "repeat_frequency": 1
  },
  {
    "channel": "variant",
    "variant": "e9fff953-e4bc-3879-4376-cf29c402492d",
    "execute_condition": ""
  }
]

I personally recommend adopting the further simplified format. It is the easiest to parse and offers the clearest and most straightforward approach.

SnaveSutit commented 2 months ago

The pre post keyframes contain multiple data points.

Dearliet commented 2 months ago

That's what the arrays are for.

Dearliet commented 2 months ago

It might even be more straightforward to change it like this:

{
  "channel": "rotation",
  "x": ["0", "0"],
  "y": ["0", "2"],
  "z": ["0", "0"]
}
{
  "channel": "rotation",
  "x": {"pre": "0", "post": "0"},
  "y": {"pre": "0", "post": "2"},
  "z": {"pre": "0", "post": "0"}
}
SnaveSutit commented 2 months ago

I'd prefer converting them to more direct arrays. There's no keyframe types that have more than 2 data points anyway.

{
  "channel": "rotation",
  "value": ["0", "0", "0"],
  "post": ["0", "0", "0"]
}
Dearliet commented 2 months ago

Sounds great 👍