Storing objects in lua
Posted: Thu Jan 23, 2020 8:28 pm
I've got a minigame in my game that has an initial state, and as you play that state needs to be modified and saved. I was contemplating trying to use the lua state so that my minigame state gets saved with all the rest of the state, but I wasn't sure the best approach.
Here's what my objects look like:
As you play, the game will remove patients and update their status as they are healed or made worse.
My question is should I be side-stepping the save system and just serialize the data to a text file, or is there some way to write this object to a lua table or something.
ALSO if there is some way to do that, what's the best place to do it? Start of a newgame?
Here's what my objects look like:
Code: Select all
/// <summary>
/// Represents the state of the minigame.
/// </summary>
public class MinigameState
{
public bool complete { get; set; }
public PatientDifficulty currentDifficulty { get; set; }
public List<Patient> easy { get; set; }
public List<Patient> medium { get; set; }
public List<Patient> hard { get; set; }
}
/// <summary>
/// Represents a patient with an ailment.
/// </summary>
public class Patient
{
public PatientStatus status { get; set; }
public PatientWalkerAnimator walkerAnimator { get; set; }
public PatientPortraitAnimator portraitAnimator { get; set; }
public string ailmentTextId { get; set; } // unique id
public List<CureIngredientInformation> cureIngredientList { get; set; }
}
/// <summary>
/// CureIngredientInformation contains information about a cure's ingredient and it's value.
/// </summary>
public class CureIngredientInformation
{
public string name { get; set; }
public float value { get; set; }
public bool isBonus { get; set; }
}
/// <summary>
/// Various statuses a patient can have. If they are healed, the are removed from the list during the scoring phase.
/// </summary>
public enum PatientStatus
{
Sick,
Angry,
Healthy,
VeryHealthy,
}
/// <summary>
/// Enum representing difficulty of the patient.
/// </summary>
public enum PatientDifficulty
{
Easy,
Medium,
Hard,
}
My question is should I be side-stepping the save system and just serialize the data to a text file, or is there some way to write this object to a lua table or something.
ALSO if there is some way to do that, what's the best place to do it? Start of a newgame?