170 lines
7.6 KiB
C#
170 lines
7.6 KiB
C#
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.BattleObjects.UnitStatBlock;
|
|
using Johnmagotchi.GameContent.Objects.Units.Loadouts.PlayerClasses;
|
|
using Johnmagotchi.GameContent.Objects.Units;
|
|
|
|
namespace Johnmagotchi.GameContent.Units
|
|
{
|
|
public class UnitLoader
|
|
{
|
|
public static List<string> 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<string> listA = new List<string>();
|
|
|
|
return listA;
|
|
}
|
|
//public static List<UnitObject> LoadBaseUnits() {
|
|
// List<UnitObject> unitList = new List<UnitObject>();
|
|
// System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
|
|
// var path = "..\\..\\..\\Data\\BattleObjects\\UnitDefinitions.csv";
|
|
// List<string> listA = new List<string>();
|
|
// List<string> listB = new List<string>();
|
|
// 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 <Unit> LoadUnitList ()
|
|
{
|
|
List<Unit> unitList = new List<Unit>();
|
|
|
|
|
|
System.Console.WriteLine("PATH: {0}", Directory.GetCurrentDirectory());
|
|
var path = "..\\..\\..\\Data\\BattleObjects\\UnitDefinitions.csv";
|
|
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
|
|
{
|
|
Unit unit = new Unit();
|
|
unit.UnitID = Int32.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 = Int32.Parse(values[HealthIndex]);
|
|
unit.stats.baseStats.Attack = Int32.Parse(values[AttackIndex]);
|
|
unit.stats.baseStats.Defense = Int32.Parse(values[DefenseIndex]);
|
|
unit.stats.baseStats.Speed = Int32.Parse(values[SpeedIndex]);
|
|
unit.stats.baseStats.Movement = Int32.Parse(values[MovementIndex]);
|
|
unit.stats.baseStats.setMovementTypeFromFile(values[MovementTypeIndex]);
|
|
|
|
unitList.Add(unit);
|
|
}
|
|
}
|
|
}
|
|
|
|
return unitList;
|
|
}
|
|
}
|
|
} |