|
@@ -18,12 +18,19 @@ Global jsonifier:=New Jsonifier
|
|
|
|
|
|
Class Component
|
|
Class Component
|
|
|
|
|
|
|
|
+ 'simple contructor
|
|
Method New( entity:Entity )
|
|
Method New( entity:Entity )
|
|
|
|
|
|
_entity=entity
|
|
_entity=entity
|
|
|
|
|
|
_entity.AddComponent( Self )
|
|
_entity.AddComponent( Self )
|
|
End
|
|
End
|
|
|
|
+
|
|
|
|
+ 'copy contructor
|
|
|
|
+ Method New( component:Component,entity:Entity )
|
|
|
|
+
|
|
|
|
+ Self.New( entity )
|
|
|
|
+ End
|
|
|
|
|
|
Property Entity:Entity()
|
|
Property Entity:Entity()
|
|
|
|
|
|
@@ -32,11 +39,20 @@ Class Component
|
|
|
|
|
|
Protected
|
|
Protected
|
|
|
|
|
|
|
|
+ Method OnCopy( entity:Entity ) Virtual
|
|
|
|
+
|
|
|
|
+ End
|
|
|
|
+
|
|
Method SaveInitialState()
|
|
Method SaveInitialState()
|
|
|
|
|
|
If editing jsonifier.AddInstance( Self,New Variant[]( _entity ) )
|
|
If editing jsonifier.AddInstance( Self,New Variant[]( _entity ) )
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method SaveInitialState( component:Component )
|
|
|
|
+
|
|
|
|
+ If editing jsonifier.AddInstance( Self,New Variant[]( component,_entity ) )
|
|
|
|
+ End
|
|
|
|
+
|
|
Private
|
|
Private
|
|
|
|
|
|
Field _entity:Entity
|
|
Field _entity:Entity
|
|
@@ -45,13 +61,26 @@ End
|
|
|
|
|
|
Class Behaviour Extends Component
|
|
Class Behaviour Extends Component
|
|
|
|
|
|
|
|
+ 'simple contructor
|
|
Method New( entity:Entity )
|
|
Method New( entity:Entity )
|
|
|
|
|
|
Super.New( entity )
|
|
Super.New( entity )
|
|
|
|
+
|
|
|
|
+ Color=graphics.Color.White
|
|
|
|
|
|
SaveInitialState()
|
|
SaveInitialState()
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ 'copy constructor
|
|
|
|
+ Method New( behaviour:Behaviour,entity:Entity )
|
|
|
|
+
|
|
|
|
+ Super.New( entity )
|
|
|
|
+
|
|
|
|
+ Color=behaviour.Color
|
|
|
|
+
|
|
|
|
+ SaveInitialState( behaviour )
|
|
|
|
+ End
|
|
|
|
+
|
|
Property Color:Color()
|
|
Property Color:Color()
|
|
|
|
|
|
Return _color
|
|
Return _color
|
|
@@ -61,17 +90,32 @@ Class Behaviour Extends Component
|
|
_color=color
|
|
_color=color
|
|
End
|
|
End
|
|
|
|
|
|
- Private
|
|
|
|
|
|
+ Internal
|
|
|
|
+
|
|
|
|
+ Method OnCopy( entity:Entity ) Override
|
|
|
|
+
|
|
|
|
+ New Behaviour( Self,entity )
|
|
|
|
+ End
|
|
|
|
|
|
- Field _color:Color=graphics.Color.White
|
|
|
|
|
|
+ Private
|
|
|
|
|
|
|
|
+ Field _color:Color
|
|
End
|
|
End
|
|
|
|
|
|
Class Entity
|
|
Class Entity
|
|
|
|
|
|
|
|
+ 'simple ctor
|
|
Method New( parent:Entity )
|
|
Method New( parent:Entity )
|
|
|
|
|
|
_parent=parent
|
|
_parent=parent
|
|
|
|
+
|
|
|
|
+ If _parent _parent._children.Add( Self )
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ 'copy ctor
|
|
|
|
+ Method New( entity:Entity,parent:Entity )
|
|
|
|
+
|
|
|
|
+ Self.New( parent )
|
|
End
|
|
End
|
|
|
|
|
|
Property Visible:Bool()
|
|
Property Visible:Bool()
|
|
@@ -83,6 +127,15 @@ Class Entity
|
|
_visible=visible
|
|
_visible=visible
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method Copy:Entity( parent:Entity ) Virtual
|
|
|
|
+
|
|
|
|
+ Local copy:=OnCopy( parent )
|
|
|
|
+
|
|
|
|
+ CopyTo( copy )
|
|
|
|
+
|
|
|
|
+ Return copy
|
|
|
|
+ End
|
|
|
|
+
|
|
Method AddComponent<T>:T()
|
|
Method AddComponent<T>:T()
|
|
|
|
|
|
Local component:=New T( Self )
|
|
Local component:=New T( Self )
|
|
@@ -92,15 +145,40 @@ Class Entity
|
|
|
|
|
|
Protected
|
|
Protected
|
|
|
|
|
|
|
|
+ Method OnCopy:Entity( parent:Entity ) Virtual
|
|
|
|
+
|
|
|
|
+ Return New Entity( Self,parent )
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Method CopyTo( copy:Entity )
|
|
|
|
+
|
|
|
|
+ For Local child:=Eachin _children
|
|
|
|
+
|
|
|
|
+ child.CopyTo( child.OnCopy( copy ) )
|
|
|
|
+ Next
|
|
|
|
+
|
|
|
|
+ For Local c:=Eachin _components
|
|
|
|
+
|
|
|
|
+ c.OnCopy( copy )
|
|
|
|
+ Next
|
|
|
|
+ End
|
|
|
|
+
|
|
Method SaveInitialState()
|
|
Method SaveInitialState()
|
|
|
|
|
|
If editing jsonifier.AddInstance( Self,New Variant[]( _parent ) )
|
|
If editing jsonifier.AddInstance( Self,New Variant[]( _parent ) )
|
|
End
|
|
End
|
|
|
|
+
|
|
|
|
+ Method SaveInitialState( entity:Entity )
|
|
|
|
+
|
|
|
|
+ If editing jsonifier.AddInstance( Self,New Variant[]( entity,_parent ) )
|
|
|
|
+ End
|
|
|
|
|
|
Private
|
|
Private
|
|
|
|
|
|
Field _parent:Entity
|
|
Field _parent:Entity
|
|
|
|
|
|
|
|
+ Field _children:=New Stack<Entity>
|
|
|
|
+
|
|
Field _visible:Bool
|
|
Field _visible:Bool
|
|
|
|
|
|
Field _components:=New Stack<Component>
|
|
Field _components:=New Stack<Component>
|
|
@@ -118,11 +196,53 @@ Class Camera Extends Entity
|
|
|
|
|
|
Super.New( parent )
|
|
Super.New( parent )
|
|
|
|
|
|
|
|
+ FOV=90
|
|
|
|
+
|
|
SaveInitialState()
|
|
SaveInitialState()
|
|
|
|
|
|
Visible=True
|
|
Visible=True
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method New( camera:Camera,parent:Entity )
|
|
|
|
+
|
|
|
|
+ Super.New( camera,parent )
|
|
|
|
+
|
|
|
|
+ FOV=camera.FOV
|
|
|
|
+
|
|
|
|
+ SaveInitialState( camera )
|
|
|
|
+
|
|
|
|
+ Visible=True
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Property FOV:Float()
|
|
|
|
+
|
|
|
|
+ Return _fov
|
|
|
|
+
|
|
|
|
+ Setter( fov:Float )
|
|
|
|
+
|
|
|
|
+ _fov=fov
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Method Copy:Camera( parent:Entity ) Override
|
|
|
|
+
|
|
|
|
+ Local camera:=OnCopy( parent )
|
|
|
|
+
|
|
|
|
+ CopyTo( camera )
|
|
|
|
+
|
|
|
|
+ Return camera
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Protected
|
|
|
|
+
|
|
|
|
+ Method OnCopy:Camera( parent:Entity ) Override
|
|
|
|
+
|
|
|
|
+ Return New Camera( Self,parent )
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Private
|
|
|
|
+
|
|
|
|
+ Field _fov:Float
|
|
|
|
+
|
|
End
|
|
End
|
|
|
|
|
|
Class Light Extends Entity
|
|
Class Light Extends Entity
|
|
@@ -136,6 +256,31 @@ Class Light Extends Entity
|
|
Visible=True
|
|
Visible=True
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method New( light:Light,parent:Entity )
|
|
|
|
+
|
|
|
|
+ Super.New( parent )
|
|
|
|
+
|
|
|
|
+ SaveInitialState( light )
|
|
|
|
+
|
|
|
|
+ Visible=True
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Method Copy:Light( parent:Entity ) Override
|
|
|
|
+
|
|
|
|
+ Local light:=OnCopy( parent )
|
|
|
|
+
|
|
|
|
+ CopyTo( light )
|
|
|
|
+
|
|
|
|
+ Return light
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Protected
|
|
|
|
+
|
|
|
|
+ Method OnCopy:Light( parent:Entity ) Override
|
|
|
|
+
|
|
|
|
+ Return New Light( Self,parent )
|
|
|
|
+ End
|
|
|
|
+
|
|
End
|
|
End
|
|
|
|
|
|
Class Model Extends Entity
|
|
Class Model Extends Entity
|
|
@@ -144,22 +289,64 @@ Class Model Extends Entity
|
|
|
|
|
|
Super.New( parent )
|
|
Super.New( parent )
|
|
|
|
|
|
|
|
+ Mesh=""
|
|
|
|
+
|
|
SaveInitialState()
|
|
SaveInitialState()
|
|
|
|
|
|
Visible=True
|
|
Visible=True
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method New( model:Model,parent:Entity )
|
|
|
|
+
|
|
|
|
+ Super.New( parent )
|
|
|
|
+
|
|
|
|
+ Mesh=model.Mesh
|
|
|
|
+
|
|
|
|
+ SaveInitialState( model )
|
|
|
|
+
|
|
|
|
+ Visible=True
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Property Mesh:String()
|
|
|
|
+
|
|
|
|
+ Return _mesh
|
|
|
|
+
|
|
|
|
+ Setter( mesh:String )
|
|
|
|
+
|
|
|
|
+ _mesh=mesh
|
|
|
|
+ End
|
|
|
|
+
|
|
Function Load:Model( path:String,parent:Entity )
|
|
Function Load:Model( path:String,parent:Entity )
|
|
|
|
|
|
Local model:=New Model( parent,True )
|
|
Local model:=New Model( parent,True )
|
|
|
|
|
|
|
|
+ model.Mesh="<"+path+">"
|
|
|
|
+
|
|
If editing jsonifier.AddInstance( model,"Load",New Variant[]( path,parent ) )
|
|
If editing jsonifier.AddInstance( model,"Load",New Variant[]( path,parent ) )
|
|
|
|
|
|
Return model
|
|
Return model
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method Copy:Model( parent:Entity ) Override
|
|
|
|
+
|
|
|
|
+ Local model:=OnCopy( parent )
|
|
|
|
+
|
|
|
|
+ CopyTo( model )
|
|
|
|
+
|
|
|
|
+ Return model
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Protected
|
|
|
|
+
|
|
|
|
+ Method OnCopy:Model( parent:Entity ) Override
|
|
|
|
+
|
|
|
|
+ Return New Model( Self,parent )
|
|
|
|
+ End
|
|
|
|
+
|
|
Private
|
|
Private
|
|
|
|
|
|
|
|
+ Field _mesh:String
|
|
|
|
+
|
|
Method New( parent:Entity,loading:Bool )
|
|
Method New( parent:Entity,loading:Bool )
|
|
|
|
|
|
Super.New( parent )
|
|
Super.New( parent )
|
|
@@ -173,6 +360,20 @@ Function CreateScene()
|
|
|
|
|
|
jsonifier=New Jsonifier
|
|
jsonifier=New Jsonifier
|
|
|
|
|
|
|
|
+ Local model1:=Model.Load( "model1.png",Null )
|
|
|
|
+
|
|
|
|
+ Local behavour1:=New Behaviour( model1 )
|
|
|
|
+
|
|
|
|
+ Local model2:=model1.Copy( Null )
|
|
|
|
+
|
|
|
|
+End
|
|
|
|
+
|
|
|
|
+Function CreateScene2()
|
|
|
|
+
|
|
|
|
+ Print "CreateScene"
|
|
|
|
+
|
|
|
|
+ jsonifier=New Jsonifier
|
|
|
|
+
|
|
Local camera:=New Camera( Null )
|
|
Local camera:=New Camera( Null )
|
|
|
|
|
|
Local light:=New Light( Null )
|
|
Local light:=New Light( Null )
|
|
@@ -186,6 +387,8 @@ Function CreateScene()
|
|
Local component:=New Behaviour( model )
|
|
Local component:=New Behaviour( model )
|
|
Next
|
|
Next
|
|
|
|
|
|
|
|
+ Local copy:=root.Copy( Null )
|
|
|
|
+
|
|
End
|
|
End
|
|
|
|
|
|
Function SaveScene:JsonObject()
|
|
Function SaveScene:JsonObject()
|