public XDocument GenerateModuleConfigXml(SkinPack skins) { string MakeSafePath(string input) { return(Path.GetInvalidFileNameChars().Aggregate(input, (current, c) => current.Replace(c, '-'))); } var aircraftLookup = skins.Skins.ToLookup(k => k.Value.GetAircraftName()); var moduleChildren = new List <XElement> { new XElement("moduleName", _title), }; var image = checkForPreview(); if (image != null) { moduleChildren.Add(new XElement("moduleImage", new XAttribute("path", image))); } if (skins.ReadmeFiles.Count > 0) { moduleChildren.Add(new XElement("requiredInstallFiles", skins.ReadmeFiles.Select(r => new XElement("file", new XAttribute("source", r), new XAttribute("destination", Path.Combine(MakeSafePath(_title), new FileInfo(r).Name)))))); } moduleChildren.Add(GenerateStepsXml(aircraftLookup, skins.ExtraFiles.ToList(), skins.MultiSkinFiles.EnumerateDictionary(), skins.Crosshairs.EnumerateDictionary(), skins.Portraits.EnumerateDictionary(), skins.Weapons.EnumerateDictionary(), skins.Effects.EnumerateDictionary(), skins.Canopies.EnumerateDictionary(), skins.Emblems.EnumerateDictionary(), skins.Cockpits.EnumerateDictionary())); XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; var xdoc = new XDocument(GetCreatedComment(), new XElement("config", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "noNamespaceSchemaLocation", "http://qconsulting.ca/fo3/ModConfig5.0.xsd"), moduleChildren)); return(xdoc); }
public void SkinPack_ThrowsWhenSkinFileIsMissing() { string skinpack = @"{ ""Version"": ""1.2.3"", ""Name"": ""Test Pack"", ""Description"": ""Test skin pack"", ""Skins"": [ { ""Name"": ""A clock"", ""Description"": ""A test clock for testing"", ""Definition"": ""skin.json"" } ] }"; var fileReaderMock = new Mock <IFileReader>(); fileReaderMock.Setup(f => f.FileExists(It.IsAny <string>())).Returns((string s) => s == "skinpack.json"); fileReaderMock.Setup(f => f.GetString("skinpack.json")).Returns(skinpack); Assert.Throws <SkinPack.ValidationFailedException>(() => { SkinPack.Load(fileReaderMock.Object); }); }
public void SkinPackIndex_CanBeLoaded() { var files = new Dictionary <string, string> { { "skinpack.json", @"{ ""Version"": ""1.2.3"", ""Name"": ""Test Pack"", ""Description"": ""Test skin pack"", ""Skins"": [ { ""Name"": ""A clock"", ""Description"": ""A test clock for testing"", ""Definition"": ""testclock.json"" } ] }" }, { "testclock.json", @"{}" } }; var fileReader = new FakeFileReader(files); var sut = SkinPack.Load(fileReader); Assert.IsNotNull(sut); Assert.AreEqual(1, sut.Skins.Count); var skin = sut.Skins[0]; Assert.AreEqual("A clock", skin.Name); Assert.AreEqual("testclock.json", skin.Definition); Assert.IsEmpty(skin.Variables); }
public void SkinPack_ThrowsWhenIndexIsMissing() { var io = Mock.Of <IFileReader>(r => r.FileExists(It.IsAny <string>()) == false); Assert.Throws <EntryPointNotFoundException>(() => { SkinPack.Load(io); }); }
public void SkinPack_UpdatesVariables() { var files = new Dictionary <string, string> { { "skinpack.json", @"{ ""Version"": ""1.2.3"", ""Name"": ""Test Pack"", ""Description"": ""Test skin pack"", ""Skins"": [ { ""Name"": ""A clock"", ""Description"": ""A test clock for testing"", ""Definition"": ""clock.json"", ""Variables"": { ""col"": ""1"", ""color"": ""red"" } } ] }" }, { "clock.json", @"{ ""Width"": 100, ""Height"": 100, ""Layers"": [ { ""$type"": ""SolidLayer"", ""BackgroundColor"": ""#fff"", ""Shapes"": [ { ""$type"": ""RectangleShape"", ""Left"": $col, ""Top"": 0.0, ""Width"": 50.0, ""Height"": 50.0, ""Color"": ""$color"" } ], } ] }" } }; var fileReader = new FakeFileReader(files); var skinpack = SkinPack.Load(fileReader); var shape = skinpack.Skins.First().Canvas.Layers.First().Shapes.First() as RectangleShape; Assert.IsNotNull(shape); Assert.AreEqual("red", shape.Color); Assert.AreEqual(1, shape.Left); }
private void PrintSummaryTable(SkinPack files) { var table = new Table(); table.AddColumn(new TableColumn("[u]Type[/]")); table.AddColumn(new TableColumn("[u]Count[/]")); var summary = files.GetSummaryCount(true); foreach (var item in summary) { if (item.Value != 0) { table.AddRow(item.Key, item.Value.ToString()); } } AnsiConsole.Render(table); }
public void SkinPackIndex_CanBeDeserializedInto() { var json = @"{ ""Version"": ""1.2.3"", ""Name"": ""Test Pack"", ""Description"": ""Test skin pack"", ""Skins"": [ ] }"; var sut = new SkinPack(); JsonConvert.PopulateObject(json, sut); Assert.AreEqual("1.2.3", sut.Version.ToString()); Assert.AreEqual("Test Pack", sut.Name); Assert.IsNotEmpty(sut.Description); Assert.IsEmpty(sut.Skins); }
/// <summary> /// Задать список скинов /// </summary> /// <param name="skinList"></param> public void SkinPack_Init(int selected, Dictionary <int, List <Sprite> > skinList) { if (skinlist_inited) { return; } skinPack = new Dictionary <int, SkinPack>(); this.selected = selected; rtBtnSkins.gameObject.SetActive(true); int skinN = 0; foreach (var skinItem in skinList) { if (skinItem.Value == null) { continue; } if (skinItem.Value.Count == 0) { continue; } SkinPack skinPackHeader = new SkinPack(); skinPackHeader.skinPreviewList = new List <Image>(); skinPackHeader.id = skinN; GameObject rowGo = Instantiate(RowSkinPref, RowSkinPref.transform.parent); rowGo.SetActive(true); Transform buttonTr = rowGo.transform.Find("Button"); skinPackHeader.img_on = buttonTr.Find("ImageOn").GetComponent <Image>(); skinPackHeader.img_off = buttonTr.Find("ImageOff").GetComponent <Image>(); skinPackHeader.img_closed = buttonTr.Find("ImageClosed").GetComponent <Image>(); skinPackHeader.btn = buttonTr.GetComponent <Button>(); Transform contentTr = buttonTr.Find("content"); Transform imgTr1 = contentTr.Find("Image_1"); Transform imgTr2 = contentTr.Find("Image_2"); Transform imgTr3 = contentTr.Find("Image_3"); Transform imgTr4 = contentTr.Find("Image_4"); Image img1 = imgTr1.GetComponent <Image>(); img1.enabled = false; skinPackHeader.skinPreviewList.Add(img1); Image img2 = imgTr2.GetComponent <Image>(); img2.enabled = false; skinPackHeader.skinPreviewList.Add(img2); Image img3 = imgTr3.GetComponent <Image>(); img3.enabled = false; skinPackHeader.skinPreviewList.Add(img3); Image img4 = imgTr4.GetComponent <Image>(); img4.enabled = false; skinPackHeader.skinPreviewList.Add(img4); if (selected == skinN) { skinPackHeader.img_on.enabled = true; skinPackHeader.img_off.enabled = false; skinPackHeader.img_closed.enabled = false; } else { skinPackHeader.img_on.enabled = false; skinPackHeader.img_off.enabled = true; skinPackHeader.img_closed.enabled = false; } int i = 1; foreach (var spr in skinItem.Value) { if (i > 4) { continue; } if (i == 1) { img1.sprite = spr; img1.enabled = true; } if (i == 2) { img2.sprite = spr; img2.enabled = true; } if (i == 3) { img3.sprite = spr; img3.enabled = true; } if (i == 4) { img4.sprite = spr; img4.enabled = true; } i++; } //btn.onClick.RemoveAllListeners(); int nn = skinN; skinPackHeader.btn.onClick.AddListener(() => { BtnClickSelectSkin(nn); }); skinPack.Add(skinN, skinPackHeader); skinN++; } skinlist_inited = true; }