Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefab style feature #34

Merged
merged 9 commits into from
Oct 9, 2024
Merged

Prefab style feature #34

merged 9 commits into from
Oct 9, 2024

Conversation

sondirn
Copy link
Contributor

@sondirn sondirn commented Oct 8, 2024

This update allows the user to have a pre-fab style workflow.

Simply Call GetEntityDefinition From the LDtkFile class to return an Entity instance with the default data that is set in the LDtk editor.

This update allows the user to have a pre-fab style workflow similar to Unity.

Simply Call GetEntityDefinition<T> From the LDtkFile class to return an Entity instance with the default data set in the LDtk editor.
@IrishBruse
Copy link
Owner

Hi thanks for the PR it probably makes more sense to generate the default class instance in the code generator project as it seems to be pretty static also the ldtkfile and full version are auto generated so if you make a change to it make sure its generated from the schema and not manually modified but if you go the generator route no changes should be necessary.

@sondirn
Copy link
Contributor Author

sondirn commented Oct 8, 2024

Correct, I am currently using code generation. However if any of the other variables are altered then you wouldn't know which one is the "default one".

This would just add an easier way to get the entity with default values.

@IrishBruse
Copy link
Owner

IrishBruse commented Oct 8, 2024

Your pr does not have any changes to LDtk.JsonSchema thats the project that generated the LDtkFile and LDtkFileFull this pr does not contain any changes to the code generation that I can see.
Also my point is instead of getting the entity at runtime we can create a static readonly one generated by LDtk.CodeGen I dont quite get what you mean by other variables are altered then you wouldn't know which one is the "default one" What i mean is to create an instance of that entity thats static in side the generated code.

https://github.com/IrishBruse/LDtkMonogame/blob/main/LDtk.Example/LDtkTypes/World/Entities/Enemy.cs


public partial class Enemy : ILDtkEntity
{
	public static readonly Enemy Default = new(){
	    Identifier=blah
	    Type = BlueBee
	    ...etc
	}

or maybe

	public static Enemy Default() => new(){
	    Identifier=blah
	    Type = BlueBee
	    ...etc
	}

    public string Identifier { get; set; }
    public System.Guid Iid { get; set; }
    public int Uid { get; set; }
    public Vector2 Position { get; set; }
    public Vector2 Size { get; set; }
    public Vector2 Pivot { get; set; }
    public Rectangle Tile { get; set; }

    public Color SmartColor { get; set; }

    public Vector2[] Wander { get; set; }
    public EnemyType Type { get; set; }
    public Color Color { get; set; }
}

this way if you want to get it you just do Enemy.Default for the default instance if you wish to clone the default instance using something like ICloneable should work this way there is no need for heavy runtime reflection

@sondirn
Copy link
Contributor Author

sondirn commented Oct 9, 2024

This is a great idea. Let me cook something up so it's created on the CodeGen side rather than using reflection at runtime.

@sondirn sondirn closed this Oct 9, 2024
@sondirn sondirn reopened this Oct 9, 2024
@sondirn
Copy link
Contributor Author

sondirn commented Oct 9, 2024

Here is an updated version with your idea.

I've tested it out with my current workflow and have no issues. Not every type of variable can be initialized in LDtk. For example Arrays can only be assigned when an Entity instance is created in a level. So when pulling from entity definitions arrays will always be null.

I don't necessarily foresee issues, but more testing will need to be done

@IrishBruse
Copy link
Owner

Great job thanks 😃

@IrishBruse IrishBruse merged commit 0ddf8aa into IrishBruse:main Oct 9, 2024
1 check passed
@IrishBruse
Copy link
Owner

Release to test in 1.6.0-beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants