Skip to content

Commit

Permalink
initial material reading
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Dec 13, 2019
1 parent d1f60be commit c0cbdc1
Show file tree
Hide file tree
Showing 9 changed files with 701 additions and 12 deletions.
429 changes: 429 additions & 0 deletions MaterialForm.Designer.cs

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions MaterialForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cdda_item_creator
{
public partial class MaterialForm : Form
{
MaterialType main_material = new MaterialType() { };
private BindingSource MaterialBindingSource;
private void LoadMaterialDataBinding()
{
MaterialBindingSource = new BindingSource(components);
((ISupportInitialize)(MaterialBindingSource)).BeginInit();

identTextBox.DataBindings.Add(new Binding("Text", MaterialBindingSource, "Ident", true));
nameTextBox.DataBindings.Add(new Binding("Text", MaterialBindingSource, "Name", true));

bashResistUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "BashResist", true));
cutResistUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "CutResist", true));
acidResistUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "AcidResist", true));
elecResistUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "ElecResist", true));
fireResistUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "fireResist", true));
chipResistUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "ChipResist", true));

densityUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "Density", true));

specificHeatLiquidUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "SpecificHeatLiquid", true));
specificHeatSolidUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "SpecificHeatSolid", true));
latentHeatUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "LatentHeat", true));
freezePointUpDown.DataBindings.Add(new Binding("Value", MaterialBindingSource, "FreezePoint", true));

salvagedIntoTextBox.DataBindings.Add(new Binding("Text", MaterialBindingSource, "SalvagedInto", true));
repairedIntoTextBox.DataBindings.Add(new Binding("Text", MaterialBindingSource, "RepairedInto", true));

edibleCheckBox.DataBindings.Add(new Binding("Checked", MaterialBindingSource, "Edible", true));
rottingCheckBox.DataBindings.Add(new Binding("Checked", MaterialBindingSource, "Rotting", true));
softCheckBox.DataBindings.Add(new Binding("Checked", MaterialBindingSource, "Soft", true));
reinforcesCheckBox.DataBindings.Add(new Binding("Checked", MaterialBindingSource, "Reinforces", true));

bashDmgVerbTextBox.DataBindings.Add(new Binding("Text", MaterialBindingSource, "BashDmgVerb", true));
cutDmgVerbTextBox.DataBindings.Add(new Binding("Text", MaterialBindingSource, "CutDmgVerb", true));

((ISupportInitialize)(MaterialBindingSource)).EndInit();

MaterialBindingSource.Add(main_material);
}
private void LoadMaterialList()
{
materialLoaderComboBox.Items.AddRange(Program.LoadedObjectDictionary.GetList("material").ToArray());
}
public MaterialForm()
{
InitializeComponent();
LoadMaterialList();
LoadMaterialDataBinding();
}
private void UpdateMainMaterialBindings()
{
MaterialBindingSource.Clear();
MaterialBindingSource.Add(main_material);
MaterialBindingSource.ResetBindings(false);
}
private void materialLoaderComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (materialLoaderComboBox.SelectedIndex == -1)
{
return;
}
// TODO: selector for items, and show what mod they're from
List<MaterialType> mats = Program.LoadedObjectDictionary.GetMaterials(materialLoaderComboBox.Text);
main_material = mats[0].DeepCopy();
UpdateMainMaterialBindings();
}
}
}
120 changes: 120 additions & 0 deletions MaterialForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
4 changes: 2 additions & 2 deletions MaterialType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace cdda_item_creator
{
class BurnDataChunk
public class BurnDataChunk
{
public bool Immune { get; set; }
// volume string, like "10 ml"
Expand All @@ -17,7 +17,7 @@ class BurnDataChunk
public float Smoke { get; set; }
public float Burn { get; set; }
}
class MaterialType
public class MaterialType
{
// mandatory
public string Ident { get; set; } = "";
Expand Down
21 changes: 21 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class LoadedObjectDictionary
static Dictionary<string, List<Mtype>> mtypes_by_id = new Dictionary<string, List<Mtype>> { };
static Dictionary<string, List<spell.spell_type>> spells_by_id = new Dictionary<string, List<spell.spell_type>> { };
static Dictionary<string, List<MonsterAttack>> mattacks_by_id = new Dictionary<string, List<MonsterAttack>> { };
static Dictionary<string, List<MaterialType>> materials_by_id = new Dictionary<string, List<MaterialType>> { };

static public void Add(string type, string id)
{
Expand All @@ -38,6 +39,20 @@ static public void Add(string type, string id)
ids_by_type.Add(type, temp_list);
}
}
static public void Add(string id, MaterialType material)
{
List<MaterialType> temp_material;
if (materials_by_id.TryGetValue(id, out temp_material))
{
temp_material.Add(material);
materials_by_id[id] = temp_material;
}
else
{
temp_material = new List<MaterialType> { material };
materials_by_id.Add(id, temp_material);
}
}
static public void Add(string id, MonsterAttack mattack)
{
List<MonsterAttack> temp_attack;
Expand Down Expand Up @@ -100,6 +115,12 @@ static public List<MonsterAttack> GetMAttacks(string id)
mattacks_by_id.TryGetValue(id, out ret);
return ret;
}
static public List<MaterialType> GetMaterials(string id)
{
List<MaterialType> ret;
materials_by_id.TryGetValue(id, out ret);
return ret;
}
}
/// <summary>
/// The main entry point for the application.
Expand Down
9 changes: 9 additions & 0 deletions cdda-item-creator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="custom_json.cs" />
<Compile Include="MaterialForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MaterialForm.Designer.cs">
<DependentUpon>MaterialForm.cs</DependentUpon>
</Compile>
<Compile Include="MaterialType.cs" />
<Compile Include="MonsterAttack.cs" />
<Compile Include="MonsterAttackForm.cs">
Expand Down Expand Up @@ -86,6 +92,9 @@
<Compile Include="ViewerForm.Designer.cs">
<DependentUpon>ViewerForm.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="MaterialForm.resx">
<DependentUpon>MaterialForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MonsterAttackForm.resx">
<DependentUpon>MonsterAttackForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down
10 changes: 7 additions & 3 deletions custom_json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,14 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JArray outer = JToken.Load(reader).ToObject<JArray>();
Dictionary<string, T> ret = new Dictionary<string, T> { };
foreach (JArray array in outer)
Dictionary<string, T> ret = null;
if (outer != null)
{
ret.Add((string)array[0], array[1].ToObject<T>());
ret = new Dictionary<string, T> { };
foreach (JArray array in outer)
{
ret.Add((string)array[0], array[1].ToObject<T>());
}
}
return ret;
}
Expand Down
15 changes: 14 additions & 1 deletion selector.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0cbdc1

Please sign in to comment.