private static void LoadStatsFromFile(string filepath) { StreamReader file = new StreamReader(filepath); char[] delim = { ' ', ',' }; while (!file.EndOfStream) { string line = file.ReadLine(); string [] values = line.Split(delim, StringSplitOptions.RemoveEmptyEntries); if (values.Length == 0 || values[0] == "#") { continue; } WeaponType WeaponType = EnumUtil.FromString <WeaponType>(values[0]); int statIndex = 1; foreach (WeaponStat s in EnumUtil.GetValues <WeaponStat>()) { mWeaponStats [(int)WeaponType, (int)s] = float.Parse(values [statIndex]); statIndex++; } } file.Close(); }
private static void LoadLevelsFromFile(string filepath) { StreamReader file = new StreamReader(filepath); char[] delim = { ' ', ',' }; while (!file.EndOfStream) { string line = file.ReadLine(); string [] values = line.Split(delim, StringSplitOptions.RemoveEmptyEntries); if (values.Length == 0 || values[0] == "#") // Ignore comments and blank lines { continue; } // FileFormat: "<UnitType> <Era> <Level> <Experience>" UnitType unitType = EnumUtil.FromString <UnitType>(values[0]); Era era = EnumUtil.FromString <Era>(values[1]); mUnitLevels[(int)unitType, (int)era] = int.Parse(values[2]); mUnitExperience[(int)unitType, (int)era] = int.Parse(values[3]); } file.Close(); }
private static void LoadStatsFromFile(string filepath) { StreamReader file = new StreamReader(filepath); char[] delim = { ' ', ',' }; while (!file.EndOfStream) { string line = file.ReadLine(); string [] values = line.Split(delim, StringSplitOptions.RemoveEmptyEntries); if (values[0] == "#") { continue; } UnitType unitType = EnumUtil.FromString <UnitType>(values[0]); int statIndex = 1; foreach (UnitStat s in EnumUtil.GetValues <UnitStat>()) { if (s == UnitStat.Level || s == UnitStat.Experience) { continue; } mUnitStats [(int)unitType, (int)s] = float.Parse(values [statIndex]); statIndex++; } } file.Close(); }
// See src/dialogue_1.txt for formatting the file private void LoadDialogueFromFile(string filepath) { StreamReader file = new StreamReader(filepath); char[] delim = { ' ', ',' }; while (!file.EndOfStream) { string line = file.ReadLine(); //string [] values = line.Split (delim, StringSplitOptions.RemoveEmptyEntries); string [] values = line.Split(delim, 5, StringSplitOptions.RemoveEmptyEntries); if (values.Length == 0 || values[0] == "#") // ignore blank lines and comments { continue; } if (values[0].Contains(">>>")) // start trigger { string trigger = values[1]; DialogueType type = EnumUtil.FromString <DialogueType>(values[2]); Dialogue dialogue = GetMessagesFromFile(file); mTriggers[type].Add(trigger, dialogue); } } file.Close(); }
private Dialogue GetMessagesFromFile(StreamReader file) { Dialogue dialogue = new Dialogue(); char[] delim = { ' ', ',' }; while (true) { string line = file.ReadLine(); string [] values = line.Split(delim, 6, StringSplitOptions.RemoveEmptyEntries); if (values[0].Contains("<<<")) // end trigger { break; } // read the message float duration = float.Parse(values[0]); SpeakerState state = EnumUtil.FromString <SpeakerState>(values[1]); string speaker = values[2]; SpeakerLocation location = EnumUtil.FromString <SpeakerLocation>(values[3]); // ignore the literal "---" string message = values[5]; dialogue.AddMessage(duration, state, speaker, location, message); } return(dialogue); }
// Format: <Spawn Time> <Size> <Preset> <Action Type> <Waypoint>,<Waypoint>,... // "2.5 Large Default AttackMove ArcherTower,SwordsmanTower" // "1 Individual Elite ForcedMove AbilityTower" private void AddSquad(string input) { float spawnTime; Vector3 spawnLocation; char[] delimiters = { ' ', ',' }; string[] param = input.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); spawnTime = float.Parse(param [0]); SquadSize size = EnumUtil.FromString <SquadSize> (param [1]); Waypoint wp = EnumUtil.FromString <Waypoint> (param [4]); spawnLocation = Waypoints[wp]; SquadLeaderType preset = EnumUtil.FromString <SquadLeaderType> (param [2]); //SquadBehavior behavior = EnumHelper.FromString<SquadBehavior> (param [3]); EnemySquad es = new EnemySquad((int)size, spawnTime, spawnLocation, UnitType.Peasant, preset); for (int i = 5; i < param.Length; ++i) { wp = EnumUtil.FromString <Waypoint> (param [i]); es.AddWaypoint(Waypoints [wp]); } es.AddWaypoint(Waypoints [Waypoint.King]); units.Add(es); }