コード例 #1
0
        /// <summary>
        /// Gets all objects managed by the repository
        /// </summary>
        /// <returns>object list</returns>
        public IList <T> Get()
        {
            var files = GetFiles();

            return(files != null
                ? files.FileNames.Cast <string>().Select(p => KspData.LoadKspFile(p, registry.Create <T>())).Where(obj => obj != null).ToList()
                : null);
        }
コード例 #2
0
        public void DataTypeConvertTest()
        {
            var data = (new StreamReader(File.Open(TestHelpers.BaseDataPath() + @"Ships\VAB\MultiSatMk1.craft", FileMode.Open))).ReadToEnd();

            var convertedCraft  = KspData.Convert(data, ProcessorRegistry.Create().Create <CraftFile>()); // Bit ugly to test this use case, would never be this way in the real world as this is what happens internally
            var convertedCraft2 = KspData.Convert <CraftFile>(data);
            var craft           = KspData.LoadKspFile <CraftFile>(TestHelpers.BaseDataPath() + @"Ships\VAB\MultiSatMk1.craft");

            Assert.NotNull(convertedCraft);
            Assert.NotNull(convertedCraft2);
            Assert.AreEqual(craft.Parts.Count, convertedCraft.Parts.Count);
            Assert.AreEqual(craft.Parts.Count, convertedCraft2.Parts.Count);
        }
コード例 #3
0
        public void CloneTest()
        {
            var save  = KspData.LoadKspFile(TestHelpers.BaseDataTempPath() + @"saves\KspPersistentSfswMods\persistent.sfs", ProcessorRegistry.Create().Create <SaveFile>());
            var clone = save.Clone <SaveFile>();

            Assert.AreEqual(save.Game.Description, clone.Game.Description);
        }
コード例 #4
0
        public void SingleFileSaveTest()
        {
            var save = KspData.LoadKspFile(TestHelpers.BaseDataTempPath() + @"saves\KspPersistentSfswMods\persistent.sfs", ProcessorRegistry.Create().Create <SaveFile>());

            save.Game.Description = "HELLO WORLD!";
            save.Save();

            var changed = KspData.LoadKspFile(TestHelpers.BaseDataTempPath() + @"saves\KspPersistentSfswMods\persistent.sfs", ProcessorRegistry.Create().Create <SaveFile>());

            Assert.AreEqual(save.Game.Description, changed.Game.Description);

            changed.Save(TestHelpers.BaseDataTempPath() + @"saves\KspPersistentSfswMods\newname.sfs");

            var newsave = KspData.LoadKspFile(TestHelpers.BaseDataTempPath() + @"saves\KspPersistentSfswMods\newname.sfs", ProcessorRegistry.Create().Create <SaveFile>());

            Assert.AreEqual(save.Game.Description, newsave.Game.Description);
        }