// This does none of the loading; it just lists all the loadable files and prompts the user to pick one. It then redirects to the function below. public static bool LoadFromFile() { string fileMouth; if (!TryGetMapsFolder(out fileMouth)) { return(false); } DirectoryInfo directory = new DirectoryInfo(fileMouth); Dictionary <string, FileInfo> files = new Dictionary <string, FileInfo>(); foreach (FileInfo file in directory.GetFiles("*.xml")) { files.Add(file.Name, file); } if (files.Count == 0) { Output.WriteLineTagged("It appears there are no files to load. Either download a world file, or try designing one in the level editor", Output.Tag.Error); return(false); } string[] fileNames = files.Keys.ToArray(); Output.WriteLineTagged("Choose a file from the options below.", Output.Tag.Prompt); if (CommandInterpretation.InterpretString(fileNames, out string result)) { Game.FilePath = files[result].FullName; LoadFromFile(files[result].FullName); } else { if (CommandInterpretation.AskYesNo("No file found with that name. Would you like to try again?")) { return(LoadFromFile()); } return(false); } return(true); }
// Used in InterpretTile() and other cases. Prompts user for all aspects of Contents public static bool InterpretContents(out Contents result) { Output.WriteLineToConsole("\nContents"); result = null; int uniqueID = Contents.UniqueID(); Dictionary <string, string> preContainerParamMap = new Dictionary <string, string>() { { "Name", GetUserResponse("Name (unique identifier)<string>:") }, { "VisualChar", GetUserResponse("Visual character (to represent on the grid)<character>:") }, { "Transparent", GetUserResponse("Would you like this tile to be transparent? (visible and targetable through)<boolean>:") }, { "Durability", GetUserResponse("Durability (health points)<integer>:") }, { "Size", GetUserResponse("Size (space it takes up in containers)<integer>:") }, { "Weight", GetUserResponse("Weight (Depending on player strength, they may or may not be able to pick this up)<float>:\nCurrent player strength is " + World.Player.Strength) }, { "Action", string.Empty }, { "Behavior", string.Empty }, { "Tags", string.Empty } }; Output.WriteLineTagged("Choose an action that this contents takes", Output.Tag.Prompt); if (!CommandInterpretation.InterpretString(UseActions.GetIdentifiers(), out string actionString)) { Output.WriteLineTagged("Action was not a valid response", Output.Tag.Error); return(false); } preContainerParamMap["Action"] = actionString; if (preContainerParamMap["Action"] == "Dialogue") { string dialogue = CommandInterpretation.GetUserResponse("Please enter the line of dialogue for this contents"); World.Dialogue.Add(uniqueID, dialogue); } Output.WriteLineTagged("Choose a behavior for this contents", Output.Tag.Prompt); do { if (!CommandInterpretation.InterpretString(Behavior.GetIdentifiers(), out string behaviorString)) { Output.WriteLineTagged("Behavior was not a valid response", Output.Tag.Error); return(false); } preContainerParamMap["Behavior"] += behaviorString + ","; } while (CommandInterpretation.AskYesNo("Would you like to add any more behavior?")); string tempBehavior = preContainerParamMap["Behavior"]; tempBehavior = tempBehavior.Substring(0, tempBehavior.Length - 1); #region Checking params if (!InterpretInt(preContainerParamMap["Durability"], out int durability)) { Output.WriteLineTagged("Durability was not in integer format", Output.Tag.Error); return(false); } if (!InterpretInt(preContainerParamMap["Size"], out int size)) { Output.WriteLineTagged("Size was not in integer format", Output.Tag.Error); return(false); } if (!InterpretFloat(preContainerParamMap["Weight"], out float weight)) { Output.WriteLineTagged("Weight was not in float format", Output.Tag.Error); return(false); } if (!UseActions.TryGetAction(preContainerParamMap["Action"], out Action <string[], Contents> action)) { Output.WriteLineTagged("Action was not found", Output.Tag.Error); return(false); } if (!Behavior.TryGetBehaviors(tempBehavior.Split(","), out Action <Contents>[] behavior))