kumurtash / castlelines2d Goto Github PK
View Code? Open in Web Editor NEWCastle Lines 2D is a set of two components for Castle Game Engine
Home Page: https://kumurtash.github.io/CastleLines2D-docs/index.html
License: MIT License
Castle Lines 2D is a set of two components for Castle Game Engine
Home Page: https://kumurtash.github.io/CastleLines2D-docs/index.html
License: MIT License
I noticed you use a pattern like this to fill a newly-created instance of TCastlePolygon2D / TCastleLine2D with initial points:
constructor TCastlePolygon2D.Create(AOwner: TComponent);
begin
inherited;
...
{$ifdef CASTLE_DESIGN_MODE}
Points.Add(Vector2(0,80));
Points.Add(Vector2(25,35));
....
ReLoad;
{$endif}
end;
It means that this initialization happens always (at design-time, in editor) when TCastlePolygon2D
is created, even when TCastlePolygon2D
is created only to be deserialized (loaded) from a JSON file. In your code, these Points
will be effectively overridden later by TCastleLine2DBase.CustomSerialization
, which makes the end result correct... but adding these points at every construction is unnecessary.
It may be better to just add these initial points once when the TCastlePolygon2D / TCastleLine2D are added by user to the design. This is the purpose of TRegisteredComponent.OnCreate
method. See https://castle-engine.io/custom_components#_children_components_that_user_can_freely_edit_and_remove_using_tregisteredcomponent_oncreate for usage, although the example there is more complicated than you need, as the example shows how to add children components. You instead want to just initialize points. Something like this may be good:
type
TCastlePolygon2D = class...
private
class procedure CreateInitialPoints(Sender: TObject);
...
end;
class procedure TCastlePolygon2D.CreateInitialPoints(Sender: TObject);
begin
P := Sender as TCastlePolygon2D;
P.Points.Add(Vector2(0,80));
P.Points.Add(Vector2(25,35));
....
P.ReLoad;
end;
var
R: TRegisteredComponent;
initialization
R := TRegisteredComponent.Create;
R.ComponentClass := TCastlePolygon2D;
R.Caption := ['Polygon2D Transform'];
R.OnCreate := {$ifdef FPC}@{$endif}TMyRectanglesGroup.CreateInitialPoints;
RegisterSerializableComponent(R);
end.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.