/// <summary> /// Initializes a new instance of the <see cref="Character"/> class. /// </summary> /// <param name="in_bounds"> /// The bounds within which the <see cref="Character"/>'s <see cref="GameObjectID"/> is defined. /// Must be one of <see cref="All.BeingIDs"/>. /// </param> /// <param name="in_id">Unique identifier for the <see cref="Character"/>. Cannot be null.</param> /// <param name="in_description">Player-friendly description of the <see cref="Character"/>.</param> /// <param name="in_comment">Comment of, on, or by the <see cref="Character"/>.</param> /// <param name="in_personalName">Personal name of the <see cref="Character"/>. Cannot be null or empty.</param> /// <param name="in_familyName">Family name of the <see cref="Character"/>. Cannot be null or empty.</param> /// <param name="in_primaryBehavior">The rules that govern how this <see cref="Character"/> acts. Cannot be null.</param> /// <param name="in_avoids">Any parquets this <see cref="Character"/> avoids.</param> /// <param name="in_seeks">Any parquets this <see cref="Character"/> seeks.</param> /// <param name="in_pronoun">How to refer to this <see cref="Character"/>.</param> /// <param name="in_storyCharacterID">A means of identifying this <see cref="Character"/> across multiple shipped game titles.</param> /// <param name="in_startingQuests">Any quests this <see cref="Character"/> has to offer or has undertaken.</param> /// <param name="in_dialogue">All dialogue this <see cref="Character"/> may say.</param> /// <param name="in_startingInventory">Any items this <see cref="Character"/> owns at the outset.</param> protected Character(Range <GameObjectID> in_bounds, GameObjectID in_id, string in_personalName, string in_familyName, string in_description, string in_comment, GameObjectID in_nativeBiome, Behavior in_primaryBehavior, List <GameObjectID> in_avoids = null, List <GameObjectID> in_seeks = null, string in_pronoun = DefaultPronoun, string in_storyCharacterID = "", List <GameObjectID> in_startingQuests = null, List <string> in_dialogue = null, List <GameObjectID> in_startingInventory = null) : base(in_bounds, in_id, $"{in_personalName} {in_familyName}", in_description, in_comment, in_nativeBiome, in_primaryBehavior, in_avoids, in_seeks) { var nonNullPronoun = string.IsNullOrEmpty(in_pronoun) ? DefaultPronoun : in_pronoun; var nonNullQuests = in_startingQuests ?? Enumerable.Empty <GameObjectID>(); var nonNullInventory = in_startingInventory ?? Enumerable.Empty <GameObjectID>(); Precondition.AreInRange(nonNullQuests, All.QuestIDs, nameof(in_startingQuests)); Precondition.AreInRange(nonNullInventory, All.ItemIDs, nameof(in_startingInventory)); Precondition.IsNotEmpty(in_personalName, nameof(in_personalName)); Precondition.IsNotEmpty(in_familyName, nameof(in_familyName)); PersonalName = in_personalName; FamilyName = in_familyName; Pronoun = nonNullPronoun; StoryCharacterID = in_storyCharacterID; StartingQuests = nonNullQuests.ToList(); Dialogue = (in_dialogue ?? Enumerable.Empty <string>()).ToList(); StartingInventory = nonNullInventory.ToList(); }
public void IsNotEmptyStringTest() { var testValue = "will pass"; var exception = Record.Exception(() => Precondition.IsNotEmpty(testValue)); Assert.Null(exception); }
public void IsNotEmptyTest() { var testValue = new List <EntityID> { 0, 1, 2 }; var exception = Record.Exception(() => Precondition.IsNotEmpty(testValue)); Assert.Null(exception); }
protected GameObject(Range <GameObjectID> in_bounds, GameObjectID in_id, string in_name, string in_description, string in_comment) { Precondition.IsInRange(in_id, in_bounds, nameof(in_id)); Precondition.IsNotEmpty(in_name, nameof(in_name)); ID = in_id; Name = in_name; Description = in_description ?? ""; Comment = in_comment ?? ""; }
/// <summary> /// Initializes a new instance of the <see cref="RoomRecipe"/> class. /// </summary> /// <param name="in_id">Unique identifier for the <see cref="RoomRecipe"/>. Cannot be null.</param> /// <param name="in_name">Player-friendly name of the <see cref="RoomRecipe"/>.</param> /// <param name="in_description">Player-friendly description of the <see cref="RoomRecipe"/>.</param> /// <param name="in_comment">Comment of, on, or by the <see cref="RoomRecipe"/>.</param> /// <param name="in_requiredFurnishings">A list of furnishing categories this <see cref="RoomRecipe"/> requires.</param> /// <param name="in_MinimumWalkableSpaces">The minimum number of walkable <see cref="Space"/>s required by this <see cref="RoomRecipe"/>.</param> /// <param name="in_optionallyRequiredWalkableFloors">An optional list of floor categories this <see cref="RoomRecipe"/> requires.</param> /// <param name="in_optionallyRequiredPerimeterBlocks">An optional list of block categories this <see cref="RoomRecipe"/> requires as walls.</param> public RoomRecipe(GameObjectID in_id, string in_name, string in_description, string in_comment, List <RecipeElement> in_requiredFurnishings, int in_MinimumWalkableSpaces = All.Recipes.Rooms.MinWalkableSpaces, List <RecipeElement> in_optionallyRequiredWalkableFloors = null, List <RecipeElement> in_optionallyRequiredPerimeterBlocks = null) : base(All.RoomRecipeIDs, in_id, in_name, in_description, in_comment) { Precondition.IsNotNull(in_requiredFurnishings, nameof(in_requiredFurnishings)); Precondition.IsNotEmpty(in_requiredFurnishings, nameof(in_requiredFurnishings)); if (in_MinimumWalkableSpaces < All.Recipes.Rooms.MinWalkableSpaces || in_MinimumWalkableSpaces > All.Recipes.Rooms.MaxWalkableSpaces) { throw new ArgumentOutOfRangeException(nameof(in_MinimumWalkableSpaces)); } MinimumWalkableSpaces = in_MinimumWalkableSpaces; RequiredFloors = in_optionallyRequiredWalkableFloors ?? Enumerable.Empty <RecipeElement>().ToList(); RequiredPerimeterBlocks = in_optionallyRequiredPerimeterBlocks ?? Enumerable.Empty <RecipeElement>().ToList(); RequiredFurnishings = in_requiredFurnishings; }
/// <summary> /// Initializes a new instance of the <see cref="CraftingRecipe"/> class. /// </summary> /// <param name="in_id">Unique identifier for the <see cref="CraftingRecipe"/>. Cannot be null.</param> /// <param name="in_name">Player-friendly name of the <see cref="CraftingRecipe"/>. Cannot be null or empty.</param> /// <param name="in_description">Player-friendly description of the <see cref="CraftingRecipe"/>.</param> /// <param name="in_comment">Comment of, on, or by the <see cref="CraftingRecipe"/>.</param> /// <param name="in_products">The types and quantities of <see cref="Items.Item"/>s created by following this recipe once.</param> /// <param name="in_ingredients">All items needed to follow this <see cref="CraftingRecipe"/> once.</param> /// <param name="in_panelPattern">The arrangment of panels encompassed by this <see cref="CraftingRecipe"/>.</param> /// <exception cref="IndexOutOfRangeException"> /// Thrown when <paramref name="in_panelPattern"/> has zero-dimensions or dimensions larger than those given by /// <see cref="All.Dimensions.PanelsPerPatternWidth"/> and <see cref="All.Dimensions.PanelsPerPatternHeight"/>. /// </exception> public CraftingRecipe(GameObjectID in_id, string in_name, string in_description, string in_comment, IEnumerable <RecipeElement> in_products, IEnumerable <RecipeElement> in_ingredients, StrikePanel[,] in_panelPattern) : base(All.CraftingRecipeIDs, in_id, in_name, in_description, in_comment) { Precondition.IsNotNull(in_products, nameof(in_products)); Precondition.IsNotEmpty(in_products, nameof(in_products)); Precondition.IsNotNull(in_ingredients, nameof(in_ingredients)); Precondition.IsNotEmpty(in_ingredients, nameof(in_ingredients)); Precondition.IsNotNull(in_panelPattern, nameof(in_panelPattern)); if (in_panelPattern.GetLength(0) > All.Dimensions.PanelsPerPatternHeight || in_panelPattern.GetLength(1) > All.Dimensions.PanelsPerPatternWidth || in_panelPattern.GetLength(0) < 1 || in_panelPattern.GetLength(1) < 1) { throw new IndexOutOfRangeException($"Dimension outside specification: {nameof(in_panelPattern)}"); } Products = in_products.ToList(); Ingredients = in_ingredients.ToList(); PanelPattern = in_panelPattern; }
/// <summary> /// Initializes a new instance of the <see cref="GameObjectCollection{T}"/> class. /// </summary> /// <param name="in_bounds">The bounds within which the collected <see cref="GameObjectID"/>s are defined.</param> /// <param name="in_serializedParquets">The serialized parquets.</param> public GameObjectCollection(List <Range <GameObjectID> > in_bounds, string in_serializedParquets) { Precondition.IsNotEmpty(in_serializedParquets, nameof(in_serializedParquets)); // TODO: Ensure this is working as intended. See: // https://stackoverflow.com/questions/6348215/how-to-deserialize-json-into-ienumerablebasetype-with-newtonsoft-json-net // https://www.newtonsoft.com/json/help/html/SerializeTypeNameHandling.htm Dictionary <GameObjectID, GameObject> baseCollection; try { baseCollection = JsonConvert.DeserializeObject <Dictionary <GameObjectID, GameObject> >(in_serializedParquets); } catch (JsonReaderException exception) { throw new System.Runtime.Serialization.SerializationException( $"Error reading string while deserializing an {nameof(GameObject)} or {nameof(GameObjectID)}", exception); } Bounds = in_bounds; Entities = baseCollection; }
public void IsNotEmptyStringThrowsOnEmptyStringTest() { var testValue = ""; Assert.Throws <IndexOutOfRangeException>(() => Precondition.IsNotEmpty(testValue)); }
public void IsNotEmptyThrowsOnEmptyTest() { var testValue = new List <EntityID>(); Assert.Throws <IndexOutOfRangeException>(() => Precondition.IsNotEmpty(testValue)); }