Refactoring: Cutscene Player


Setting the Stage

Today I'm going to do things a little bit differently. I'm going to stream my development session over on my YouTube channel. But, before I start, I wanted to play a little game. I'm going to use this dev log to describe what it is I plan to accomplish and how I expect to do it. Then, I will come back later (hopefully) to update this post with the outcome. Not sure if this will be as cool as I want it to be, but it's something a little different. Now, down to business! 

Today I want to completely refactor my cutscene player. When I originally built it, I had no idea what I was doing. This was months ago, back when I was still very new to Godot and vibe coding. Gemini helped build out a functional system, but not everything works the way I want. The real issue though is the data. Lemme explain how the cutscene player currently works.

When a cutscene is called, the UI manager loads up my cutscene player which is told which cutscene to play. Each cutscene (there's only one currently) is a self-contained scene, consisting of a few nodes for the cutscene itself with a script that makes them work. Inside that script is a hard-coded variable full of the data needed to run the cutscene. There's some decent functionality in there, I've got animatable nodes, background music controls, text overlays, etc. 

But it doesn't all work the way it was intended, and it's all Gemini's fault. Not really, I didn't understand enough about how it all worked together to realize at first that it wasn't going to do what I wanted. There's a whole bit of the code that doesn't even work right, so it's not even being used. The real issue though, is the data. I don't want to have to hard code the data into the each cutscene scene individually. So what I'm going to do today is fix all of this to the best of my ability. 

First, I'm going to take my cutscene data and create a new resource definition similar to the ones I've already got for my items/quests/effects/etc. With that new resource definition, I will then transpose my existing cutscene data into a JSON file that matches the appropriate format for my definition. Once that's ready, I'll add a whole new function into my data manager to load my cutscene(s) for later use. 

This should all be pretty simple and straightforward. I anticipate that there will be some issues initially with the data manager loading up the cutscene data. For some reason, there's always an issue with Gemini's code when it comes to matching data types in my data manager. Luckily, in the past, it's always been a pretty easy fix.

Then things get harder. After the data manager successfully loads my cutscene, I have to actually put that data to use. The first step of that is going to be rolling the cutscene template into cutscene player. This will involve making sure I have all the right nodes in place, export variables in the script to hold them, and then re-coding all of it so it works together. Seems simple when I type it out,  but I feel like it's gonna be a decent lift.

During all of that, I've also gotta work out my issues with the cutscene player and make some modifications to suit my desires. Specifically, the cutscene player currently has functionality to animate a large area, but it doesn't work because Gemini got it wrong and I didn't realize until it was too late. Plus, I'd like to change the specific way cutscenes are played. Right now, all the text is just displayed, but I'd like it to appear slowly over time, letter by letter or word by word. I also want to add a time delay, so the player is forced to wait between each frame of the cutscene. Don't worry, there's still going to be a skip button. Although, now that I think about it, I should probably allow the use of the escape key to skip too.

How does that sound? You gonna join me for my stream? Any advice? Think I can handle it? I sure hope so! I'll be back later with a wrap-up, wish me luck.

Recap and Reflection

Wow, I really felt like creating the resource definition based on existing data was going to be the easy part. I was so wrong! I don't know how, but Gemini decided to go off the rails and built out a resource definition with all kinds of excessive keys that don't exist, while leaving out or renaming others. It wasn't until I had begun building the JSON file itself that I realized how bad everything was.

And then, trying to have Gemini take the existing data, that was used to create the definition, and build a JSON file was a disaster! It just made everything up. I have no idea how it managed to screw up so badly, but I had to chastise it. It took multiple tries to get something that actually contained the data I wanted. Even then it wasn't in the right format. It became really frustrating because this was supposed to be the easy part!

Once I had the resource definition and JSON file to load, I had to dive into my data manager. I did the modifications myself at first. Just some placeholders, variables, but not the actual, real, data loading. Of course I had to test it before I actually jumped into loading the data itself. And, of course it was broken, thanks to Gemini not getting the JSON format correct. I really don't understand why it's having so much troubles. I've done something like this a number of times with Quests, and Dialogues.

But, eventually that got figured out and it was finally time to load the data. And again, I kept running into issues. I knew, up front, that the data processing was going to take a couple of tries. Every time I've done this before, it always ends up with some data type mismatching that breaks the game. It's usually really easy to fix! I just tell Gemini what the error is (by giving it a screen clipping) and it fixes it. But this time it couldn't. Somehow, it was getting completely incorrect information from the image of the error. 

I had to just drop that chat instance and start over fresh, building a new data loader. Instead, I just did it myself. I had more than enough previously written code to use as a reference. I cannibalized my NPC and Dialogue loading functions to build out cutscene loading. It went off without a hitch, surprisingly. 

But, because of how much troubles I've been with Gemini today, I decided to stop there. I know I planned on accomplishing more, but I've grown frustrated with the major errors Gemini is causing. The portion not accomplished is actually putting this new cutscene definition to use inside my refactored cutscene player. Put it that way and I feel like I only got about half of what I wanted done. That's okay though, still a major accomplishment and I'm very proud of the progress.

Leave a comment

Log in with itch.io to leave a comment.