Refactors Galore

Refactors Galore

Its been a few months since my last update on the project. So here’s an update on the progress so far.

The Refactoring

Moves

Before this refactor I had the 1 move implemented in a way. That being the persona attack skill use ability. When attempting to implement the guard move for a party member I found that the old implementation was far too limiting. So I refactored it. The new setup uses an interface for the logic shared between each move and a class implementation of every move the user can have. I managed to refactor the move I had before in to this new setup and implement a guard move without any issues which was good. Since then I’ve started implementing other moves such as the support skills.

using CarterGames.Common.Events;

namespace Gameplay.Actions
{
    /// <summary>
    /// Implement to make a new move in the game for a party member or enemy to use.
    /// </summary>
    public interface IGameMove
    {
        /* ————————————————————————————————————————————————————————————————————————————
        |   Properties
        ———————————————————————————————————————————————————————————————————————————— */
        
        /// <summary>
        /// The type of action the move is.
        /// </summary>
        GameMoveType ActionType { get; }
        
        
        /// <summary>
        /// Raises when the move is completed.
        /// </summary>
        Evt MoveCompleted { get; set; }
        
        
        /// <summary>
        /// Any ctx for the move to use.
        /// </summary>
        object ActionCtxData { get; set; }
        
        /* ————————————————————————————————————————————————————————————————————————————
        |   Methods
        ———————————————————————————————————————————————————————————————————————————— */
        
        /// <summary>
        /// Performs the move when called.
        /// </summary>
        void PerformMove();
        
        
        /// <summary>
        /// Resets the move when called.
        /// </summary>
        void ResetMove();
    }
}

Slot Navigation

While its still not fully complete, I’ve also refactored the slot navigation system to be more flexible that it was. Beforehand it was a bit of a mess with the whole wildcard solution, honestly it was a bit over-engineered. With this refactor the system is much better, but while writing this post I noticed some bugs with the wild option, so there is still some work to do there.I was also able to use this system in the persona skill select display as well. Before I as using a different setup for that which felt a bit dumb.

Minor Bits

Some extra refactors, not full systems but some improvement include:

  • Target Manager > Sorted the resetting when selecting skills, as skills like support skills can target the party instead of enemies.
  • Turn Manager > Updated the turn manager to track complete turns and the ability to loop around to the start again.

Party Buffs

In Persona you can buff or debuff combatants in Critical chance, Attack/Defense/Agiligy & reflection walls to repel single attacks. I wrote a system to support this on combatants in the last month. The system took a bit of time to implement properly but I was able to get it working eventually. I also sorted the UI for the setup which appears over the combatant when they have any buff or debuff applied. These buffs are also set to only last a number of turns and will expire on the turn when there are no uses left.

And yea, there are some UI bugs and missing art on the character stats now…. Lots of little bits to fix 🙂

Project Cleanup

Behind the scenes I’ve also been doing a lot of cleaning up. There were a lot of prefabs and old art in the project that wasn’t being used anymore. I managed to clear up all the old prefabs and improve the structure so there is a prefab for the model as is for menu’s etc. While the other is for the actual persona model for the game scene when summoning the persona.

I also renamed all the assets to match a naming convention I use a work which is mostly for the art side but with some extra conventions for prefabs and scenes. The convention below if you’re interested:

That’s about all the big news I have for now. I’ll still be working away at this project when I get the time. But I am taking at-least 1 day off a week to just chill and do nothing game dev related. With an extra day off for the rest of the year more or less I’ll be taking that fully. I’ve been slowly getting through Person 4 Golden on those days so far, been good fun. Held off on Persona 3 Portable once Persona 3 Reload was annouced officially as that’ll be much more engaging to play when it comes out next year. Its looking awesome so far, really looking forward to playing it on release day, may even take a day off to play it xD

View Display & Fixes

View Display & Fixes

Another month has passed since the last update, and I’ve been mostly focusing on the UI displays and fixing a few bugs as well as some general organisation. I haven’t been able to dedicate much time to the project for the last few weeks, as I had the Save Manager to finish up for Carter Games by the end of April.

Preview

Below is a short video of the current progress made on the project as of writing:

View persona UI

The UI hasn’t changed much on the front-end, but behind the scenes a lot had gone on. I’ve spent the time to improve the UI Polygon setup that I’m using for the odd shapes in the UI. The new setup lets me drag points in the editor space and the graphic is then drawn using those points. I’ve also made it so this updates in edit mode so it’s easier to visualize. The upside being it’s easier to edit and less buggy. But I still need to do a little bit more to it. As it currently doesn’t scale with the bounds (width/height) of the graphic.

A screenshot of the unity editor with a element of the persona UI selected showing 4 points highlighted as gizmo's

With this new UI polygon setup I remade the UI for the skill strengths & weaknesses. Mainly to have the extra length for the text. I couldn’t quite match the text perfectly with Persona 5’s text as the font has a few layers to it. That and I couldn’t find a font close enough to match it, so I went with the readable option. This turned out okay and I refactored the display code to toggle the sections correctly when needed.

A screenshot of the view persona display with a skill highlighted.

The next new part was the navigation of the UI. In Persona 5 you can inspect each skill and move around the slots for each persona. This wasn’t the easiest system to code despite it being simple in theory. I ended up with a data structure that split the slots in the columns with an option for wildcard slots that could be accessed from specific slots. I reused the old selection UI from the skills select screen and refactored it to allow for 4-directional blue backgrounds. This was done so as in the game you would see this highlight in the direction you were navigating in.

With this I also implemented the inspect display which I had already laid out to show the skill in more detail. This display updates as you move around the skills and hides is no skill is currently being hovered over. Some of the more general fixes such as toggling user input listeners at the right times were also adjusted. As some of them were listening on start instead of when the screen was opened.

Another notable change is the model preview. While it is still early days, I was able to get the model to spawn in and rotate with user input. The model is stored in a new model system that replaces the old one I had from the 1st day of working on the project. The main upside of the new setup is that I can easily get & re-use models without spawning them all in on start.

The final main change is the ability to switch personas. Using the newly released Save manager 2.x I was able to make a save object for the held persona’s the player has. Currently this is the container class but down the line it will be the raw data for each persona. There is still a lot to do with this system as is, but the ability to switch between all held and select a different persona is now possible which is the key thing.

General organisation

The only other progress of note is a major clean-up of old code. While a lot of the code base is still scrappy and a bit messy, I have spent the time to remove scripts that I want to re-do or are for systems I’ve yet to actually focus on. Structurally the code is split into categories based on what it is about. So, data structures or scriptable objects are in a “Data” folder. While general systems, gameplay specific systems & UI all have their own folders. Inside these folders I have the code split by mechanic. Namespaces wise they all now use the base folder which does name more namespaces, but a more structured setup which I like, for now.

Closing thoughts

Given this has only been a small amount of progress, I’m still happy with it so far. I’m hoping in the coming months to be able to get into some of the gameplay. Implementing the enemies, moves & actual combat. So hopefully more exciting stuff to come! I’d expect the next update in about a months’ time.

Persona UI, Its A Lot Of Work

Persona UI, Its A Lot Of Work

So it’s been about a month and I felt it was about time I updated you’ll on the progress so far. I’m still working on the UI setups at the moment as they are required for the rest of the project to really function. Have been hoping between this project and another on and off all month. So I’ve only actually worked on this for about 10 or so days this month but the progress is worth showing.

Menu Management

With the amount of UI there is to do I needed to make a menu system that would let me switch between different menus with ease. Before I had a manager class that did this on context, but that was getting really messy really quickly. Instead of continuing with the messy setup I decided to refactoring it into something more useable.

The new setup is entirely static and is called in the displays logic for the active menu. The active menu then controls what buttons open what displays and runs the logic to open the new one and close the current if needed. Using an interface to keep it simple. So far this solution is proving to work quite well. Though I imagine I will, have to come back to it at some point and make further adjustments. An example of the new menu controller API in use to close one display & open another:

// API - uses type to open/close menus, with each being registered on the scene opening. 
// MenuController.OpenMenuCloseThis<TOpenMenuType, TCloseMenuType>();
// Below would switch from the skill select UI on the active persona to the detailed persona view display. 
MenuController.OpenMenuCloseThis<ViewPersonaDisplayController, SelectPersonaSkillDisplay>();

Persona Inspect

This is by far the most complex display in the entire project. But so far it’s not going too badly. I’ve managed to get then reveal mostly working and sorted a setup to show the active persona’s data. But there is still a long way to go. One of the challenges of this UI is the fact that it changes each time it’s opened or modified. With boxes randomly changing sizes etc. I have a feeling I’m going to need to work more on the UI polygon script to make it more reliable for all the use cases that are gonna crop up in the future.

P5R

My Version So Far

Some other bits include a popup description display that appears when inspecting the persona skills. I have setup a mockup for this display on the UI which works, but it needs to actually populate with data and appear still which it currently doesn’t. The other main progress is the stat level bars, these are a tad annoying as the actual “fill” is not set the actual value due to the background needing to take up more space than the fill. Currently I have the background taking the actual space while the fill uses a reduced size. But I still want to see if I can get it to update without needing such a workaround. There still a lot to-do on this display but I’m hoping to get it functionally working by the next update.

Data

In my last post I went over some of the data stuff I was working on with Google sheets, this is still an ongoing task with instant kill, healing and some passive skills still to work out and implementation for. Its tricky as a lot of these skills are very specific and working out a generic structure to store the data is proving tricky. But I am hoping to have the data done by the next update or two as it will be needed before I get fully into the gameplay and move implementation. I did fix a few issues here where data wasn’t updating object in the project, but I did some refactoring here and there to make the implementation on the dev side a bit easier. Most notable was the battle stats, so “Str, Ma, En, Ag, Lu”. The main change was to change the data from a struct to a class and to store all the data in a custom SerializableDictionary instead of individual values for ease of access. With getter/setter methods to access specific values by stat type. The code now looking like this:

/// <summary>
/// A container class to hold a persona's battle stats.
/// </summary>
[Serializable]
public class BattleStats
{
    /* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
    |   Fields
    ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */
    
    [SerializeField] private SerializableDictionary<PersonaBattleStat, int> stats;
    
    /* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
    |   Constructors
    ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

    /// <summary>
    /// Makes a blank battle stats class.
    /// </summary>
    public BattleStats() { }


    /// <summary>
    /// Makes a new battle stats data with the dictionary entered.
    /// </summary>
    /// <param name="data">The data to set.</param>
    public BattleStats(SerializableDictionary<PersonaBattleStat, int> data)
    {
        stats = data;
    }
        
    /* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
    |   Methods
    ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

    /// <summary>
    /// Gets the stat of the type entered.
    /// </summary>
    /// <param name="statType">The stat to get.</param>
    /// <returns>The stat value.</returns>
    public int GetStat(PersonaBattleStat statType)
    {
        if (stats.ContainsKey(statType))
        {
            return stats[statType];
        }
        
        return -1;
    }


    /// <summary>
    /// Sets the stat to the entered value.
    /// </summary>
    /// <param name="statType">The stat to edit.</param>
    /// <param name="value">The value to set to.</param>
    public void SetStat(PersonaBattleStat statType, int value)
    {
        if (!stats.ContainsKey(statType)) return;
        stats[statType] = value;
    }
}

Misc

In the last post I also covered affinities and their display. I mentioned i wasn’t going to do the two versions. Well I’ve changed my mind on that and now plan to implement the extended boxes in the future. The display just looks really off without the background behind the text. So expect an update on that soon. Otherwise progress is good and I’m pretty happy with how the project is going so far. Even played a little P5R to get some reference material and had to stop myself playing xD

That’s about it for this update, see you all in the next one.

So Much Data

So Much Data

Data Handling

After the first day I was spending time working on the data structure for all the data needed for persona’s which is a lot. The skills stuff I did on day 1 is great, but when thinking about it further I knew I’d need a way to generate a lot of skills and items without needing to do it all manually. As that would just take far too long and I would hate it all by the time I had created each skill by hand. This meant I needed to looking to ways of automating the data creation with some tool. For this I looked to see if there was any way to make a google sheet readable in Unity. Thankfully there was a nice short tutorial on downloading data to a csv format in Unity. I managed to make a system based on that, that would download a google sheet tab to a .csv file that I could then read and convert into the sciprtable objects as needed.

The code is nothing special here and is rather rigid as I made it purely to make scriptable objects and not for general game data use. Though down the line I may looking to make a system like that. But the good thing is that it works and makes handling skills & later the custom personas considerably easier.


Affinites Display UI

Other than that I did a bit more UI work and setup a display for the persona skill affinites. These being the skills they are weak or strong to etc. The display in persona 5 is fairly dynamic with two states for this, one for no text but unkown affinities and another for when there is an affinity. But, due to a lack of good screenshots to mock it up with and the hassle of mathcing it for each icon I’ve decided that for my version to just use the one version and just update the text.

The good news is the unknown state that I’m matching from persona 5 look spretty accurate and cool. See the left for how it looks currently. Note that there is a white background behind it in the final UI setup. I haven’t worked on any of the logic for hooking this up yet, but the data it will use will make it easy to just update the affinity text if it is revealed.


Organisation & Cleanup

The final progress for the day was a bit more clean up with some commenting & script organisation. I improved the polygon ui mover script to auto start/stop and to only run when active and started a better structure where mechanics are grouped together instead of all the ui in one parent folder and all of the data in another as it makes it harder to find some bits of the codebase as it grows in size.


Whats Next?

Mostly more data xD, yea I’ve yet to get the healing skills in as of writing as well as about half of the passive ones. This is due to the varying data that I’ll need to store. There is a chance that I may have to hard code some skills in with no data just due to how specific they are, but I’ll keep trying to make a good structure before going down that way. I also plan to get some early setup for the turn management for a 1 v 1 to start with and then a x v 1 as I plan to have a full party of 4 for the player to use, matching the source game. It’ll probably be a few weeks before the next update as I do have to work on another project at the same time as this and that one has a more rigid deadline to hit.


Project Start, Persona Summoning & UI Tests

Project Start, Persona Summoning & UI Tests

A personal project where I replicate the Persona 5 Royal Turn-Based Combat system as best I can for fun.

I was able to get a full day more of less to kick the project off with a bang. For the majority of the day I was focused on implementing some of the bits I wasn’t sure would work to prove the concept to myself before committing to it fully. I’m glad to say its looking good so we’re all go. To the left is a little video of the setup I made today. However I will be reworking all of this as I rough coded this together and it is a mess.

Whats setup:

  • Basic player & animations
  • Players stats + UI
  • Player persona
  • Persona skill select UI
  • Target select UI

I spent the tail end of the day doing some clean up of the code in preperation for the larger project. Today this was the persona skills. I knew each skill would be more of less the same in structure so I made a base class with the meta data and then specific inheritors for each type like attack & support etc. In doing this I made a custom inspector setup to make it easier to make new skills. A preview of this can be seen to the side.

The custom editor logic handles things such as the icon & name of each skill as well as elements such as the cost of the skill, as some skills use a percentage of the players health while others use a pre-defined amount. For the icons I’m just using some placeholder art I got from FlatIcon for now but I will likely change these down the line. Below are the icons I currently have for each ability:

I’ve already setup a system where you can access each of these icons in code in a static class by the type they represent. Following a similar setup for other data bits down the line should make working with such a large data set more steamlined, but we’ll see how that goes when we get to it.