public static void SaveToModDirectory() { var path = ModConfiguration.streamingAssetsPath + "/" + ModConfiguration.current.modName; for (int i = 0; i < ModConfiguration.current.modData.Length; i++) { List <dynamic> cat = (List <dynamic>)ModConfiguration.current.modData[i]; if (!Directory.Exists(path + "/" + Enum.GetName(typeof(Catalog.Category), i))) { Directory.CreateDirectory(path); } if (cat.Count > 0) { DirectoryInfo directoryInfo; var catPath = path + "/" + Enum.GetName(typeof(Catalog.Category), i); if (!Directory.Exists(catPath)) { directoryInfo = Directory.CreateDirectory(catPath); } foreach (var fileObj in cat) { var id = fileObj.GetType().GetField("id").GetValue(fileObj); var filePath = path + "/" + Enum.GetName(typeof(Catalog.Category), i) + "/" + Enum.GetName(typeof(Catalog.Category), i) + "_" + id + ".json"; Type externalType = Type.GetType(fileObj.type); var instantiatedExternalObject = Activator.CreateInstance(externalType); var internalType = fileObj.GetType(); //TypeHelper.GenerateMissingType(externalType); // Converts to internal type dynamic internalObject = ModConfiguration.ConvertDynamic(fileObj, internalType); // Foreach internalField find the externalField corresponding to it and add the values // from the internal object to the external object. foreach (var internalField in internalType.GetFields()) { var commonFieldExternal = externalType.GetFields().FirstOrDefault(x => x.Name == internalField.Name); if (commonFieldExternal == null) { continue; } var internalObjectValue = internalField.GetValue(internalObject); // TODO: Check if list, if list then ... do stuff? commonFieldExternal.SetValue(instantiatedExternalObject, internalObjectValue); } var jsonNetSerializerSettings = GetDefaultJsonSettings(); File.WriteAllText(filePath, JsonConvert.SerializeObject(instantiatedExternalObject, jsonNetSerializerSettings)); } } } foreach (var field in typeof(Mod).GetProperties()) { if (!Attribute.IsDefined(field, typeof(SerializableAttribute))) { continue; } } }
public void CreateData(dynamic data, Type type, string newName, int category) { dynamic d = Activator.CreateInstance(type); foreach (var field in type.GetFields()) { field.SetValue(d, field.GetValue(ModConfiguration.ConvertDynamic(data, type))); } type.GetField("id").SetValue(d, newName); modData[category].Add(d); }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "File|*.json"; openFileDialog1.Title = "Select profile .json file"; var res = openFileDialog1.ShowDialog(); if (!File.Exists(openFileDialog1.FileName)) { return; } ModConfiguration.LoadModProfile(openFileDialog1.FileName); }
public StartupLoading() { InitializeComponent(); var path = String.IsNullOrEmpty(debugPath) ? Assembly.GetEntryAssembly().Location : debugPath; ModConfiguration.streamingAssetsPath = path + @"\BladeAndSorcery_Data\StreamingAssets"; ModConfiguration.LoadDefault(); // Preference? timer = new Timer(); timer.Interval = 5; timer.Tick += Timer_Tick; timer.Start(); }
private void Form1_Load(object sender, EventArgs e) { foreach (var data in ModConfiguration.generatedTypes) { Debug.Log(data.Name + " " + data.GetParentTypes().First().Name); } startupComplete = true; var auto = new AutoCompleteStringCollection(); foreach (var generatedType in ModConfiguration.allowedTypesStr) { auto.Add(generatedType); } customBaseText.AutoCompleteCustomSource = auto; customBaseText.AutoCompleteMode = AutoCompleteMode.Suggest; customBaseText.GotFocus += CustomBaseText_GotFocus; customBaseText.AutoCompleteSource = AutoCompleteSource.CustomSource; dataGrid = dataGridAttribute; dataGrid.CellContentClick += DataGrid_CellContentClick; ReferenceManager.ReferenceComplete += ReferenceManager_ReferenceComplete; Debug.Log("----DEFAULT LOADING COMPLETE----"); ModConfiguration.LoadMod("Default"); }
private void savToolStripMenuItem_Click(object sender, EventArgs e) { ModConfiguration.SaveModProfile(); ModConfiguration.SaveToModDirectory(); }