Nebula
Loading...
Searching...
No Matches
Nebula.PropertyLevelFormat Class Reference

Detailed Description

The level format's contribution for managed properties.

The native side treats what this produces as text it does not interpret: it writes the text as a node under the entity, and it hands the text it read back here. That is what lets a property hold anything the json writer can express, and what lets a level written with this extension still be saved by a build that does not have it.

Entity references inside a property are written as the guid the file names the target by, and read back through the map the file gives. The level format cannot resolve them on its own, because it does not read this text, so it hands the map here before the call that needs it. Without a map a reference writes as null, which is what a build that has no file to resolve against gets.

Classes

class  EntityConverter
class  Vector2Converter
class  Vector3Converter
class  Vector4Converter
class  QuaternionConverter
class  ColorConverter

Static Public Member Functions

static string Utf8 (IntPtr ptr, int length)
 Text from a pointer the native side owns.
static void SetRefContext (string pairs)
 The file's guid map, as "guid:entityId" pairs.
static bool IsAuthored (ulong entityId, string path)
static List< string > CollectKeys (string text)
 The keys one text carries, as "property.field" paths.
static int JsonKeys (string text, IntPtr outBuffer, int maxLen)
static string MergeJson (string baseText, string overText)
 What the base text gives when the keys the other text carries are put over it.
static int MergeJson (string baseText, string overText, IntPtr outBuffer, int maxLen)
static string Resolve (string baseText, string keys)
 The text for the named keys, each value read from the base text, or the field's default when the base has nothing.
static int Resolve (string baseText, string keys, IntPtr outBuffer, int maxLen)
static void RegisterAssembly (Assembly assembly)
 The property types of an assembly, by the name the level file carries them under.
static void ClearAssembly (Assembly assembly)
 The property types of an assembly that is going away.
static int SerializeEntity (ulong entityId, IntPtr outBuffer, int maxLen)
 The json object of one entity's properties, written into a buffer the native side owns.
static int SerializeKeys (ulong entityId, string keys, IntPtr outBuffer, int maxLen)
 The entity's text with only the keys it authored, as the newline separated paths the level format holds for it.
static unsafe int ApplyEntity (ulong entityId, IntPtr jsonUtf8, int length)
 One entity, put back from the json the file carried for it.
static void RecordChange (ulong entityId, Type type, string fieldName, string valueJson)
 The write path the inspector uses.
static void DrawProperties (ulong entityId)
 The property section the inspector draws.
static int HasProperty (ulong entityId, string propertyName)
 Whether the entity has the property.
static int DefaultPropertyJson (string propertyName, IntPtr outBuffer, int maxLen)
 The text a default instance of the type produces, which is what an editor's add writes.
static string BuildJsonText (Nebula.Game.Entity entity, HashSet< string > keys)

Private Member Functions

static void RecordPropertyChange (ulong entityId, string path, string oldText, string newText)
static void RequestPropertyRevert (ulong entityId, string path)
static bool IsAuthoredCall (ulong entityId, string path)
static void AddNameCall (string name)
static void ClearNamesCall ()

Static Private Member Functions

static PropertyLevelFormat ()
static string KeyPath (string propertyName, string fieldName)
static List< string > SplitKeys (string keys)
static void WriteMerged (Utf8JsonWriter writer, JsonNode baseNode, bool hasBase, JsonNode overNode, bool hasOver)
static void WriteNode (Utf8JsonWriter writer, JsonNode node)
static int WriteNames (List< string > names, IntPtr outBuffer, int maxLen)
static int WriteText (string text, IntPtr outBuffer, int maxLen)
static int WriteBytes (byte[] bytes, IntPtr outBuffer, int maxLen)
static void MirrorNames ()
static void DrawProperty (ulong entityId, Nebula.Game.Property property)
static void DrawField (ulong entityId, Type type, Nebula.Game.Property property, FieldInfo field)
static byte ToByte (float value)
static bool DrawEnum (string key, Type enumType, object current, out int index, string description)
static int ApplyProperty (Nebula.Game.Entity entity, string propertyName, string json)
static Nebula.Game.Entity ResolveEntity (World world, UInt64 id)
static Type GetPropertyType (string propertyName)
static List< Nebula.Game.Property > SortedProperties (Nebula.Game.Entity entity)
static byte[] BuildJson (Nebula.Game.Entity entity, HashSet< string > keys)
static string BuildChangeJson (Nebula.Game.Entity entity, Type type, string fieldName, string valueJson)
static bool AnyKeyFor (HashSet< string > keys, Type type)
static void WritePropertyFields (Utf8JsonWriter writer, Type type, Nebula.Game.Property property, string fieldName, string valueJson, HashSet< string > keys)
static FieldInfo[] GetSerializableFields (Type type)

Static Private Attributes

static readonly Dictionary< string, Type > propertyTypes = []
static readonly Dictionary< string, UInt64 > refByGuid = []
static readonly Dictionary< UInt64, string > guidByRef = []
static readonly JsonSerializerOptions jsonOptions
static readonly JsonWriterOptions writerOptions
static readonly Dictionary< string, object > pendingValues = []
static readonly byte[] comboOptions = new byte[4096]
static readonly byte[] stringBuffer = new byte[1024]
static readonly float[] floatBuffer = new float[4]

Constructor & Destructor Documentation

◆ PropertyLevelFormat()

Nebula.PropertyLevelFormat.PropertyLevelFormat ( )
inlinestaticprivate

Member Function Documentation

◆ AddNameCall()

void Nebula.PropertyLevelFormat.AddNameCall ( string name)
private

◆ AnyKeyFor()

bool Nebula.PropertyLevelFormat.AnyKeyFor ( HashSet< string > keys,
Type type )
inlinestaticprivate

◆ ApplyEntity()

unsafe int Nebula.PropertyLevelFormat.ApplyEntity ( ulong entityId,
IntPtr jsonUtf8,
int length )
inlinestatic

One entity, put back from the json the file carried for it.

Exact: the entity's properties are the nodes the text names, and what it does not name is taken off. A command holds the entity's whole text, so this is what makes a change that took one property off read as a change rather than as an addition. A property the text names but the assembly does not have is skipped, because there is no type to make it from.

◆ ApplyProperty()

int Nebula.PropertyLevelFormat.ApplyProperty ( Nebula.Game.Entity entity,
string propertyName,
string json )
inlinestaticprivate

◆ BuildChangeJson()

string Nebula.PropertyLevelFormat.BuildChangeJson ( Nebula.Game.Entity entity,
Type type,
string fieldName,
string valueJson )
inlinestaticprivate

◆ BuildJson()

byte[] Nebula.PropertyLevelFormat.BuildJson ( Nebula.Game.Entity entity,
HashSet< string > keys )
inlinestaticprivate

◆ BuildJsonText()

string Nebula.PropertyLevelFormat.BuildJsonText ( Nebula.Game.Entity entity,
HashSet< string > keys )
inlinestatic

◆ ClearAssembly()

void Nebula.PropertyLevelFormat.ClearAssembly ( Assembly assembly)
inlinestatic

The property types of an assembly that is going away.

◆ ClearNamesCall()

void Nebula.PropertyLevelFormat.ClearNamesCall ( )
private

◆ CollectKeys()

List< string > Nebula.PropertyLevelFormat.CollectKeys ( string text)
inlinestatic

The keys one text carries, as "property.field" paths.

The level format cannot see inside the text, so this is how it knows which part of it an entity authored.

◆ DefaultPropertyJson()

int Nebula.PropertyLevelFormat.DefaultPropertyJson ( string propertyName,
IntPtr outBuffer,
int maxLen )
inlinestatic

The text a default instance of the type produces, which is what an editor's add writes.

It is the entity shape, because that is the shape a command holds, so an add composes it over what the entity already has rather than applying it on its own.

◆ DrawEnum()

bool Nebula.PropertyLevelFormat.DrawEnum ( string key,
Type enumType,
object current,
out int index,
string description )
inlinestaticprivate

◆ DrawField()

void Nebula.PropertyLevelFormat.DrawField ( ulong entityId,
Type type,
Nebula.Game.Property property,
FieldInfo field )
inlinestaticprivate

◆ DrawProperties()

void Nebula.PropertyLevelFormat.DrawProperties ( ulong entityId)
inlinestatic

The property section the inspector draws.

The panel owns the window and calls this inside it, so everything here is inside the ImGui frame.

A field the surface has no widget for is drawn as text rather than guessed at.

◆ DrawProperty()

void Nebula.PropertyLevelFormat.DrawProperty ( ulong entityId,
Nebula.Game.Property property )
inlinestaticprivate

◆ GetPropertyType()

Type Nebula.PropertyLevelFormat.GetPropertyType ( string propertyName)
inlinestaticprivate

◆ GetSerializableFields()

FieldInfo[] Nebula.PropertyLevelFormat.GetSerializableFields ( Type type)
inlinestaticprivate

◆ HasProperty()

int Nebula.PropertyLevelFormat.HasProperty ( ulong entityId,
string propertyName )
inlinestatic

Whether the entity has the property.

This is what makes the editor's dropdown row read as already added, the same way a component that is already on the entity does.

◆ IsAuthored()

bool Nebula.PropertyLevelFormat.IsAuthored ( ulong entityId,
string path )
inlinestatic

◆ IsAuthoredCall()

bool Nebula.PropertyLevelFormat.IsAuthoredCall ( ulong entityId,
string path )
private

◆ JsonKeys()

int Nebula.PropertyLevelFormat.JsonKeys ( string text,
IntPtr outBuffer,
int maxLen )
inlinestatic

◆ KeyPath()

string Nebula.PropertyLevelFormat.KeyPath ( string propertyName,
string fieldName )
inlinestaticprivate

◆ MergeJson() [1/2]

string Nebula.PropertyLevelFormat.MergeJson ( string baseText,
string overText )
inlinestatic

What the base text gives when the keys the other text carries are put over it.

A text that is not an object carries nothing, and a key the base does not have joins it.

◆ MergeJson() [2/2]

int Nebula.PropertyLevelFormat.MergeJson ( string baseText,
string overText,
IntPtr outBuffer,
int maxLen )
inlinestatic

◆ MirrorNames()

void Nebula.PropertyLevelFormat.MirrorNames ( )
inlinestaticprivate

◆ RecordChange()

void Nebula.PropertyLevelFormat.RecordChange ( ulong entityId,
Type type,
string fieldName,
string valueJson )
inlinestatic

The write path the inspector uses.

It does not write the field: it works out what the entity's text would be after the change and hands the before and the after text to the editor, which is what runs the change through a command. That is why the command is the only place a property changes, and why plugin code that sets a field directly does not record anything: a runtime change is not an authoring change.

A null field means the property is left out, which is what a removal reports. The path is what the recorder builds the override marker from, and it is the only thing that says which key inside the text changed. A property the entity did not have is reported as the whole property, which is what the recorder reads as an add: every key the after text carries for it is the entity's own.

◆ RecordPropertyChange()

void Nebula.PropertyLevelFormat.RecordPropertyChange ( ulong entityId,
string path,
string oldText,
string newText )
private

◆ RegisterAssembly()

void Nebula.PropertyLevelFormat.RegisterAssembly ( Assembly assembly)
inlinestatic

The property types of an assembly, by the name the level file carries them under.

◆ RequestPropertyRevert()

void Nebula.PropertyLevelFormat.RequestPropertyRevert ( ulong entityId,
string path )
private

◆ Resolve() [1/2]

string Nebula.PropertyLevelFormat.Resolve ( string baseText,
string keys )
inlinestatic

The text for the named keys, each value read from the base text, or the field's default when the base has nothing.

A revert needs this because a key the chain does not carry has no value to put back, and only this side knows what its field's default is.

◆ Resolve() [2/2]

int Nebula.PropertyLevelFormat.Resolve ( string baseText,
string keys,
IntPtr outBuffer,
int maxLen )
inlinestatic

◆ ResolveEntity()

Nebula.Game.Entity Nebula.PropertyLevelFormat.ResolveEntity ( World world,
UInt64 id )
inlinestaticprivate

◆ SerializeEntity()

int Nebula.PropertyLevelFormat.SerializeEntity ( ulong entityId,
IntPtr outBuffer,
int maxLen )
inlinestatic

The json object of one entity's properties, written into a buffer the native side owns.

Answers with the length it needs when the buffer was too small, which is what makes the call be made again with a bigger one.

◆ SerializeKeys()

int Nebula.PropertyLevelFormat.SerializeKeys ( ulong entityId,
string keys,
IntPtr outBuffer,
int maxLen )
inlinestatic

The entity's text with only the keys it authored, as the newline separated paths the level format holds for it.

This is what a linked entity writes: the rest of it is what its prefab chain gives, and writing the whole value here would make the instance stop following the prefab.

◆ SetRefContext()

void Nebula.PropertyLevelFormat.SetRefContext ( string pairs)
inlinestatic

The file's guid map, as "guid:entityId" pairs.

This is the only way the level format can give it here, because it does not read this text and cannot know which parts of it name entities. It is only valid for the duration of the call that sets it.

◆ SortedProperties()

List< Nebula.Game.Property > Nebula.PropertyLevelFormat.SortedProperties ( Nebula.Game.Entity entity)
inlinestaticprivate

◆ SplitKeys()

List< string > Nebula.PropertyLevelFormat.SplitKeys ( string keys)
inlinestaticprivate

◆ ToByte()

byte Nebula.PropertyLevelFormat.ToByte ( float value)
inlinestaticprivate

◆ Utf8()

string Nebula.PropertyLevelFormat.Utf8 ( IntPtr ptr,
int length )
inlinestatic

Text from a pointer the native side owns.

The formats hand null for a text they do not have, which is what a merge with nothing on one side is, and the marshaler throws on a null pointer instead of answering with an empty string.

◆ WriteBytes()

int Nebula.PropertyLevelFormat.WriteBytes ( byte[] bytes,
IntPtr outBuffer,
int maxLen )
inlinestaticprivate

◆ WriteMerged()

void Nebula.PropertyLevelFormat.WriteMerged ( Utf8JsonWriter writer,
JsonNode baseNode,
bool hasBase,
JsonNode overNode,
bool hasOver )
inlinestaticprivate

◆ WriteNames()

int Nebula.PropertyLevelFormat.WriteNames ( List< string > names,
IntPtr outBuffer,
int maxLen )
inlinestaticprivate

◆ WriteNode()

void Nebula.PropertyLevelFormat.WriteNode ( Utf8JsonWriter writer,
JsonNode node )
inlinestaticprivate

◆ WritePropertyFields()

void Nebula.PropertyLevelFormat.WritePropertyFields ( Utf8JsonWriter writer,
Type type,
Nebula.Game.Property property,
string fieldName,
string valueJson,
HashSet< string > keys )
inlinestaticprivate

◆ WriteText()

int Nebula.PropertyLevelFormat.WriteText ( string text,
IntPtr outBuffer,
int maxLen )
inlinestaticprivate

Member Data Documentation

◆ comboOptions

readonly byte [] Nebula.PropertyLevelFormat.comboOptions = new byte[4096]
staticprivate

◆ floatBuffer

readonly float [] Nebula.PropertyLevelFormat.floatBuffer = new float[4]
staticprivate

◆ guidByRef

readonly Dictionary<UInt64, string> Nebula.PropertyLevelFormat.guidByRef = []
staticprivate

◆ jsonOptions

readonly JsonSerializerOptions Nebula.PropertyLevelFormat.jsonOptions
staticprivate
Initial value:
= new()
{
WriteIndented = false,
}

◆ pendingValues

readonly Dictionary<string, object> Nebula.PropertyLevelFormat.pendingValues = []
staticprivate

◆ propertyTypes

readonly Dictionary<string, Type> Nebula.PropertyLevelFormat.propertyTypes = []
staticprivate

◆ refByGuid

readonly Dictionary<string, UInt64> Nebula.PropertyLevelFormat.refByGuid = []
staticprivate

◆ stringBuffer

readonly byte [] Nebula.PropertyLevelFormat.stringBuffer = new byte[1024]
staticprivate

◆ writerOptions

readonly JsonWriterOptions Nebula.PropertyLevelFormat.writerOptions
staticprivate
Initial value:
= new()
{
Indented = false,
}

The documentation for this class was generated from the following file: