using System; using System.IO; using System.Collections.Generic; using System.Diagnostics; using Johnmagotchi.Core.tools; using System.Collections; using System.Net.Http.Headers; using static Johnmagotchi.GameContent.Objects.Units.Stats.UnitStatBlock; using Johnmagotchi.GameContent.Objects.Units.Stats.Loadouts.PlayerClasses; namespace Johnmagotchi.GameContent.Objects.Units { public class UnitLoader { public static List GetTest() { // MAC OS also prly Linux - var path = Path.Combine(Directory.GetCurrentDirectory(), "GameContent/Objects/Units/UnitDefines.csv"); //System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory()); //var path = "..\\..\\..\\GameContent\\Objects\\Units\\UnitDefines.csv"; List listA = new List(); return listA; } //public static List LoadBaseUnits() { // List unitList = new List(); // System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory()); // var path = "..\\..\\..\\Data\\BattleObjects\\UnitDefinitions.csv"; // List listA = new List(); // List listB = new List(); // System.Console.WriteLine("path: {0} ", path); // // these let us resolve which column is which // int IdIndex = -1; // int NameIndex = -1; // int ClassIndex = -1; // int isUniqueIndex = -1; // int HealthIndex = -1; // int AttackIndex = -1; // int DefenseIndex = -1; // int SpeedIndex = -1; // int MovementIndex = -1; // int MovementTypeIndex = -1; // bool AreColumnIndexesSet = false; // using (var reader = new StreamReader(path)) // { // while (!reader.EndOfStream) // { // var line = reader.ReadLine(); // var values = line.Split(','); // if (AreColumnIndexesSet == false) // { // //These strings MUST match /GameContent/Data/UnitDefines.CSV // // That file MUST have these in the first row. // for (int i = 0; i < values.Length; i++) { // if (values[i].Trim() == "ID") { IdIndex = i; } // if (values[i].Trim() == "NAME") { NameIndex = i; } // if (values[i].Trim() == "CLASS") { ClassIndex = i; } // if (values[i].Trim() == "IS_UNIQUE") { isUniqueIndex = i; } // if (values[i].Trim() == "HEALTH") { HealthIndex = i; } // if (values[i].Trim() == "ATTACK") { AttackIndex = i; } // if (values[i].Trim() == "DEFENSE") { DefenseIndex = i; } // if (values[i].Trim() == "SPEED") { SpeedIndex = i; } // if (values[i].Trim() == "MOVEMENT") { MovementIndex = i; } // if (values[i].Trim() == "MOVEMENT_TYPE") { MovementTypeIndex = i; } // } // AreColumnIndexesSet = true; // } // else { // UnitObject unit = new UnitObject(); // unit.id = Int32.Parse(values[IdIndex]); // unit.name = unit.stats = values[NameIndex]; // unit.playerClassEnum = PlayerClass.GetClassFromShortHand(values[ClassIndex]); // unit.isUnique = (values[isUniqueIndex].ToLower() == "true"); // unit.stats.MaxHealth = Int32.Parse(values[HealthIndex]); // unit.stats.Attack = Int32.Parse(values[AttackIndex]); // unit.stats.Defense = Int32.Parse(values[DefenseIndex]); // unit.stats.Speed = Int32.Parse(values[SpeedIndex]); // unit.stats.Movement = Int32.Parse(values[MovementIndex]); // unit.stats.setMovementTypeFromFile(values[MovementTypeIndex]); // unitList.Add(unit); // } // } // } // return unitList; //} public static List LoadUnitList () { List unitList = new List(); Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory()); var path = "..\\..\\..\\Data\\BattleObjects\\UnitDefinitions.csv"; Console.WriteLine("path: {0} ", path); // these let us resolve which column is which int IdIndex = -1; int NameIndex = -1; int ClassIndex = -1; int isUniqueIndex = -1; int HealthIndex = -1; int AttackIndex = -1; int DefenseIndex = -1; int SpeedIndex = -1; int MovementIndex = -1; int MovementTypeIndex = -1; bool AreColumnIndexesSet = false; using (var reader = new StreamReader(path)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); if (AreColumnIndexesSet == false) { //These strings MUST match /GameContent/Data/UnitDefines.CSV // That file MUST have these in the first row. for (int i = 0; i < values.Length; i++) { if (values[i].Trim() == "ID") { IdIndex = i; } if (values[i].Trim() == "NAME") { NameIndex = i; } if (values[i].Trim() == "CLASS") { ClassIndex = i; } if (values[i].Trim() == "IS_UNIQUE") { isUniqueIndex = i; } if (values[i].Trim() == "HEALTH") { HealthIndex = i; } if (values[i].Trim() == "ATTACK") { AttackIndex = i; } if (values[i].Trim() == "DEFENSE") { DefenseIndex = i; } if (values[i].Trim() == "SPEED") { SpeedIndex = i; } if (values[i].Trim() == "MOVEMENT") { MovementIndex = i; } if (values[i].Trim() == "MOVEMENT_TYPE") { MovementTypeIndex = i; } } AreColumnIndexesSet = true; } else { Unit unit = new Unit(); unit.UnitID = int.Parse(values[IdIndex]); unit.stats.classId = PlayerClass.GetClassFromShortHand(values[ClassIndex]); // unit.isUnique = (values[isUniqueIndex].ToLower() == "true"); unit.name = unit.stats.Name = values[NameIndex]; unit.stats.baseStats.MaxHealth = int.Parse(values[HealthIndex]); unit.stats.baseStats.Attack = int.Parse(values[AttackIndex]); unit.stats.baseStats.Defense = int.Parse(values[DefenseIndex]); unit.stats.baseStats.Speed = int.Parse(values[SpeedIndex]); unit.stats.baseStats.Movement = int.Parse(values[MovementIndex]); unit.stats.baseStats.setMovementTypeFromFile(values[MovementTypeIndex]); unitList.Add(unit); } } } return unitList; } } }