I opened a can of something.

Dev Log for Sep 2024, Week 38:
Right up front, I think I’ll be changing the format for these. I can probably structure this a little better to give a better view into the development stuff, instead of just covering what I got done on a day by day basis.

Dev Log:

Item Management – Starting out.

This has been interesting to tackle so far. My initial node structure didn’t really pan out, so I rebuilt things to fall in line with the rest of the UI work I’ve been doing. If I had to guess how it would turn out, I would say this:

  1. Players encounter items either as scenario rewards, or as area2D entities on the world map. In either case these are essentially containers for the data resource (which is how most of my data is being managed right now.)
  2. On interaction, the resource will get passed from it’s current holding object to a Control node to display info on it, and allow the player to claim it.
  3. Claiming it will pretty much queue_free() the current holding object, then pass the resource to the CharacterSheet control node where it can be interacted with.
    I have most of this in play, I just need to resolve a bug that’s causing that last handoff to the character sheet to shit the bed. It’s having a hard time grabbing the texture icon. EDIT: I fucking LOVE the Godot Documentation! I was doing some reading on how crazy (or not) getting save functionality was going to be, which rabbit-holed me into Resources, which helped me solve the problem. Full disclosure, half of this was my fault for referencing .GD instead of the .TSCN. Then the rest came down to getting the preload right and everything else was good. It’s still buggy, but I have a direction now.

Getting it Wired Up.

I got everything mostly in place, and learned a wild lesson about using signals in code. I wanted to have a signal call a function, and pass it the first argument of the original signal as a reference, I thought this would work:

func _populate_items():
    var item_group: Array = scenario.items

    for item in item_group:
        var new_item = item_button.instantiate()
        new_item.item_data = item
        reward_container.add_child(new_item)
        if new_item.has_signal("item_selected"):
            #NOTE Passing the signal also passes it's arguments to the callable.
            // Below is the culprit.
            new_item.connect("item_selected", claim_item.bind(new_item.item_data))

This was the error it gave me:

0:00:05:0436 item.gd:31 @ _on_panel_container_gui_input(): Error calling from signal ‘item_selected’ to callable: ‘Control(scenario_viewer.gd)::claim_item’: Method expected 1 arguments, but called with 2.

That made no immediate sense to me, since I thought I was only passing it the single typed reference it was looking for. This is what fixed it:

func _populate_items():
    var item_group: Array = scenario.items

    for item in item_group:
        var new_item = item_button.instantiate()
        new_item.item_data = item
        reward_container.add_child(new_item)
        if new_item.has_signal("item_selected"):
            #NOTE Passing the signal also passes it's arguments to the callable.
            // Notice something missing.
            new_item.connect("item_selected", claim_item.bind())

Apparently, when connecting a signal this way, It’s assumed the data carried in the signal will be used as the argument for the called method. Now I know. But with that out of the way I have the ground work for items laid in!

Updating the Character Sheet

I took some time out to update the character sheet and it’s data. I think this stems mostly from feeling squirrely today, but also because I’ll need to touch this stuff to integrate item usage and equipping too.
This is starting to bring into contrast the facts that I need to better structure this project, and need to learn more about structuring a project in general. I’ve run into a few places where I’ve had to put timers in the _ready() function to get things to load correctly, which I’m sure is a result of something I’m doing ass-backwards.

The Re-Factor Hell Mouth

It’s Thursday as I’m writing this, and I’m a little sideways at this point. I finished up a few odd and ends on the project, pretty much everything it made sense to do before beginning the re-factor. It kind of all flooded in at that point, that there were probably some serious re-writes coming to make everything jive with Items correctly.
So I spent some time in the afternoon getting my notes together and doing some napkin diagramming. Mentally, I’m in a weird spot where I know roughly what needs to get done, as well as roughly how to do it. This makes it all the wilder that I feel up against the wall for some reason. I’m sure this is temporary, but I might take the afternoon to do a mental reset (I’ve also got friends coming in from out of town this weekend, so it might just be an early start.).

Closing Thoughts:

I feel pretty good about the week overall, it feels like I got a decent amount of stuff done. I didn’t think I’d be running into such a large refactor, but seeing as I’m still learning, that can of worms was getting opened at some point no matter what.