mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
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:
parent
79cb75c478
commit
c7b3a74390
1172710
src/Resources/store.xml
1172710
src/Resources/store.xml
File diff suppressed because it is too large
Load Diff
25
src/Schema/StoreData.cs
Normal file
25
src/Schema/StoreData.cs
Normal 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;
|
||||
}
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user