Nebula
Loading...
Searching...
No Matches
propertyextension.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
25//------------------------------------------------------------------------------
26#include "game/levelextension.h"
27#include "game/entity.h"
28#include "util/array.h"
29#include "util/string.h"
30#include "util/stringatom.h"
31#include "assemblyid.h"
32
33//------------------------------------------------------------------------------
34namespace Scripting
35{
36
37class NSharpServer;
38
39//------------------------------------------------------------------------------
43{
44public:
48 using ChangeFunc = void(*)(uint64_t entityId, const char* path, const char* oldText, const char* newText);
49 static void SetChangeCallback(ChangeFunc func);
50
53 using RevertFunc = void(*)(uint64_t entityId, const char* path);
54 static void SetRevertCallback(RevertFunc func);
55
59 using AuthoredFunc = bool(*)(uint64_t entityId, const char* path);
60 static void SetAuthoredCallback(AuthoredFunc func);
61
63 static void Register(Scripting::NSharpServer* server, Scripting::AssemblyId assemblyId);
64
66 static void Capture(Game::Entity entity, Util::String& out);
67
69 static void Apply(Game::Entity entity, const char* json);
70
71 // -- The merge contract. The level formats cannot read what this extension produces, so these are the
72 // only things they can say about it --
73
75 static void CaptureKeys(Game::Entity entity, const Util::Array<Util::String>& keys, Util::String& out);
76
78 static void TextKeys(const char* text, Util::Array<Util::String>& out);
79
81 static void Merge(const char* base, const char* over, Util::String& out);
82
86 static void Resolve(const char* base, const Util::Array<Util::String>& keys, Util::String& out);
87
90 static void SetRefContext(const char* pairs);
91
94 static void TextRefs(const char* text, Util::Array<Game::TextRef>& out);
95
97 static void Remap(const char* text, const char* pairs, Util::String& out);
98
102 static void ClearMirror(uint32_t worldId);
103
104 // -- The editor contract --
105
108 static void Draw(Game::Entity entity);
109
112
116 static void RecordChange(Game::Entity entity, const char* path, const char* oldText, const char* newText);
117
120 static void RequestRevert(Game::Entity entity, const char* path);
121
124 static bool IsAuthored(Game::Entity entity, const char* path);
125
126 // -- The menu contract --
127
128 // The names the editor's dropdown lists. The panel does not know what a property is, so the managed side
129 // mirrors its registry into here. The mirror is rebuilt from the managed side on every change, because an
130 // assembly can be registered more than once
131 static void AddPropertyName(const char* propertyName);
132 static void ClearPropertyNames();
134
136 static bool HasProperty(Game::Entity entity, const char* propertyName);
137
139 static void DefaultPropertyJson(const char* propertyName, Util::String& out);
140
141private:
143 static void* applyProperties;
144 static void* drawProperties;
145 static void* hasProperty;
147 static void* serializeKeys;
148 static void* jsonKeys;
149 static void* mergeJson;
150 static void* resolveJson;
151 static void* setRefContext;
152 static void* textRefs;
153 static void* remapRefs;
154 static void* clearWorldMirror;
155
159
160 // A feature unit can be attached more than once, and the registry refuses two extensions with the
161 // same name, so the extension is only registered the first time
162 static bool registered;
163
164 // The name the extension registered under, which is what the editor's override marker is keyed by
166
167 // The buffer the managed side writes into. Owned here, because the delegate writes into it directly
169
170 // The names the managed side mirrored. Owned here, because the panel reads them while it draws
172};
173
174} // namespace Scripting
175//------------------------------------------------------------------------------
C# backend for the Nebula scripting subsystem.
Definition nsharpserver.h:31
The level formats' contribution for managed properties.
Definition propertyextension.h:43
static void TextRefs(const char *text, Util::Array< Game::TextRef > &out)
the entity references a text names, as the paths this extension names its fields by.
Definition propertyextension.cc:397
static void * defaultPropertyJson
Definition propertyextension.h:146
static void RecordChange(Game::Entity entity, const char *path, const char *oldText, const char *newText)
the change the managed write path reported.
Definition propertyextension.cc:536
static void SetRefContext(const char *pairs)
the file's guid map, as "guid:entityId" pairs.
Definition propertyextension.cc:381
static RevertFunc revertCallback
Definition propertyextension.h:157
void(*)(uint64_t entityId, const char *path, const char *oldText, const char *newText) ChangeFunc
what an editor hands the extension when it attaches.
Definition propertyextension.h:48
static void RequestRevert(Game::Entity entity, const char *path)
the key the managed side pressed the override marker on.
Definition propertyextension.cc:551
static const Util::Array< Util::String > & PropertyNames()
Definition propertyextension.cc:601
static bool HasProperty(Game::Entity entity, const char *propertyName)
true when the entity has the property, which is what makes a dropdown row read as already added
Definition propertyextension.cc:612
static void * jsonKeys
Definition propertyextension.h:148
void(*)(uint64_t entityId, const char *path) RevertFunc
what an editor hands the extension for a revert request.
Definition propertyextension.h:53
static void SetChangeCallback(ChangeFunc func)
An editor attaches itself here.
Definition propertyextension.cc:116
static void CaptureKeys(Game::Entity entity, const Util::Array< Util::String > &keys, Util::String &out)
the json for one entity with only the named keys, which is what a linked entity writes
Definition propertyextension.cc:206
static void SetRevertCallback(RevertFunc func)
An editor attaches itself here.
Definition propertyextension.cc:127
static void * remapRefs
Definition propertyextension.h:153
static void Merge(const char *base, const char *over, Util::String &out)
what the base text gives when the keys the other text carries are put over it
Definition propertyextension.cc:299
static void Capture(Game::Entity entity, Util::String &out)
the json for one entity, as the managed runtime produces it
Definition propertyextension.cc:159
static void Remap(const char *text, const char *pairs, Util::String &out)
the text with the named paths' references put as the given guids, as "path\tguid" pairs
Definition propertyextension.cc:465
static ChangeFunc changeCallback
Definition propertyextension.h:156
static void * mergeJson
Definition propertyextension.h:149
static void Register(Scripting::NSharpServer *server, Scripting::AssemblyId assemblyId)
resolve the managed entry points and register the extension with the level formats
Definition propertyextension.cc:56
static void * serializeKeys
Definition propertyextension.h:147
static Util::Array< Util::String > names
Definition propertyextension.h:171
static void * hasProperty
Definition propertyextension.h:145
static void * textRefs
Definition propertyextension.h:152
bool(*)(uint64_t entityId, const char *path) AuthoredFunc
what an editor hands the extension for the override marker.
Definition propertyextension.h:59
static void AddPropertyName(const char *propertyName)
One of the names the editor's dropdown lists.
Definition propertyextension.cc:580
static void * serializeProperties
Definition propertyextension.h:142
static Util::StringAtom ExtensionName()
the name the extension registered under, which is what the editor's override marker is keyed by
Definition propertyextension.cc:147
static void ClearPropertyNames()
Definition propertyextension.cc:592
static void * setRefContext
Definition propertyextension.h:151
static void TextKeys(const char *text, Util::Array< Util::String > &out)
the keys a text carries, as the paths this extension names them by
Definition propertyextension.cc:248
static void * applyProperties
Definition propertyextension.h:143
static void * drawProperties
Definition propertyextension.h:144
static void SetAuthoredCallback(AuthoredFunc func)
An editor attaches itself here.
Definition propertyextension.cc:138
static Util::StringAtom extensionName
Definition propertyextension.h:165
static AuthoredFunc authoredCallback
Definition propertyextension.h:158
static bool registered
Definition propertyextension.h:162
static void * resolveJson
Definition propertyextension.h:150
static bool IsAuthored(Game::Entity entity, const char *path)
whether the editor's marker says this entity authored the path.
Definition propertyextension.cc:566
static Util::Array< char > buffer
Definition propertyextension.h:168
static void Draw(Game::Entity entity)
the property section, drawn by the managed side through the editor's ImGui surface.
Definition propertyextension.cc:517
static void Apply(Game::Entity entity, const char *json)
one entity, put back from the json the file carried for it
Definition propertyextension.cc:190
static void * clearWorldMirror
Definition propertyextension.h:154
static void ClearMirror(uint32_t worldId)
the mirror this extension keeps of a world, dropped.
Definition propertyextension.cc:502
static void Resolve(const char *base, const Util::Array< Util::String > &keys, Util::String &out)
the text for the named keys, each value read from the base text, or the field's default when the base...
Definition propertyextension.cc:336
static void DefaultPropertyJson(const char *propertyName, Util::String &out)
the text a default instance of the property produces, which is what an add writes
Definition propertyextension.cc:627
Nebula's dynamic array class.
Definition array.h:61
A StringAtom.
Definition stringatom.h:22
Nebula's universal string class.
Definition string.h:50
Definition game.cc:16
An entity is essentially just an Id with some utility functions attached.
Definition entity.h:35
Definition assemblyid.h:12