PowerfulBacon
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# TypeDef Documentation ## Contents [toc] ## C# Game Engine ### EntityCreator #### CreateEntity Instantiates a TypeDef, setting up the properties and calling Initialize with the provided position. Parameters: - string name: The name of the TypeDef being instantiated. - Vector\<float> position: The position to created the entity at. ```csharp= EntityConfig.LoadedEntityDefs[name].InstantiateAt(position); ``` ### IInstantiable IInstantiable is the interface that represents a TypeDef. Anything referenced in a TypeDef file needs to implement IInstantiable in order for it to be able to be created. #### TypeDef A property that represents what TypeDef represents this entity. Added in #167. This property exists in order to replace the use of Types, as the TypeDef system does not use unique Types for each instantiated object. ```csharp= EntityDef TypeDef { get; set; } ``` #### SetProperty SetProperty is used during object initialization to set the properties of an object as they are defined in the XML file. The name is the identifier of the property that needs to be set. The property is the object that should be stored in that property. Property is the result of GetValue called on whatever propertyDef defines that property. It requires casting to the proper type. ```csharp= void SetProperty(string name, object property); ``` --- ##### Change Proposal Replace set property with a property registering method. ```csharp= void RegisterProperties(); ``` ```csharp= class Instantiable : IInstantiable { private string StringProperty { get; private set; } private int IntProperty { get; private set; } private Class ClassProperty { get; private set; } public void RegisterProperties() { RegisterProperty<string>(value => { StringProperty = value; }); RegisterProperty<int>(value => { IntProperty = value; }); RegisterProperty<Class>(value => { ClassProperty = value; }); } } ``` --- #### Initialize Initialize is called at the end of object instantiation, once all the properties have been set. The most common use for this method is to put the created entity in the location provided by initializePosition. ```csharp= void Initialize(Vector<float> initializePosition); ``` #### PreInitialize Pre-initialize is called at the start of object instantiation, before any of the properties have been set. ```csharp= void PreInitialize(Vector<float> initializePosition); ``` ## Writing TypeDefs TypeDef is the name for the XML storage of Entities. The name of the first child attribute does not matter. ```xml= <Entities> <Entity> ... </Entity> <Banana> ... </Banana> </Entities> ``` Entity and Banana will be treated the same. ### Boolean Types Boolean types can be written by simply writing true or fals.e ```xml= <VarName>true</VarName> <VarName>false</VarName> ``` ### Numerical Types Basic numerical types can be parsed by inserting a number in the text space between a tag. ```xml= <VarName>0</VarName> <VarName>5.1</VarName> <VarName>5.128673</VarName> <VarName>-6</VarName> ``` ### Text Types Any text that isn't a boolean or numerical will be saved into a string. ```xml= <VarName>Any text</VarName> ``` ### Entity / Class Types Internally Entity and Classes are treated as the same thing. When the parent of an entity/class tag is instantiated, the parent or class associated with this variable will also be instantiated. Example: ```csharp= class ClassA : IInstantiable { ClassB Variable { get; private set; } ... } class ClassB : IInstantiable { int IntegerProperty { get; private set; } ... } ``` When the ClassA class is created, ClassB will be instantiated with whatever values are provided. ```xml= <Entity Class="ClassA"> <Variable Class="ClassB"> <IntegerProperty>5</IntegerProperty> </Variable> </Entity> ``` Note that currently there is no way to store a TypeDef for instantiation later, this needs implementing. (If we want to store an entityDef but not instantiate it, and only instantiate it when called, this is not possible) ### List Types ListDefs are returned as a list of objects when GetValue is called on them. They are defined by a parent component with ListEntry in their children. ```xml= <VariableName> <ListEntry>Value1</ListEntry> <ListEntry>Value2</ListEntry> <ListEntry>Value3</ListEntry> </VariableName> ``` Note that the contents of list entries are defs themselves, so can contain complex types including entities and other lists. ```xml= <VariableName> <ListEntry> <AnotherList> <ListEntry>5</ListEntry> <ListEntry>10</ListEntry> <ListEntry>15</ListEntry> </AnotherList> </ListEntry> </VariableName> ``` ### Enumerable Types Enum types do not need to be specified, as they are infered from the variable type with whatever the enum property is being applied to. Enum types are specified by having a set of EnumValue children containing the name of the flag to add. ```csharp= enum EnumExample { FLAG_SAMPLE } class ExampleClass : IInstantiable { EnumExample Flags { get; private set; } } ``` ```xml= <Flags> <EnumValue>FLAG_SAMPLE</EnumValue> </Flags> ``` ### Constants The constant property can reference a value stored in a seperate place. The constant referenced has to be defined in a constants file somewhere. ```xml= <Constants> <Constant Name="CONSTANT_NAME"> 273.15 </Constant> </Constants> ... <VarName> <Constant Name="CONSTANT_NAME" /> </VarName> ``` During parsing `<Constant Name="CONSTANT_NAME" />` is replaced with 273.15. ### Property Types Property is the default type that the xml variables will be saved as when the parser cannot determine the type of what is being represented in the XML file. When GetValue() is called on a property type, the PropertyDef is returned without anything being created or parsed. This can happen when a tag has children and doesn't have any of the following properties: - Does not have the 'Name' attribute. (Is not a top level entity) - Does not have the 'Class' attribute. (Is not an EntityDef) - Does not have 'Components' as a parent element. (Is not a Component) - Does not have 'ListEntry' as a child element. (Is not a list) - Does not have 'DictEntry' as a child element. (Is not a dictionary) - Does not have 'EnumValue' as a child element. (Is not an enum) - Does not have 'Constant' as a child element. (Does not contain a constant) ```xml= <Property> <IntegerElement>5</IntegerElement> <StringElement>Hello!</StringElement> </Property> ``` When parsed this will return a propertyDef with the Name 'Property' and 2 children Properties: - An integerDef containing 5. - A stringDef containing "Hello!" ### Special Tags #### Components Children elements of the components tag will be treated as classes rather than variable names. Any child component of the \<Components> tag is assumed to be a class. ```xml= <Components> <ComponentClassName> ... </ComponentClassName> </Components> ``` ## Potential Issues This code should work? ```xml= <Entity Name="Thing"> <PropertyEntity ParentName="Thing" /> </Entity> ``` ## Changes Required - ParentName (Cannot be instantiated on getValue() as this would allow for a self referencing loop of death) and Class tags are treated inconsistently. - There is no way to store an entityDef, as they are automatically instantiated when GetValue() is called. - Why is there no way to initialize things that don't have a position (data vs entities)?

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully