protected override void LoadContent() { base.LoadContent(); _ogmoProject = Content.Load <OgmoProject>(@"ogmo\testproject"); _level = _ogmoProject.GetLevel("testlevel"); }
/// <summary> /// Loads all levels for the game and project data. /// </summary> /// <returns>The generated starting scene.</returns> public Node2D Load(out Node2D player, out Vector2 levelBoundsX, out Vector2 levelBoundsY) { string pathToProjectFile = "res://ogmo/project.ogmo"; string pathToLevelsDir = "res://ogmo/levels"; project = JsonConvert.DeserializeObject <OgmoProject>(ObtainFileString(pathToProjectFile)); Levels = new Dictionary <string, OgmoLevel>(); var levelDir = new Directory(); levelDir.Open(pathToLevelsDir); levelDir.ListDirBegin(true, true); string levelPath; OgmoLevel startLevel = null; while ((levelPath = levelDir.GetNext()) != string.Empty) { if (!levelPath.EndsWith(".json")) { continue; } Levels.Add(levelPath.Replace(".json", string.Empty), JsonConvert.DeserializeObject <OgmoLevel>(ObtainFileString(pathToLevelsDir + "/" + levelPath))); if (levelPath.StartsWith("start", StringComparison.InvariantCultureIgnoreCase)) { startLevel = Levels.Last().Value; } } levelBoundsX = new Vector2(0, startLevel.width); levelBoundsY = new Vector2(0, startLevel.height); return(GenerateScene(project, startLevel, out player)); }
static void Main(string[] args) { // Create a new Game. var game = new Game("Ogmo Editor Example"); // Set the background color to see stuff a little better. game.Color = Color.Cyan; // Create a new Scene to use for the Ogmo data. var scene = new Scene(); // The path to the level to be loaded. var pathLevel = "Level.oel"; // The path to the Ogmo Project to use when loading the level. var pathProject = "OgmoProject.oep"; // Create a new OgmoProject using the .oep file. var OgmoProject = new OgmoProject(pathProject); // Ensure that the grid layer named "Solids" gets the Solid collision tag when loading. OgmoProject.RegisterTag(Tags.Solid, "Solids"); // Load the level into the Scene. OgmoProject.LoadLevelFromFile(pathLevel, scene); // Start the game using the Scene with the loaded Ogmo Level. game.Start(scene); }
public PlatformerScene() : base() { // Create the Ogmo Editor project. var ogmoProject = new OgmoProject("OgmoProject.oep"); // Register the "Solid" layer with the tag Solid. ogmoProject.RegisterTag(CollisionTag.Solid, "Solid"); // Set the game's color to the Ogmo Project's background color. Game.Instance.Color = ogmoProject.BackgroundColor; // Load the level. ogmoProject.LoadLevel("Level.oel", this); }
public TestingMode() { //tank entity creation was moved to ogmo; see testlevel.oep for adding a decorator to your tank. //try to load a project OgmoProject proj = new OgmoProject("Resources/Maps/test.oep", "Resources/Maps/"); //register our function to call for creating entities //this just is a string with the method name, the method itself has to be in the entities (see tank) proj.CreationMethodName = _creationMethodName; //uuh this somehow "registers a collision tag" proj.RegisterTag(CollidableTags.Wall, "CollisionLayer"); //try to load a level into "Scene" proj.LoadLevel("Resources/Maps/collisionTestBench.oel", Scene); }
private void LoadMap(Maps map) { //tank entity creation was moved to ogmo; see testlevel.oep for adding a decorator to your tank. //try to load a project OgmoProject proj = new OgmoProject("Resources/Maps/test.oep", "Resources/Maps/"); //register our function to call for creating entities //this just is a string with the method name, the method itself has to be in the entities (see tank) proj.CreationMethodName = _creationMethodName; //uuh this somehow "registers a collision tag" proj.RegisterTag(CollidableTags.Wall, "CollisionLayer"); //try to load a level into "Scene"; map gets auto-ToString() to enum position name proj.LoadLevel("Resources/Maps/" + map + ".oel", Scene); }
private void LoadMap(Maps map) { //tank entity creation was moved to ogmo; see testlevel.oep for adding a decorator to your tank. //try to load a project, second path is image path. it goes into maps because ogmo instructs to go up a level, so we end up in resources OgmoProject proj = new OgmoProject("Resources/Maps/test.oep", "Resources/Maps/"); //register our function to call for creating entities //this just is a string with the method name, the method itself has to be in the entities (see tank) proj.CreationMethodName = _creationMethodName; //uuh this somehow "registers a collision tag" proj.RegisterTag(CollidableTags.Wall, "CollisionLayer"); //try to load a level into "Scene" proj.LoadLevel("Resources/Maps/" + map + ".oel", Scene); }
private Node2D GenerateScene(OgmoProject project, OgmoLevel level, out Node2D player) { nodes = new List <Node2D>(); player = null; var tileMap = (TileMap)((PackedScene)ResourceLoader.Load("res://prefab/TileMap.tscn")).Instance(); tileMap.Name = "TileMap"; Node2D ultimateParent = new Node2D(); ultimateParent.Name = "Level"; ultimateParent.AddChild(tileMap); //Load set tiles in var tileData = level.layers.First(x => x.name == "Tiles").data2D; for (int y = 0; y < tileData.Count; y++) { for (int x = 0; x < tileData[y].Count; x++) { tileMap.SetCell(x, y, tileData[y][x]); if (y == 0) { tileMap.SetCell(x, -1, 0); } if (x == 0) { tileMap.SetCell(-1, y, 0); } if (x == tileData.Count - 1) { tileMap.SetCell(tileData.Count, y, 0); } if (y == tileData[y].Count - 1) { tileMap.SetCell(x, tileData[y].Count, 0); } } } var playerScene = (PackedScene)ResourceLoader.Load("res://prefab/PlayerOwl.tscn"); var bugScene = ((PackedScene)ResourceLoader.Load("res://prefab/Enemies/Bug.tscn")); var beeScene = ((PackedScene)ResourceLoader.Load("res://prefab/Enemies/Beee.tscn")); var carnosaurScene = ((PackedScene)ResourceLoader.Load("res://prefab/Enemies/Carnosaur.tscn")); var carnosaurusRexScene = ((PackedScene)ResourceLoader.Load("res://prefab/Enemies/CarnosaurusRex.tscn")); var playerEntity = level.layers.First(x => x.name == "Entity").entities.First(x => x.name == "LevelSpawn"); player = (Node2D)playerScene.Instance(); player.Name = "Player_" + playerEntity._eid; player.Position = new Vector2(playerEntity.x, playerEntity.y); foreach (var entity in level.layers.First(x => x.name == "Entity").entities) { Node2D childInstance = null; switch (entity.name) { case "Walker": childInstance = (Node2D)bugScene.Instance(); childInstance.Name = "Walker_" + entity._eid; break; case "TargetFlyer": childInstance = (Node2D)carnosaurScene.Instance(); childInstance.Name = "Flyer_" + entity._eid; break; case "Bee": childInstance = (Node2D)beeScene.Instance(); childInstance.Name = "Bee_" + entity._eid; break; case "Boss": childInstance = (Node2D)carnosaurusRexScene.Instance(); childInstance.Name = "Boss_" + entity._eid; break; } if (childInstance != null) { childInstance.AddToGroup("enemy", true); nodes.Add(childInstance); ultimateParent.AddChild(childInstance); childInstance.Position = new Vector2(entity.x, entity.y); } } return(ultimateParent); }
public override OgmoEntity ReadJson(JsonReader reader, Type objectType, OgmoEntity existingValue, bool hasExistingValue, JsonSerializer serializer) { JObject obj = JObject.Load(reader); OgmoProject project = serializer.Context.Context as OgmoProject; OgmoValueDefinition[] defs = null; var ent = new OgmoEntity(); ent.Target = (string)obj["name"]; for (int i = 0; i < project.EntityDefinitions.Length; i++) { if (project.EntityDefinitions[i].Name == ent.Target) { defs = project.EntityDefinitions[i].ValueDefinitions; break; } } ent.ExportID = (string)obj["_eid"]; ent.WorldID = (int)obj["id"]; ent.Position = new Point((int)obj["x"], (int)obj["y"]); ent.Origin = new Point((int)obj["originX"], (int)obj["originY"]); var valArray = obj["values"] as JObject; ent.Values = new Dictionary <string, OgmoValue>(); if (defs == null || valArray == null) { if (defs == null) { Debug.Warn($"Definition member was not found for type {ent.Target}"); } return(ent); } foreach (var pair in valArray) { for (int x = 0; x < defs.Length; x++) { if (defs[x].Name == pair.Key) { var definition = defs[x]; switch (definition) { case OgmoColorValueDefinition color: var colorVal = new OgmoColorValue(); colorVal.Name = pair.Key; colorVal.Definition = color; colorVal.Value = ColorExt.HexToColor((string)pair.Value); ent.Values.Add(pair.Key, colorVal); break; case OgmoStringValueDefinition str: var stringVal = new OgmoStringValue(); stringVal.Name = pair.Key; stringVal.Definition = str; stringVal.Value = (string)pair.Value; ent.Values.Add(pair.Key, stringVal); break; case OgmoEnumValueDefinition enu: var enumVal = new OgmoEnumValue(); enumVal.Name = pair.Key; enumVal.Definition = enu; enumVal.Value = (int)pair.Value; ent.Values.Add(pair.Key, enumVal); break; case OgmoFloatValueDefinition flo: var floatVal = new OgmoFloatValue(); floatVal.Name = pair.Key; floatVal.Definition = flo; floatVal.Value = (float)pair.Value; ent.Values.Add(pair.Key, floatVal); break; case OgmoTextValueDefinition text: var textValue = new OgmoTextValue(); textValue.Name = pair.Key; textValue.Definition = text; textValue.Value = (string)pair.Value; ent.Values.Add(pair.Key, textValue); break; } } } } return(ent); }
public override OgmoLayer ReadJson(JsonReader reader, Type objectType, OgmoLayer existingValue, bool hasExistingValue, JsonSerializer serializer) { JObject obj = JObject.Load(reader); OgmoProject project = serializer.Context.Context as OgmoProject; OgmoLayerDefinition[] context = project.LayerDefinitions; if (context == null) { throw new Exception("You must pass the OgmoProject as a serializer context to deserialize this type."); } var eid = (string)obj["_eid"]; for (int i = 0; i < context.Length; i++) { if (context[i] == null) // Grid layers arent implemented, nor will they. { continue; } if (eid == context[i].ExportID) { // Found the matching definition. var def = context[i]; switch (def) { case OgmoTileLayerDefinition tile: OgmoTileLayer tileLayer = new OgmoTileLayer(); tileLayer.Target = tile; tileLayer.TileSet = (string)obj["tileset"]; tileLayer.ExportID = eid; // Todo: read the data array mode and map it to a 1d array always. var dat = obj["data"].Children().ToArray(); tileLayer.Data = new int[dat.Length]; for (int j = 0; j < dat.Length; j++) { tileLayer.Data[j] = (int)dat[j]; } tileLayer.CellSize = new Point((int)obj["gridCellWidth"], (int)obj["gridCellHeight"]); tileLayer.CellCount = new Point((int)obj["gridCellsX"], (int)obj["gridCellsY"]); return(tileLayer); case OgmoEntityLayerDefinition entity: OgmoEntityLayer entityLayer = new OgmoEntityLayer(); entityLayer.ExportID = eid; entityLayer.Target = entity; var valuelist = obj["entities"].Children().ToArray(); entityLayer.Entities = new OgmoEntity[valuelist.Length]; for (int x = 0; x < valuelist.Length; x++) { OgmoEntity ov = new OgmoEntity(); OgmoEntity result = (OgmoEntity)OgmoEntityConverter.Instance.ReadJson(valuelist[x].CreateReader(), typeof(OgmoEntity), ov, serializer); entityLayer.Entities[x] = result; } return(entityLayer); } } } return(null); }
public override OgmoLevel ReadJson(JsonReader reader, Type objectType, OgmoLevel existingValue, bool hasExistingValue, JsonSerializer serializer) { JObject obj = JObject.Load(reader); OgmoProject project = serializer.Context.Context as OgmoProject; OgmoValueDefinition[] defs = project.LevelValueDefinitions; OgmoLevel level = new OgmoLevel(); level.LevelSize = new Point((int)obj["width"], (int)obj["height"]); level.OgmoVersion = (string)obj["ogmoVersion"]; // Layers. var layerList = obj["layers"].Children().ToArray(); level.Layers = new OgmoLayer[layerList.Length]; for (int x = 0; x < layerList.Length; x++) { OgmoLayer result = (OgmoLayer)OgmoLayerConverter.Instance.ReadJson(layerList[x].CreateReader(), typeof(OgmoLayer), null, serializer); level.Layers[x] = result; } // Values. var valArray = obj["values"] as JObject; level.Values = new Dictionary <string, OgmoValue>(); if (valArray == null) { return(level); } foreach (var pair in valArray) { for (int x = 0; x < defs.Length; x++) { if (defs[x].Name == pair.Key) { var definition = defs[x]; switch (definition) { case OgmoColorValueDefinition color: var colorVal = new OgmoColorValue(); colorVal.Name = pair.Key; colorVal.Definition = color; colorVal.Value = ColorExt.HexToColor((string)pair.Value); level.Values.Add(pair.Key, colorVal); break; case OgmoStringValueDefinition str: var stringVal = new OgmoStringValue(); stringVal.Name = pair.Key; stringVal.Definition = str; stringVal.Value = (string)pair.Value; level.Values.Add(pair.Key, stringVal); break; case OgmoEnumValueDefinition enu: var enumVal = new OgmoEnumValue(); enumVal.Name = pair.Key; enumVal.Definition = enu; var enumstring = (string)pair.Value; enumVal.Value = Array.IndexOf(enu.Choices, enumstring); level.Values.Add(pair.Key, enumVal); break; case OgmoFloatValueDefinition flo: var floatVal = new OgmoFloatValue(); floatVal.Name = pair.Key; floatVal.Definition = flo; floatVal.Value = (float)pair.Value; level.Values.Add(pair.Key, floatVal); break; case OgmoTextValueDefinition text: var textValue = new OgmoTextValue(); textValue.Name = pair.Key; textValue.Definition = text; textValue.Value = (string)pair.Value; level.Values.Add(pair.Key, textValue); break; } } } } return(level); }