Skip to content

Commit

Permalink
handle synthesis logs
Browse files Browse the repository at this point in the history
  • Loading branch information
msarilar committed Nov 5, 2016
1 parent 9c3c2b2 commit fc4745f
Showing 1 changed file with 57 additions and 23 deletions.
80 changes: 57 additions & 23 deletions EDEngineer/Utils/JournalEntryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ private JournalOperation ExtractOperation(JObject data, JournalEvent journalEven
return ExtractCollectCargo(data);
case JournalEvent.EjectCargo:
return ExtractEjectCargo(data);
case JournalEvent.Synthesis:
return ExtractSynthesis(data);
default:
return null;
}
}

private JournalOperation ExtractMarketSell(JObject data)
{
string marketSellName;
Expand Down Expand Up @@ -239,29 +240,69 @@ private JournalOperation ExtractMaterialDiscarded(JObject data)
}
}

private JournalOperation ExtractSynthesis(JObject data)
{
foreach (var jToken in data["Materials"])
{
var material = (JProperty) jToken;
string synthesisIngredientName;
if (!converter.TryGet(material.Name, out synthesisIngredientName))
{
MessageBox.Show($"Unknown material, please contact the author ! {material.Name}");
return null;
}

var entry = converter[synthesisIngredientName];

switch (entry.Kind)
{
case Kind.Material:
return new MaterialOperation()
{
MaterialName = synthesisIngredientName,
Size = material.Value != null ? (int) material.Value : 1
};
case Kind.Data:
return new DataOperation()
{
DataName = synthesisIngredientName,
Size = material.Value != null ? (int)material.Value : 1
};
case Kind.Commodity:
return new CargoOperation()
{
CommodityName = synthesisIngredientName,
Size = material.Value != null ? (int)material.Value : 1
};
default:
throw new ArgumentOutOfRangeException();
}
}

return null;
}

private JournalOperation ExtractMaterialCollected(JObject data)
{
string materialCollectedName;
if (!converter.TryGet((string)data["Name"], out materialCollectedName))
if (!converter.TryGet((string) data["Name"], out materialCollectedName))
{
MessageBox.Show($"Unknown material, please contact the author ! {(string)data["Name"]}");
MessageBox.Show($"Unknown material, please contact the author ! {(string) data["Name"]}");
return null;
}

if (((string)data["Category"]).ToLowerInvariant() == "encoded")
if (((string) data["Category"]).ToLowerInvariant() == "encoded")
{
return new DataOperation
{
DataName = materialCollectedName,
Size = data["Count"]?.ToObject<int>() ?? 1
DataName = materialCollectedName, Size = data["Count"]?.ToObject<int>() ?? 1
};
}
else // Manufactured & Raw
{
return new MaterialOperation
{
MaterialName = materialCollectedName,
Size = data["Count"]?.ToObject<int>() ?? 1
MaterialName = materialCollectedName, Size = data["Count"]?.ToObject<int>() ?? 1
};
}
}
Expand All @@ -270,17 +311,12 @@ private EngineerOperation ExtractEngineerOperation(JObject data)
{
var operation = new EngineerOperation
{
IngredientsConsumed = data["Ingredients"]
.Select(c =>
{
dynamic cc = c;
string rewardName;
return Tuple.Create(converter.TryGet((string) cc.Name, out rewardName),
rewardName,
(int) cc.Value);
})
.Where(c => c.Item1)
.Select(c => new BlueprintIngredient(entries[c.Item2], c.Item3)).ToList()
IngredientsConsumed = data["Ingredients"].Select(c =>
{
dynamic cc = c;
string rewardName;
return Tuple.Create(converter.TryGet((string) cc.Name, out rewardName), rewardName, (int) cc.Value);
}).Where(c => c.Item1).Select(c => new BlueprintIngredient(entries[c.Item2], c.Item3)).ToList()
};

return operation.IngredientsConsumed.Any() ? operation : null;
Expand All @@ -290,8 +326,7 @@ private static ManualChangeOperation ExctractManualOperation(JObject data)
{
return new ManualChangeOperation
{
Name = (string) data["Name"],
Count = (int) data["Count"]
Name = (string) data["Name"], Count = (int) data["Count"]
};
}

Expand All @@ -301,8 +336,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
var operation = (ManualChangeOperation) entry.JournalOperation;
writer.WriteStartObject();
writer.WritePropertyName("timestamp");
writer.WriteValue(entry.TimeStamp.ToString(InstantPattern.GeneralPattern.PatternText,
CultureInfo.InvariantCulture));
writer.WriteValue(entry.TimeStamp.ToString(InstantPattern.GeneralPattern.PatternText, CultureInfo.InvariantCulture));
writer.WritePropertyName("event");
writer.WriteValue(operation.JournalEvent.ToString());
writer.WritePropertyName("Name");
Expand Down

0 comments on commit fc4745f

Please sign in to comment.