Skip to content

Level Class

Level is the main entry point of the library, providing methods to load, manipulate, and save ADOFAI levels. It is located in the SharpFAI.Serialization namespace.

Constructor

csharp
// Load from file path
var level = new Level("path/to/level.adofai");

// Initialize from level info dictionary
var level = new Level(levelInfoDict);

// Create a new level with default settings
var level = Level.CreateNewLevel();

Properties

PropertyDescription
rootRoot JSON object of the level (angleData / settings / actions / decorations always in sync)
settingsLevel settings JObject
angleDataAngle array JArray
actionsEvent list JArray
decorationsDecoration list JArray (exists when version > 10)
anglesRead-only angle array ReadOnlyCollection<double>
pathToLevelFile path when loaded
deserializedEventsRead-only deserialized event list

The constructor automatically handles the following: reads directly when angleData exists; calls InitAngleData() to convert when only pathData exists; and pre-deserializes events.

Settings Management

csharp
var bpm = level.GetSetting<double>("bpm");        // Read
level.PutSetting("bpm", 180);                     // Write
bool has = level.HasSetting("artist");            // Whether it exists
level.RemoveSettings("offset", "pitch");          // Remove multiple settings

level.SetSong("song.mp3");                        // Set song
var audioPath = level.GetAudioPath();             // Absolute path of audio file
MethodDescription
GetSetting<T>(string)Get a setting value
PutSetting<T>(string, T)Set a setting value
HasSetting(string)Check if a setting exists
RemoveSettings(params string[])Remove multiple settings
SetSong(string)Set the level song
GetAudioPath()Get the absolute path of the audio file

Event Management

csharp
// Add event at specified floor
level.AddEvent(10, EventType.Twirl);

// Add using an event object
var hold = new Hold(duration: 4) { Floor = 5 };
level.AddEvent(hold);

// Query
var events = level.GetFloorEvents(10);            // All events on floor 10
var twirls = level.GetEvents(EventType.Twirl);    // All Twirls
var longPauses = level.GetEventsIf(e =>
    e.EventType == EventType.Pause && e.ToEvent<Pause>().Duration > 2.0);

// Check
bool hasAny = level.HasEvents(10);
bool hasTwirl = level.HasEvents(10, EventType.Twirl);

// Remove
level.RemoveEventsIf(e => e.EventType == EventType.MoveCamera);
level.RemoveFloorEvents(5, EventType.Twirl, 2);
MethodDescription
AddEvent(int floor, EventType type, JObject data)Add an event to a floor
AddEvent(BaseEvent)Add an event from an event object
GetEvents(int floor, EventType type)Get events of a specific type on a specific floor
GetFloorEvents(int floor)Get all events on a floor
GetEvents(EventType type)Get all events of a specific type
GetEventsIf(Func<BaseEvent, bool>)Get events matching a condition
HasEvents(int floor) / HasEvents(int floor, EventType)Check if a floor has events
RemoveEventsIf(Func<BaseEvent, bool>)Remove events matching a condition
RemoveFloorEvents(int floor, EventType type, int count)Remove events from a floor
DeserializeEvents(bool includeDecorations)Deserialize events into objects

Decoration Management

csharp
// Add text decoration
level.AddTextToDecorations(10, "Hello", tag: "title", relativeToScreen: true);

// Add decoration
level.AddDecoration(10, EventType.AddText, "title", false, null);
MethodDescription
AddTextToDecorations(int floor, string text, string tag, bool relativeToScreen, JObject data)Add a text decoration
AddDecoration(int floor, EventType type, string tag, bool relativeToScreen, JObject data)Add a decoration

Serialization

csharp
level.Save("modified-level.adofai");     // Save to file
string json = level.ToString();          // Convert to JSON string
MethodDescription
Save(string newLevelPath, bool indent = true)Save the level to a file
ToString(bool indent = true)Convert to JSON string

Equality Comparison

Level overloads == / !=: when both have file paths, they are compared by path; otherwise, they are compared item by item via deep comparison of root, decorations, settings, angleData, and actions.

An organization that researches and expands the functions of ADOFAI