-
Notifications
You must be signed in to change notification settings - Fork 0
Function Reference
This page provides a detailed reference for all key methods in the Chronicle package, including usage examples.
The central class for managing game events.
Assign a broadcaster to send events to clients.
-
Parameters:
-
caster- An object implementingIchronicleBroadcaster.
-
- Example:
ChronicleManager manager = new ChronicleManager();
manager.SetBroadcaster(new LocalBroadcaster());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-ChronicleEntryobject 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);Remove an event from the history by its unique ID.
-
Parameters:
-
id- The uniqueidof theChronicleEntry.
-
- Example:
manager.RemoveEvent("123e4567-e89b-12d3-a456-426614174000");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);Triggered when an event is added.
manager.OnChronicleAdded += entry => Debug.Log("Added: " + entry.TitleKey);Triggered when an event is removed.
manager.OnChronicleRemoved += entry => Debug.Log("Removed: ": entry.TitleKey);Interface to implement event broadcasting.
Send an event to all listeners.
-
Parameters:
-
entry- Event to broadcast.
-
- Example:
broadcaster.BroadcastChronicle(newEvent);Notify clients that an event has been removed.
-
Parameters:
-
id- Theidof the removed event.
-
- Example:
broadcaster.BroadcastChronicleRemoval(eventId);Interface to implement custom actions when an event is clicked.
Perform a custom action based on the entry's ActionKey.
-
Parameters:
-
entry-ChronicleEntrytriggering 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;
}
}
}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.
Event priority for filtering and sorting:
ChronicleEntry entry = new ChronicleEntry() {
TitleKey = "Low Priority Event",
Priority = ChroniclePriority.Low
};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; }
}