P3R.CalendarUtils.Interfaces 1.0.1

dotnet add package P3R.CalendarUtils.Interfaces --version 1.0.1                
NuGet\Install-Package P3R.CalendarUtils.Interfaces -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="P3R.CalendarUtils.Interfaces" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add P3R.CalendarUtils.Interfaces --version 1.0.1                
#r "nuget: P3R.CalendarUtils.Interfaces, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install P3R.CalendarUtils.Interfaces as a Cake Addin
#addin nuget:?package=P3R.CalendarUtils.Interfaces&version=1.0.1

// Install P3R.CalendarUtils.Interfaces as a Cake Tool
#tool nuget:?package=P3R.CalendarUtils.Interfaces&version=1.0.1                

P3R Calendar Utilities Interface

Overview

This package will allow you to implement time-dependent changes into your Persona 3 Reload mod by registering Date Actions with the main P3R.CalendarUtils mod.

Setup

Go into your ModConfig.json file and add the following to the "ModDependencies" array: P3R.CalendarUtils.

In your Mod.cs file add the following code (or something similar):

In your using list:

using P3R.CalendarUtils.Interfaces; 
using P3R.CalendarUtils.Interfaces.Types;

Above your public Mod(ModContext) declaration:_

private ICalendarMethods _calendarMethods;

Inside the declaration:_

public Mod(ModContext)
{
    /// Standard reloaded code
    ...
    var calendarController = _modLoader.GetController<ICalendarMethods>();
    if (calendarController == null || !calendarController.TryGetTarget(out var calendarMethods))
        throw new Exception($[{_modConfig.ModName}] Could not get controller for \"{modName}\". This depedency is likely missing.");)
    _calendarMethods = calendarMethods;
    ...
    /// Things like loading files via UnrealEssentials
    ...
    _modLoader.OnModLoaderInitialized += OnAllModsLoaded;
}

Implementation

Set up the actions that will be called by P3R Calendar Utilities. For this example let's create something to check if the player has reached September. Below your Mod(ModContext) block, define your actions like so:

private Action IfSeptember;
private Action IfNotSeptember;

Now define your OnAllModsLoaded method:

private void OnAllModsLoaded()
{
    IfSeptember = () => { /* Any changes to be done when it is September */ };
    IfNotSeptember = () => { /* Code to revert the above changes to their default states */ };
    _calendarMethods.RegisterAction(new(IfSeptember, IfNotSeptember, DateOperation.During, new(2009, 09, 01), new(2009, 09, 30)))
}

The three new declarations define in the following order: the DateAction, the starting P3Date, and the ending P3Date. In the following sections I will give an overview of these types.

DateAction

A DateAction is a structure that defines any time-dependent method/action. All date actions require the following arguments: 1. An ApplyAction - the actual action that applies any change a given DateAction controls. 2. A RevertAction - as the name implies this is the opposite of the ApplyAction 3. A DateOperation type - this is an enum value that controls how the DateAction is processed. *. DateOperation.After tells P3R Calendar Utilities to invoke the ApplyAction once the current game session proceeds past a specified P3Date trigger, if the player loads a save from before this date the RevertAction is invoked. *. DateOperation.Before tells P3R Calendar Utilities to invoke the ApplyAction if the current game session has not yet reached a specified P3Date trigger, if the player loads a save from after this date the RevertAction is invoked. Note: It will be reapplied if the player loads a third save that's before the date. *. DateOperation.During tells P3R Calendar Utilities to invoke the ApplyAction when the current game session first reaches the specified time frame trigger. Once the game leaves it, the RevertAction is invoked. *. DateOperation.On tells P3R Calendar Utilities to invoke the ApplyAction only if the current game session is on a specified P3Date. If the in-game date no longer equals the trigger, the RevertAction is invoked. 4. A P3Date Start, the main trigger that P3R Calendar Utilities checks against.

If you are defining a DateOperation.During action you also need a P3Date End argument to tell P3R Calendar Utilities when the changes need to be reverted. They will always be reverted if a player loads a save from before the defined time frame. _Note: During actions are the only inclusive type, meaning they are triggered ON the start day instead of the day after. Likewise they automatically revert the day after the end day.

P3Date

The P3Date struct is an extension of the standard DateOnly made specifically for Persona 3 Reload. It converts the internal daycount (as defined by the GlobalWork.Calendar.DaysSinceApril1 value) to its equivalent number of days since January 1, 0001 in the Proleptic Gregorian calendar, using April 1, 2009 as P3R's epoch. This allows you to define dates in a user friendly way, in fact it's the same way you would a DateOnly:

public P3Date(int year, int month, int day)

So before when I defined the trigger in:

_calendarMethods.RegisterAction(new(IfSeptember, IfNotSeptember, DateOperation.During, new(2009, 09, 01), new(2009, 09, 30)))

Our start date would be September 1, 2009 and our end is September 30, 2009.

Conclusion

Once you register your DateAction the main mod will handle all the logic, and invoke or revert your changes accordingly. This, in theory bypasses the need for any datatable editing.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 66 8/6/2024
1.0.0 73 8/6/2024