Simple Calendar
I've been studying the engine for this past few days and I've started to work on a simple calendar extension to test things out. The Inventory extension has proven to be an invaluable tool to use as base for this.
I realize that using a simple CustomUI and a couple of variables would be an easier solution (like explained here) but this is mostly a learning exercise, with the potential to evolve into a more fleshed out time based progression system.
Currently, it is extremely bare bones but somewhat functional with some bugs that i'm still trying to understand.
The base ideia is to use a string variable to store a date in the format "yyyy-MM-dd HH:mm:ss", this string will then be parsed on runtime into a DateTime object for manipulation. I feel that this makes it easier to work with dates and time at the same time.
Right now, the only interaction implemented is a simple increment of time based on days and/or hours but this can be scaled to include any DateTime method available (like add/remove months, minutes, seconds, etc.).
This method is extracted into a command that can be used in a Nani script. The command is @addTime and has "hours": and "days:" parameters (non-required, default value for both params is 0).
There are 3 variables accessible from the Nani script:
"gameDate" - string, holding the entire date formatted like mentioned above
"day" - string, current day's number
"month" - string, current month's English name converted from the month number using CultureInfo, all caps
Can be used in script like so (check available example nani script in the project folder):
Today is {month}, {day}.
The UI is a simple black box with 2 serializable text fields that display the day and month variables. I'm also working on UI buttons to increase time through the AddTime method but they aren't working as expected, the text is updated but the date variable isn't getting serialized like it happens when the method is run through the command via Nani script. I suppose it might be related to the asynchronous black magic that i'm still trying to wrap my newbie head around :)
This is a simple rundown of the files available in the project:
Runtime/
CalendarConfiguration.cs: Implements the initial start date variable.
CalendarManager.cs: Creates a Calendar menu in the Naninovel configurations, implementing the previous Configuration. I think that some of the logic on the CalendarUI script would make more sense here but right now it's just a "skeleton file" to implement the configuration.
Runtime/UI/
CalendarControlPanelButton.cs: Simple script to use on a button to toggle visibility of the calendar.
CalendarUI.cs: Where all the logic happens with the ConvertDate, AddTime and UpdateDate methods. Buttons and States are handled here as well. Please let me know if some of the code could be refactored into another class (like the manager).
Runtime/Commands/
AddTime.cs: Implements the Command class on the AddTime method in order to be able to use it in a Nani script.
Editor/
Scripts to handle UI prefab creation when using the Create Asset menu on Unity.
Prefabs/
CalendarUI.prefab: Template prefab with UI. Created when you use the Create Asset menu. Must be assigned on Naninovel's UI Resources.
Scripts/
CalendarTest.nani: Nani script to demo the functionality implemented by the extension.
Check the project here.
Please let me know of ways to improve the code. I'm looking for help with the buttons but the issue can be deeper than that and my implementation of the engine classes might not be correct.
Other than the aforementioned buttons bug, i also noticed that if i run the Nani script (i.e update the date), if i go back to the main menu and start a new game the calendar will display the previous state of the calendar and not the initial date for a new game. Is this related to the StateManager and how it de-/serializes variables or is some fundamental error on my code that i'm not seeing.
I'll be updating the code as i'm working through the bugs.
EDIT: Regarding the state not resetting when going back to the title and starting a New Game, should I use the CalendarManager class to handle all variable logic and use the ResetService method to reset the state? It occurred to me that it might be an option but I haven't tested it yet.
Essentially the CalendarUI class would be used just to display the variables from the CalendarManager.