private void SetData(ModSrcFile value) { if(value == data) return; data = value; UpdateView(); }
public static ModSrcFile FromFile(string file) { var data = new ModSrcFile() { FileName= file }; var lines = File.ReadAllLines(file, Encoding.UTF8); var delim = " \t".ToArray(); foreach(var i in lines) { var line = i.Trim(); var enabled = true; if(line.StartsWith("//")) { enabled = false; line = line.Substring(2).Trim(); } var t = line.Trim().Split(delim, StringSplitOptions.RemoveEmptyEntries); if(t.Length == 0) continue; switch(t[0]) { case "アイテム変更": break; case "スロット名": var slot= new ModSlot(data) { Name= t[1] }; data.Slots.Add(slot); break; case "マテリアル番号": var mtrl= new ModMaterial(data.CurrentSlot) { No= int.Parse(t[1]) }; data.CurrentSlot.Materials.Add(mtrl); break; case "テクスチャ設定": var tex = new ModTex() { Enabled = enabled, Name = t[1], Texture = t[2] }; data.CurrentMaterial.Textures.Add(tex); break; case "色設定": var col = new ModCol() { Enabled = enabled, Name = t[1], R = int.Parse(t[2]), G = int.Parse(t[3]), B = int.Parse(t[4]), A = int.Parse(t[5]) }; data.CurrentMaterial.Colors.Add(col); break; case "数値設定": var val = new ModValue() { Enabled = enabled, Name = t[1], Value = decimal.Parse(t[2]) }; data.CurrentMaterial.Values.Add(val); break; default: if(t.Length >= 2) data.Descriptions.Add(t[0], string.Join(" ", t.Skip(1).ToArray())); break; } } return data; }
public static void ToFile(string file, ModSrcFile data) { var lines = new List<string>(); foreach(var i in data.Descriptions) lines.Add(string.Format("{0}\t{1}", i.Key, i.Value)); lines.Add("アイテム変更"); foreach(var i in data.Slots) { lines.Add(string.Format("\tスロット名\t{0}", i.Name)); foreach(var j in i.Materials) { lines.Add(string.Format("\t\tマテリアル番号\t{0}", j.No)); foreach(var k in j.Textures) { lines.Add(string.Format( k.Enabled ? "\t\t\t{0}\t{1}\t{2}" : "//\t\t\t{0}\t{1}\t{2}", k.Type, k.Name, k.Texture)); } foreach(var k in j.Colors) { lines.Add(string.Format( k.Enabled ? "\t\t\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}" : "//\t\t\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}", k.Type, k.Name, k.R, k.G, k.B, k.A)); } foreach(var k in j.Values) { lines.Add(string.Format( k.Enabled ? "\t\t\t{0}\t{1}\t{2}" : "//\t\t\t{0}\t{1}\t{2}", k.Type, k.Name, k.Value)); } } } File.WriteAllLines(data.FileName, lines.ToArray()); }
public ModSlot(ModSrcFile owner) { Owner = owner; Materials = new List<ModMaterial>(); }