Skip to content

Function Reference

Ethan edited this page Oct 2, 2025 · 1 revision

OMGG Chronicle - Function Reference

This page provides a detailed reference for all key methods in the Chronicle package, including usage examples.


1. ChronicleManager

The central class for managing game events.

void SetBroadcaster(IChronicleBroadcaster caster)

Assign a broadcaster to send events to clients.

  • Parameters:
    • caster - An object implementing IchronicleBroadcaster.
  • Example:
ChronicleManager manager = new ChronicleManager();

manager.SetBroadcaster(new LocalBroadcaster());

void AddEvent(ChronicleEntry entry)

Add a new event to the Chronicle history. If id is not set, a unique one will be assigned. Timestamp is automatically set.

  • Parameters:
    • entry - ChronicleEntry object containing event data.
  • Example:
ChronicleEntry newCity = new ChronicleEntry() {
    TitleKey = "New City Found!",
    MessageKey = "You discovered a new city on the map.",
    ActionKey = "FocusMap",
    ActionArgs = new string[] { "egyptian001" }
};

manager.AddEvent(newCity);

void RemoveEvent(string id)

Remove an event from the history by its unique ID.

  • Parameters:
    • id - The unique id of the ChronicleEntry.
  • Example:
manager.RemoveEvent("123e4567-e89b-12d3-a456-426614174000");

IReadOnlyList<ChronicleEntry> GetHistory()

Get the complete event history as a read-only list.

  • Returns:
    • IReadOnlyList<ChronicleEntry> containing all added events.
  • Example:
var history = manager.GetHistory();

foreach (var entry in history)
  Debug.Log(entry.TitleKey);

Events

UnityAction<ChronicleEntry> OnChronicleAdded

Triggered when an event is added.

manager.OnChronicleAdded += entry => Debug.Log("Added: " + entry.TitleKey);

UnityAction<ChronicleEntry> OnChronicleAdded

Triggered when an event is removed.

manager.OnChronicleRemoved += entry => Debug.Log("Removed: ": entry.TitleKey);

2. IChronicleBroadcaster

Interface to implement event broadcasting.

void BroadcastChronicle(ChronicleEntry entry)

Send an event to all listeners.

  • Parameters:
    • entry - Event to broadcast.
  • Example:
broadcaster.BroadcastChronicle(newEvent);

void BroadcastChronicleRemoval(string id)

Notify clients that an event has been removed.

  • Parameters:
    • id - The id of the removed event.
  • Example:
broadcaster.BroadcastChronicleRemoval(eventId);

3. IChronicleActionResolver

Interface to implement custom actions when an event is clicked.

void ExecuteAction(ChronicleEntry entry)

Perform a custom action based on the entry's ActionKey.

  • Parameters:
    • entry - ChronicleEntry triggering the action.
  • Example:
public class DemoResolver : MonoBehaviour, IChronicleActionResolver {

    public void ExecuteAction(ChronicleEntry entry)
    {
        switch(entry.ActionKey) {
            case "FocusMap":
                Debug.Log("Focusing map on " + entry.ActionArgs[0]);
                break;
            case "OpenPopup":
                Debug.Log("Show message: " + entry.ActionArgs[0]);
                break;
        }
    }
}

4. ChronicleEntry

Represents a single event. Fields can be set directly when creating an entry.

  • Common usage example:
ChronicleEntry entry = new ChronicleEntry() {
    TitleKey = "Quest Completed",
    MessageKey = "You successfully completed the quest.",
    IconKey = "quest_icon",
    ActionKey = "OpenPopup",
    ActionArgs = new string[] { "Congrats!" },
    PayloadJson = "{ \"reward\": 100 }"
};
  • Optional fields: DescriptionArgs, PayloadJson.

5. ChroniclePriority

Event priority for filtering and sorting:

ChronicleEntry entry = new ChronicleEntry() {
    TitleKey = "Low Priority Event",
    Priority = ChroniclePriority.Low
};

6. IEventType

Event priority for filtering and sorting:

  • Example:
public enum GameEventType : byte {
    CityFounded,
    UnitKilled
}

public struct GameEvent : IEventType {
    public GameEventType Type { get; }
    public GameEvent(GameEventType type) { Type = type; }
}