Skip to content

Commit

Permalink
introduce MaterialType
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Dec 11, 2019
1 parent e03c405 commit d1f60be
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
64 changes: 64 additions & 0 deletions MaterialType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cdda_item_creator
{
class BurnDataChunk
{
public bool Immune { get; set; }
// volume string, like "10 ml"
public string VolumePerTurn { get; set; }
public float Fuel { get; set; }
public float Smoke { get; set; }
public float Burn { get; set; }
}
class MaterialType
{
// mandatory
public string Ident { get; set; } = "";
// mandatory
public string Name { get; set; } = "";
public int BashResist { get; set; }
public int CutResist { get; set; }
public int AcidResist { get; set; }
public int ElecResist { get; set; }
public int FireResist { get; set; }
public int ChipResist { get; set; }
public int Density { get; set; }
public float SpecificHeatLiquid { get; set; }
public float SpecificHeatSolid { get; set; }
public float LatentHeat { get; set; }
public int FreezePoint { get; set; }
public string SalvagedInto { get; set; }
[DefaultValue("null")]
public string RepairedInto { get; set; } = "null";
[DefaultValue(false)]
public bool Edible { get; set; } = false;
[DefaultValue(false)]
public bool Rotting { get; set; } = false;
[DefaultValue(false)]
public bool Soft { get; set; } = false;
[DefaultValue(false)]
public bool Reinforces { get; set; } = false;
// dictionary-as-array
[JsonConverter(typeof(DictionaryAsArrayConverter<double>))]
public Dictionary<string, double> Vitamins { get; set; }
// mandatory
public string BashDmgVerb { get; set; } = "";
// mandatory
public string CutDmgVerb { get; set; } = "";
// mandatory
public List<string> DmgAdj { get; set; } = new List<string> { };
public List<BurnDataChunk> BurnData { get; set; }
// dictionary-as-array
[JsonConverter(typeof(DictionaryAsArrayConverter<float>))]
public Dictionary<string, float> BurnProducts { get; set; }
public List<string> CompactAccepts { get; set; }
public List<string> CompactsInto { get; set; }
}
}
1 change: 1 addition & 0 deletions cdda-item-creator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="custom_json.cs" />
<Compile Include="MaterialType.cs" />
<Compile Include="MonsterAttack.cs" />
<Compile Include="MonsterAttackForm.cs">
<SubType>Form</SubType>
Expand Down
28 changes: 28 additions & 0 deletions custom_json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,34 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
return null;
}
}
// T is the value of the dictionary. the key is a string
public class DictionaryAsArrayConverter<T> : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(Dictionary<string, T>));
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
Dictionary<string, T> pairs = value as Dictionary<string, T>;
JArray outer = new JArray { };
foreach (string key in pairs.Keys)
{
outer.Add(new JArray { key, pairs[key] });
}
outer.WriteTo(writer);
}
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)
{
ret.Add((string)array[0], array[1].ToObject<T>());
}
return ret;
}
}
public class MAttackGunRangeConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
Expand Down

0 comments on commit d1f60be

Please sign in to comment.