Jypeli  5
The simple game programming library
LevelObject.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 
6 namespace Jypeli.LevelEditor
7 {
8  [Save]
9  public class LevelObject
10  {
11  [Save] internal int TemplateIndex;
12  [Save] public PropertySet OverridingProperties { get; private set; }
13 
14  private LevelData levelData;
15 
16  public Template Template
17  {
18  get { return levelData.Templates[TemplateIndex]; }
19  }
20 
21  public LevelObject( LevelData levelData, int templateIndex )
22  {
23  this.levelData = levelData;
24  this.TemplateIndex = templateIndex;
25  this.OverridingProperties = new PropertySet();
26  }
27 
28  public T GetPropertyValue<T>( string propName )
29  {
30  try
31  {
32  return (T)OverridingProperties.GetValue( propName );
33  }
34  catch ( KeyNotFoundException )
35  {
36  return (T)Template.Properties.GetValue( propName );
37  }
38  }
39 
40  public T GetPropertyValue<T>( string propName, T defaultValue )
41  {
42  try
43  {
44  return GetPropertyValue<T>( propName );
45  }
46  catch ( KeyNotFoundException )
47  {
48  return defaultValue;
49  }
50  }
51 
53  {
54  //GameObject obj = new GameObject( 10, 10 );
55  Type type = GetPropertyValue<Type>( "Type" );
56  object[] args = { 10, 10 };
57  GameObject obj = (GameObject)Activator.CreateInstance( type, args );
58  Template.Properties.Apply( ref obj );
59  OverridingProperties.Apply( ref obj );
60  return (GameObject)obj;
61  }
62 
63  public void ResetTemplate()
64  {
65  TemplateIndex = 0;
66  }
67  }
68 }
object GetValue(string propName)
Definition: PropertySet.cs:60
List< Template > Templates
Definition: LevelData.cs:11
void Apply(ref GameObject obj)
Definition: PropertySet.cs:98
LevelObject(LevelData levelData, int templateIndex)
Definition: LevelObject.cs:21
Pelialueella liikkuva olio. Käytä fysiikkapeleissä PhysicsObject-olioita.
Definition: __GameObject.cs:54