Skip to content

Commit

Permalink
Remove Newtonsoft.Json.dll and its references from the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
AxisKriel committed Jul 19, 2015
1 parent 7e2f55f commit e516ae1
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 292 deletions.
File renamed without changes.
Binary file not shown.
27 changes: 0 additions & 27 deletions Terraria/Achievements/Achievement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Threading;
Expand All @@ -8,7 +6,6 @@

namespace Terraria.Achievements
{
[JsonObject(MemberSerialization.OptIn)]
public class Achievement
{
private static int _totalAchievements;
Expand All @@ -25,7 +22,6 @@ public class Achievement

private IAchievementTracker _tracker;

[JsonProperty("Conditions")]
private Dictionary<string, AchievementCondition> _conditions;

private int _completedCount;
Expand Down Expand Up @@ -121,29 +117,6 @@ public IAchievementTracker GetTracker()
return this._tracker;
}

public void Load(Dictionary<string, JObject> conditions)
{
AchievementCondition achievementCondition;
foreach (KeyValuePair<string, JObject> condition in conditions)
{
if (!this._conditions.TryGetValue(condition.Key, out achievementCondition))
{
continue;
}
achievementCondition.Load(condition.Value);
if (!achievementCondition.IsCompleted)
{
continue;
}
Achievement achievement = this;
achievement._completedCount = achievement._completedCount + 1;
}
if (this._tracker != null)
{
this._tracker.Load();
}
}

private void OnConditionComplete(AchievementCondition condition)
{
Achievement achievement = this;
Expand Down
9 changes: 0 additions & 9 deletions Terraria/Achievements/AchievementCondition.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Threading;

namespace Terraria.Achievements
{
[JsonObject(MemberSerialization.OptIn)]
public abstract class AchievementCondition
{
public readonly string Name;

protected IAchievementTracker _tracker;

[JsonProperty("Completed")]
private bool _isCompleted;

public bool IsCompleted
Expand Down Expand Up @@ -60,11 +56,6 @@ public IAchievementTracker GetAchievementTracker()
return this._tracker;
}

public virtual void Load(JObject state)
{
this._isCompleted = (bool)state["Completed"];
}

public event AchievementCondition.AchievementUpdate OnComplete;

public delegate void AchievementUpdate(AchievementCondition condition);
Expand Down
119 changes: 2 additions & 117 deletions Terraria/Achievements/AchievementManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -21,8 +18,6 @@ public class AchievementManager

private Dictionary<string, Achievement> _achievements = new Dictionary<string, Achievement>();

private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings();

private ICryptoTransform _encryptor;

private ICryptoTransform _decryptor;
Expand Down Expand Up @@ -107,73 +102,7 @@ public int GetIconIndex(string achievementName)

public void Load()
{
this.Load(this._savePath);
}

private void Load(string path)
{
bool flag = false;
lock (AchievementManager._ioLock)
{
if (FileUtilities.Exists(path))
{
byte[] numArray = FileUtilities.ReadAllBytes(path);
Dictionary<string, AchievementManager.StoredAchievement> strs = null;
try
{
using (MemoryStream memoryStream = new MemoryStream(numArray))
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, this._decryptor, CryptoStreamMode.Read))
{
using (BsonReader bsonReader = new BsonReader(cryptoStream))
{
strs = JsonSerializer.Create(this._serializerSettings).Deserialize<Dictionary<string, AchievementManager.StoredAchievement>>(bsonReader);
}
}
}
}
catch (Exception)
{
FileUtilities.Delete(path);
return;
}
if (strs != null)
{
foreach (KeyValuePair<string, AchievementManager.StoredAchievement> keyValuePair in strs)
{
if (!this._achievements.ContainsKey(keyValuePair.Key))
{
continue;
}
this._achievements[keyValuePair.Key].Load(keyValuePair.Value.Conditions);
}
if (SocialAPI.Achievements != null)
{
foreach (KeyValuePair<string, Achievement> _achievement in this._achievements)
{
if (!_achievement.Value.IsCompleted || SocialAPI.Achievements.IsAchievementCompleted(_achievement.Key))
{
continue;
}
flag = true;
_achievement.Value.ClearProgress();
}
}
}
else
{
return;
}
}
else
{
return;
}
}
if (flag)
{
this.Save();
}

}

public void Register(Achievement achievement)
Expand All @@ -194,53 +123,9 @@ public void RegisterIconIndex(string achievementName, int iconIndex)

public void Save()
{
this.Save(this._savePath);
}

private void Save(string path)
{
lock (AchievementManager._ioLock)
{
if (SocialAPI.Achievements != null)
{
SocialAPI.Achievements.StoreStats();
}
try
{
using (MemoryStream memoryStream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, this._encryptor, CryptoStreamMode.Write))
{
using (BsonWriter bsonWriter = new BsonWriter(cryptoStream))
{
JsonSerializer.Create(this._serializerSettings).Serialize(bsonWriter, this._achievements);
bsonWriter.Flush();
cryptoStream.FlushFinalBlock();
FileUtilities.Write(path, memoryStream.GetBuffer(), (int)memoryStream.Length);
}
}
}
}
catch (Exception ex)
{
#if DEBUG
Console.WriteLine(ex);
System.Diagnostics.Debugger.Break();

#endif
}
}

}

public event Achievement.AchievementCompleted OnAchievementCompleted;

private class StoredAchievement
{
public Dictionary<string, JObject> Conditions;

public StoredAchievement()
{
}
}
}
}
13 changes: 0 additions & 13 deletions Terraria/GameContent/Achievements/CustomFloatCondition.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using Terraria;
using Terraria.Achievements;
Expand All @@ -8,7 +6,6 @@ namespace Terraria.GameContent.Achievements
{
internal class CustomFloatCondition : AchievementCondition
{
[JsonProperty("Value")]
private float _value;

private float _maxValue;
Expand Down Expand Up @@ -55,15 +52,5 @@ protected override IAchievementTracker CreateAchievementTracker()
{
return new ConditionFloatTracker(this._maxValue);
}

public override void Load(JObject state)
{
base.Load(state);
this._value = (float)((float)state["Value"]);
if (this._tracker != null)
{
((ConditionFloatTracker)this._tracker).SetValue(this._value, false);
}
}
}
}
13 changes: 0 additions & 13 deletions Terraria/GameContent/Achievements/CustomIntCondition.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using Terraria;
using Terraria.Achievements;
Expand All @@ -8,7 +6,6 @@ namespace Terraria.GameContent.Achievements
{
internal class CustomIntCondition : AchievementCondition
{
[JsonProperty("Value")]
private int _value;

private int _maxValue;
Expand Down Expand Up @@ -55,15 +52,5 @@ protected override IAchievementTracker CreateAchievementTracker()
{
return new ConditionIntTracker(this._maxValue);
}

public override void Load(JObject state)
{
base.Load(state);
this._value = (int)state["Value"];
if (this._tracker != null)
{
((ConditionIntTracker)this._tracker).SetValue(this._value, false);
}
}
}
}
Loading

0 comments on commit e516ae1

Please sign in to comment.