forked from project-fika/Fuyu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
521 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Common.Collections; | ||
using Fuyu.Common.Hashing; | ||
|
||
namespace Fuyu.Backend.BSG; | ||
|
||
public class ItemFactoryDatabase | ||
{ | ||
public static ItemFactoryDatabase Instance => instance.Value; | ||
private static readonly Lazy<ItemFactoryDatabase> instance = new(() => new ItemFactoryDatabase()); | ||
|
||
internal readonly ThreadDictionary<MongoId, ItemTemplate> itemTemplates; | ||
|
||
private ItemFactoryDatabase() | ||
{ | ||
itemTemplates = new ThreadDictionary<MongoId, ItemTemplate>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Backend.BSG.Models.Responses; | ||
using Fuyu.Common.Hashing; | ||
using Fuyu.Common.IO; | ||
using Fuyu.Common.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG; | ||
|
||
public class ItemFactoryLoader | ||
{ | ||
public static ItemFactoryLoader Instance => instance.Value; | ||
private static readonly Lazy<ItemFactoryLoader> instance = new(() => new ItemFactoryLoader()); | ||
|
||
private readonly ItemFactoryOrm _itemFactoryOrm; | ||
|
||
public ItemFactoryLoader() | ||
{ | ||
_itemFactoryOrm = ItemFactoryOrm.Instance; | ||
} | ||
|
||
public void Load() | ||
{ | ||
var itemsText = Resx.GetText("eft", "database.client.items.json"); | ||
var itemTemplates = Json.Parse<ResponseBody<Dictionary<MongoId, ItemTemplate>>>(itemsText).data; | ||
|
||
_itemFactoryOrm.SetItemTemplates(itemTemplates); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Common.Hashing; | ||
|
||
namespace Fuyu.Backend.BSG; | ||
|
||
public class ItemFactoryOrm | ||
{ | ||
public static ItemFactoryOrm Instance => instance.Value; | ||
private static readonly Lazy<ItemFactoryOrm> instance = new(() => new ItemFactoryOrm()); | ||
|
||
private readonly ItemFactoryDatabase _itemFactoryDatabase; | ||
|
||
public ItemFactoryOrm() | ||
{ | ||
_itemFactoryDatabase = ItemFactoryDatabase.Instance; | ||
} | ||
|
||
public void SetItemTemplates(Dictionary<MongoId, ItemTemplate> itemTemplates) | ||
{ | ||
foreach (var (key, value) in itemTemplates) | ||
{ | ||
_itemFactoryDatabase.itemTemplates.Set(key, value); | ||
} | ||
} | ||
|
||
public Dictionary<MongoId, ItemTemplate> GetItemTemplates() | ||
{ | ||
return _itemFactoryDatabase.itemTemplates.ToDictionary(); | ||
} | ||
|
||
public ItemTemplate GetItemTemplate(MongoId id) | ||
{ | ||
return _itemFactoryDatabase.itemTemplates.TryGet(id, out var itemTemplate) ? itemTemplate : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.