feature: Programmable game objects #2721
pandinocoder
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Types
RenamedFromAttribute
This is used to facilitate identifying objects that were renamed or moved across versions.
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, Inherits = true, AllowMultiple = true)]
Properties:
string
Name
(positional, required, non-null)bool
IsNamespaceQualified
(optional, defaultfalse
, no effect on assembly attributes)When this is used on assemblies the
IsNamespaceQualified
property has no effect because it is used to determine whether or not to include the current namespace of the attribute target, and assemblies don't have one.Examples
DescriptorDefinitionAttribute
This is used to identify types as descriptor definitions that will be identified by the loader and instantiated.
[AttributeUsage(AttributeTargets.Class, Inherits = true, AllowMultiple = false)]
Properties:
GameObjectType
Type
(positional, required, non-null) or should this be aType
(e.g.typeof(EventDescriptor
)?DescriptorDefinition
(class
?record
?, leaning towardsrecord
forwith
syntax)Should we have an abstract class for code-based descriptor definitions? No examples of how this would be useful beyond some common API (can be done as an interface too though).
KnownAssembly
(readonly
sealed
record
)[Key]
Guid
Id
(sourced fromassembly-metadata.intersect.json
)string
Name
(most recent assembly name, should not include version or public key)string
Version
(most recent version of the assembly)[NotMapped]
Assembly
Assembly
(the CLR assembly reference, required for the construction of theKnownAssembly
)HashSet<KnownAssemblyAlias>
Aliases
HashSet<KnownType>
Types
KnownAssemblyAlias
(readonly
sealed
record
)Id
andName
Guid
Id
[ForeignKey(nameof(Id))]
KnownAssembly
Assembly
string
Name
(assembly alias, should not include version or public key, there will always exist an alias that exactly matches theKnownAssembly
)string?
Version
(most recent version of the renamed assembly, null if the assembly was never loaded with this alias)KnownTypeKind
(enum
:
byte
)Unknown
=
0
)Descriptor
=
1
Enum is meant to leave room for other kinds of known types in future features.
KnownType
(readonly
sealed
record
)Guid
AssemblyId
[ForeignKey(nameof(AssemblyId))]
KnownAssembly
Assembly
[Key]
Guid
Id
(UUID v5)string
Name
(this is namespace-qualified, there will always exist an alias that exactly matches theId
andName
)KnownTypeKind
Kind
[NotMapped]
Type
CLRType
(required for construction of theKnownType
)HashSet<KnownTypeAlias>
Aliases
KnownTypeAlias
(readonly
sealed
record
)TypeId
andName
Guid
Id
(UUID v5)Guid
AssemblyId
[ForeignKey(nameof(AssemblyId))]
KnownAssembly
Assembly
Guid
TypeId
(UUID v5)[ForeignKey(nameof(TypeId))]
KnownType
Type
string
Name
(this is namespace-qualified)Source Generators
We need a source generator to generate a
assembly-metadata.intersect.json
fileProperties
folder of all assembliesIntersect.props
andIntersectPlugin.props
files so each individual assembly doesn't need to add it (the source generator will also be referenced in those files for the same reason, this can get put into Intersect.Building with the key generator task)Current structure:
Database Tables
KnownAssemblies
Id
Id
(UUID v4 or v7), not database-generated, this is sourced fromassembly-metadata.intersect.json
KnownAs
(string, not nullable) this is the most recently seen assembly nameLatestVersion
(string, not nullable) this is the most recently seen assembly versionId
and is unique (in this table, seeKnownAssemblyAliases
for rename-aware aliases)KnownAssemblyAliases
Id
andName
Id
(UUID v4 or v7), foreign key toKnownAssemblies
Name
(string, not nullable) this is an assembly name either sourced from the assembly or[assembly: RenamedFrom(...)]
attributes, not necessarily the latestVersion
(string, not nullable) this is the most recently seen assembly version for the given aliasKnownTypes
Id
AssemblyId
, foreign key toKnownAssemblies
Id
(UUID v5), generated using theAssemblyId
as the base andName
as the extra informationName
(string), namespace-qualified most recently seen type name (not unique)KnownTypeAliases
Id
CurrentId
andName
AssemblyId
, foreign key toKnownAssemblies
CurrentTypeId
, foreign key toKnownTypes
Id
(UUID v5), generated using theAssemblyId
as the base and theName
of this row (not the current type name) as the extra informationName
, the namespace-qualified name of the type (sourced from current type name andRenamedFrom
attributes)Loader
Success/Error Handling
Identifying Known Types
assembly-metadata.intersect.json
file will be loadedKnownAssemblies
is checked for a row with a matchingId
, if it found the current assembly name (not version qualified) will be compared againstKnownAs
[assembly: RenamedFrom(...)]
attributes, and if a match to the currentKnownAs
is found it will move to step 2[assembly: RenamedFrom(...)]
attributes match, it will check theKnownAssemblyAliases
for a match, first with the current name and then by all of the renames -- if a match is found it will move to step 2KnownAssemblyAliases
they will be addedLatestVersion
ofKnownAssemblies
andKnownAssemblyAliases
in the row specific to the current alias[DescriptorDefinition]
annotated classes will be fetched, and will be checked just like the assembliesKnownTypes
and it does not match directly, has no matchingRenamedFrom
attributes, and it doesn't directly match or have anyRenamedFrom
overlap inKnownTypeAliases
, loading will be refusedKnownTypes
entry (identified by foreign keyCurrentTypeId
inKnownTypeAliases
) does not directly match, the entry will be replaced with the appropriate entry for the current type, and all aliases for the previous entry will have theirCurrentTypeId
column updated to the newId
RenamedFrom
Intended Use-Case
Allow game objects, principally events, to be written in code for those who would prefer to not use things like the event editor.
This also facilitates forks and plugins with built-in/portable game objects.
Duplicate Check
Beta Was this translation helpful? Give feedback.
All reactions