use ItemService for store and itemId in store.xml

- replace full items def in store.xml by item id
- load items def from items.xml (via ItemService) in StoreService constructor
This commit is contained in:
Robert Paciorek 2023-09-12 19:57:44 +00:00 committed by Spirtix
parent 79cb75c478
commit c7b3a74390
3 changed files with 16640 additions and 1156508 deletions

File diff suppressed because it is too large Load Diff

25
src/Schema/StoreData.cs Normal file
View File

@ -0,0 +1,25 @@
using System.Xml.Serialization;
namespace sodoff.Schema;
[XmlRoot(ElementName = "StoreData", Namespace = "")]
[Serializable]
public class StoreData {
[XmlElement(ElementName = "i")]
public int Id;
[XmlElement(ElementName = "s")]
public string StoreName;
[XmlElement(ElementName = "d")]
public string Description;
[XmlElement(ElementName = "ii")]
public int[] ItemId;
[XmlElement(ElementName = "ss")]
public ItemsInStoreDataSale[] SalesAtStore;
[XmlElement(ElementName = "pitem")]
public PopularStoreItem[] PopularItems;
}

View File

@ -4,15 +4,24 @@ using sodoff.Util;
namespace sodoff.Services;
public class StoreService {
// NOTE: ANother memory waste (slow clap)
Dictionary<int, ItemsInStoreData> stores = new();
public StoreService() {
GetStoreResponse storeArray = XmlUtil.DeserializeXml<GetStoreResponse>(XmlUtil.ReadResourceXmlString("store"));
foreach (var s in storeArray.Stores)
if (s.ID != null)
stores.Add((int)s.ID, s);
public StoreService(ItemService itemService) {
StoreData[] storeArray = XmlUtil.DeserializeXml<StoreData[]>(XmlUtil.ReadResourceXmlString("store"));
foreach (var s in storeArray) {
var newStore = new ItemsInStoreData {
ID = s.Id,
StoreName = s.StoreName,
Description = s.Description,
Items = new ItemData[s.ItemId.Length],
SalesAtStore = s.SalesAtStore,
PopularItems = s.PopularItems
};
for (int i=0; i<s.ItemId.Length; ++i) {
newStore.Items[i] = itemService.GetItem(s.ItemId[i]);
}
stores.Add(s.Id, newStore);
}
}
public ItemsInStoreData GetStore(int id) {