/// <summary> /// Sets up the mock word document to return building block information for a range. /// </summary> /// <param name="name">The name of the building block for which information is to be set up.</param> /// <param name="startPosition">The start position of the building block.</param> /// <param name="endPosition">The end position of the building block.</param> /// <param name="previewImage">The preview image for the building block.</param> /// <param name="fieldNames">The list of field names.</param> private void SetupBuildingBlockInformation(string name, int startPosition, int endPosition, Image previewImage, params string[] fieldNames) { BuildingBlockName bbname = new BuildingBlockName(name); BuildingBlockInfo bbi = new BuildingBlockInfo(bbname, fieldNames, previewImage); this.mockWordDocument.Setup(wordDoc => wordDoc.ReadBuildingBlockInfo(bbname, startPosition, endPosition)).Returns(bbi); }
private void AssignMaterialSprite(SpriteRenderer img, BuildingBlockInfo info) { switch (BuildingBlockMenu.CurrentMaterial) { case Materials.Wood: if (info.woodIcon) { img.sprite = info.woodIcon; } break; case Materials.Ice: if (info.iceIcon) { img.sprite = info.iceIcon; } break; case Materials.Stone: if (info.stoneIcon) { img.sprite = info.stoneIcon; } break; } //This acts mostly as an exception for the slingshot if (info.foreGroundSprite) { img.sprite = info.foreGroundSprite; } }
/// <summary> /// Creates a layout information object from the building blocks that make it up. /// </summary> /// <param name="category">The category from which to get the layout name.</param> /// <param name="blocks">The building blocks that make up the layout.</param> /// <param name="blocksInfo">Information about the building blocks that make up the layout.</param> /// <returns>The layout information for the new layout.</returns> private LayoutInformation CreateLayout(string category, IEnumerable <BuildingBlock> blocks, IEnumerable <BuildingBlockInfo> blocksInfo) { BuildingBlockInfo defaultBbi = null; BuildingBlockInfo previewBbi = null; string layoutName = ExtractLayoutName(category); string[] fields = new string[0]; foreach (BuildingBlockInfo bbi in blocksInfo) { if (IsDefaultBuildingBlock(bbi)) { defaultBbi = bbi; } else if (IsPreviewBuildingBlock(bbi)) { previewBbi = bbi; } fields = fields.Union(bbi.ContentControlTags.Where(tag => Utilities.IsValidTag(tag))).ToArray(); } this.AddLayoutBlocksToCache(layoutName, blocks); return(new LayoutInformation( layoutName, blocks.Select(bb => new BuildingBlockName(bb)).ToArray(), fields.Distinct(StringComparer.Ordinal).ToArray(), previewBbi == null ? defaultBbi.PreviewImage : previewBbi.PreviewImage)); }
/// <summary> /// Reads information about a building block. /// </summary> /// <param name="buildingBlock">The building block to get the information for.</param> /// <returns>The information about the building block.</returns> public BuildingBlockInfo ReadBuildingBlockInfo(BuildingBlock buildingBlock) { BuildingBlockInfo ans = null; if (buildingBlock == null) { throw new ArgumentNullException("buildingBlock"); } this.ExecuteDocumentModifyingAction(() => { Range temp = this.CreateTemporaryRange(); try { temp = buildingBlock.Insert(temp); ans = CreateBuildingBlockInfoFromRange(new BuildingBlockName(buildingBlock), temp); } finally { this.document.Undo(2); } }); return(ans); }
/// <summary> /// Creates the building block information for a range. /// </summary> /// <param name="name">The name of the building block.</param> /// <param name="r">The range where the building block is in the document.</param> /// <returns>The building block information.</returns> private BuildingBlockInfo CreateBuildingBlockInfoFromRange(BuildingBlockName name, Range r) { BuildingBlockInfo ans; IEnumerable <ContentControl> contentControls = this.ContentControlsInRange(r); ans = new BuildingBlockInfo(name, contentControls.Select(cc => cc.Tag).ToArray(), GetPreviewForBuildingBlock(r)); return(ans); }
/// <summary> /// Sets up the mock word document to return building block information. /// </summary> /// <param name="buildingBlock">The building block to be associated with the information.</param> /// <param name="previewImage">The preview image for the building block.</param> /// <param name="fieldNames">The list of field names.</param> private void SetupBuildingBlockInformation(BuildingBlock buildingBlock, Image previewImage, params string[] fieldNames) { BuildingBlockInfo bbi = new BuildingBlockInfo(new BuildingBlockName(buildingBlock), fieldNames, previewImage); this.mockWordDocument.Setup(wordDoc => wordDoc.ReadBuildingBlockInfo(buildingBlock)).Returns(bbi); }
private void TurnVisible(Image img, BuildingBlockInfo info) { if (img.sprite) return; //Hard-coded because there are only three materials. Oooh bad coding practice ~(°O°~) img.sprite = info.woodIcon; img.SetNativeSize(); if (img.sprite) return; img.sprite = info.iceIcon; img.SetNativeSize(); if (img.sprite) return; img.sprite = info.stoneIcon; img.SetNativeSize(); if (img.sprite) return; }
/// <summary> /// Checks if a building block is the preview building block. /// </summary> /// <param name="bbi">The building block info to check.</param> /// <returns><c>True</c> if the building block is the preview building block, <c>false</c> otherwise.</returns> private static bool IsPreviewBuildingBlock(BuildingBlockInfo bbi) { return(bbi.Name == BuildingBlockName.Preview); }
/// <summary> /// Checks if a building block is the default building block. /// </summary> /// <param name="bbi">The building block info to check.</param> /// <returns><c>True</c> if the building block is the default building block, <c>false</c> otherwise.</returns> private static bool IsDefaultBuildingBlock(BuildingBlockInfo bbi) { return(bbi.Name == BuildingBlockName.Default); }
private Materials DetermineMaterial(SpriteRenderer img, BuildingBlockInfo buildingBlockInfo) { //No switch-statement for reference types if (img.sprite == buildingBlockInfo.woodIcon) { return Materials.Wood; } else if (img.sprite == buildingBlockInfo.iceIcon) { return Materials.Ice; } else { return Materials.Stone; } }
private void setBuildingBlockInfo <T>(BuildingBlockInfo <T> info) where T : class, IBuildingBlock { info.TemplateBuildingBlock = A.Fake <T>().WithId(_templateId); info.BuildingBlock = A.Fake <T>().WithId(ShortGuid.NewGuid()); }
private void checkInfo <T>(BuildingBlockInfo <T> info) where T : class, IBuildingBlock { info.TemplateBuildingBlockId.ShouldBeEqualTo(_templateId); }