Skip to content

Commit 9cc5b13

Browse files
committed
rename ShopBase -> ShopDescriptor, ShopItem -> ShopItemDescriptor
1 parent e046bd8 commit 9cc5b13

File tree

17 files changed

+118
-100
lines changed

17 files changed

+118
-100
lines changed

Framework/Intersect.Framework.Core/Descriptors/GameObjectType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public enum GameObjectType
3333
[GameObjectInfo(typeof(ResourceDescriptor), "resources")]
3434
Resource,
3535

36-
[GameObjectInfo(typeof(ShopBase), "shops")]
36+
[GameObjectInfo(typeof(ShopDescriptor), "shops")]
3737
Shop,
3838

3939
[GameObjectInfo(typeof(SpellBase), "spells")]

Framework/Intersect.Framework.Core/GameObjects/ShopBase.cs renamed to Framework/Intersect.Framework.Core/GameObjects/Shops/ShopDescriptor.cs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55

66
namespace Intersect.GameObjects;
77

8-
public partial class ShopBase : DatabaseObject<ShopBase>, IFolderable
8+
public partial class ShopDescriptor : DatabaseObject<ShopDescriptor>, IFolderable
99
{
1010
[NotMapped]
11-
public List<ShopItem> BuyingItems { get; set; } = [];
11+
public List<ShopItemDescriptor> BuyingItems { get; set; } = [];
1212

1313
[NotMapped]
14-
public List<ShopItem> SellingItems { get; set; } = [];
14+
public List<ShopItemDescriptor> SellingItems { get; set; } = [];
1515

1616
[JsonConstructor]
17-
public ShopBase(Guid id) : base(id)
17+
public ShopDescriptor(Guid id) : base(id)
1818
{
1919
Name = "New Shop";
2020
}
2121

2222
//EF is so damn picky about its parameters
23-
public ShopBase()
23+
public ShopDescriptor()
2424
{
2525
Name = "New Shop";
2626
}
@@ -45,15 +45,15 @@ public ItemDescriptor DefaultCurrency
4545
public string JsonBuyingItems
4646
{
4747
get => JsonConvert.SerializeObject(BuyingItems);
48-
set => BuyingItems = JsonConvert.DeserializeObject<List<ShopItem>>(value);
48+
set => BuyingItems = JsonConvert.DeserializeObject<List<ShopItemDescriptor>>(value);
4949
}
5050

5151
[Column("SellingItems")]
5252
[JsonIgnore]
5353
public string JsonSellingItems
5454
{
5555
get => JsonConvert.SerializeObject(SellingItems);
56-
set => SellingItems = JsonConvert.DeserializeObject<List<ShopItem>>(value);
56+
set => SellingItems = JsonConvert.DeserializeObject<List<ShopItemDescriptor>>(value);
5757
}
5858

5959
public string BuySound { get; set; } = null;
@@ -62,25 +62,4 @@ public string JsonSellingItems
6262

6363
/// <inheritdoc />
6464
public string Folder { get; set; } = string.Empty;
65-
}
66-
67-
public partial class ShopItem
68-
{
69-
public Guid CostItemId;
70-
71-
public int CostItemQuantity;
72-
73-
public Guid ItemId;
74-
75-
[JsonConstructor]
76-
public ShopItem(Guid itemId, Guid costItemId, int costVal)
77-
{
78-
ItemId = itemId;
79-
CostItemId = costItemId;
80-
CostItemQuantity = costVal;
81-
}
82-
83-
[NotMapped]
84-
[JsonIgnore]
85-
public ItemDescriptor Item => ItemDescriptor.Get(ItemId);
86-
}
65+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
using Intersect.Framework.Core.GameObjects.Items;
3+
using Newtonsoft.Json;
4+
5+
namespace Intersect.GameObjects;
6+
7+
public partial class ShopItemDescriptor
8+
{
9+
public Guid CostItemId { get; set; }
10+
11+
public int CostItemQuantity { get; set; }
12+
13+
public Guid ItemId { get; set; }
14+
15+
[JsonConstructor]
16+
public ShopItemDescriptor(Guid itemId, Guid costItemId, int costVal)
17+
{
18+
ItemId = itemId;
19+
CostItemId = costItemId;
20+
CostItemQuantity = costVal;
21+
}
22+
23+
[NotMapped]
24+
[JsonIgnore]
25+
public ItemDescriptor Item => ItemDescriptor.Get(ItemId);
26+
}

Intersect.Client.Core/General/Globals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static partial class Globals
126126

127127
//Game Shop
128128
//Only need 1 shop, and that is the one we see at a given moment in time.
129-
public static ShopBase? GameShop { get; set; }
129+
public static ShopDescriptor? GameShop { get; set; }
130130

131131
/// <see cref="GameStates" />
132132
public static GameStates GameState

Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -375,66 +375,79 @@ void _iconImage_HoverEnter(Base? sender, EventArgs? arguments)
375375
return;
376376
}
377377

378+
var inventorySlotDescriptor = inventorySlot.Descriptor;
379+
if (inventorySlotDescriptor is null)
380+
{
381+
return;
382+
}
383+
378384
if (Globals.GameShop == null)
379385
{
380-
if (inventorySlot.Descriptor != null)
381-
{
382-
_descWindow = new ItemDescriptionWindow(
383-
inventorySlot.Descriptor, inventorySlot.Quantity, _inventoryWindow.X,
384-
_inventoryWindow.Y, inventorySlot.ItemProperties
385-
);
386-
}
386+
_descWindow = new ItemDescriptionWindow(
387+
inventorySlotDescriptor,
388+
inventorySlot.Quantity,
389+
_inventoryWindow.X,
390+
_inventoryWindow.Y,
391+
inventorySlot.ItemProperties
392+
);
387393
}
388394
else
389395
{
390-
ShopItem? shopItem = default;
396+
ShopItemDescriptor? shopItemDescriptor = default;
391397
for (var i = 0; i < Globals.GameShop.BuyingItems.Count; i++)
392398
{
393399
var tmpShop = Globals.GameShop.BuyingItems[i];
394400
if (inventorySlot.ItemId == tmpShop.ItemId)
395401
{
396-
shopItem = tmpShop;
402+
shopItemDescriptor = tmpShop;
397403
break;
398404
}
399405
}
400406

401-
if (Globals.GameShop.BuyingWhitelist && shopItem != default)
407+
if (Globals.GameShop.BuyingWhitelist && shopItemDescriptor != default)
402408
{
403-
if (!ItemDescriptor.TryGet(shopItem.CostItemId, out var hoveredItem))
409+
if (!ItemDescriptor.TryGet(shopItemDescriptor.CostItemId, out var hoveredItem))
404410
{
405411
return;
406412
}
407413

408-
if (inventorySlot.Descriptor != null)
409-
{
410-
_descWindow = new ItemDescriptionWindow(
411-
inventorySlot.Descriptor, inventorySlot.Quantity,
412-
_inventoryWindow.X, _inventoryWindow.Y, inventorySlot.ItemProperties, "",
413-
Strings.Shop.SellsFor.ToString(shopItem.CostItemQuantity, hoveredItem.Name)
414-
);
415-
}
414+
_descWindow = new ItemDescriptionWindow(
415+
inventorySlotDescriptor,
416+
inventorySlot.Quantity,
417+
_inventoryWindow.X,
418+
_inventoryWindow.Y,
419+
inventorySlot.ItemProperties,
420+
"",
421+
Strings.Shop.SellsFor.ToString(shopItemDescriptor.CostItemQuantity, hoveredItem.Name)
422+
);
416423
}
417-
else if (shopItem == null)
424+
else if (shopItemDescriptor == null)
418425
{
419426
var costItem = Globals.GameShop.DefaultCurrency;
420-
if (inventorySlot.Descriptor != null && costItem != null)
427+
if (inventorySlotDescriptor != null && costItem != null)
421428
{
422429
_descWindow = new ItemDescriptionWindow(
423-
inventorySlot.Descriptor, inventorySlot.Quantity,
424-
_inventoryWindow.X, _inventoryWindow.Y, inventorySlot.ItemProperties, "",
425-
Strings.Shop.SellsFor.ToString(inventorySlot.Descriptor.Price.ToString(), costItem.Name)
430+
inventorySlotDescriptor,
431+
inventorySlot.Quantity,
432+
_inventoryWindow.X,
433+
_inventoryWindow.Y,
434+
inventorySlot.ItemProperties,
435+
"",
436+
Strings.Shop.SellsFor.ToString(inventorySlotDescriptor.Price.ToString(), costItem.Name)
426437
);
427438
}
428439
}
429440
else
430441
{
431-
if (inventorySlot.Descriptor != null)
432-
{
433-
_descWindow = new ItemDescriptionWindow(
434-
inventorySlot.Descriptor, inventorySlot.Quantity, _inventoryWindow.X, _inventoryWindow.Y, inventorySlot.ItemProperties,
435-
"", Strings.Shop.WontBuy
436-
);
437-
}
442+
_descWindow = new ItemDescriptionWindow(
443+
inventorySlotDescriptor,
444+
inventorySlot.Quantity,
445+
_inventoryWindow.X,
446+
_inventoryWindow.Y,
447+
inventorySlot.ItemProperties,
448+
"",
449+
Strings.Shop.WontBuy
450+
);
438451
}
439452
}
440453
}

Intersect.Client.Core/Networking/PacketHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ public void HandlePacket(IPacketSender packetSender, ShopPacket packet)
17111711

17121712
if (packet.ShopData != null)
17131713
{
1714-
Globals.GameShop = new ShopBase();
1714+
Globals.GameShop = new ShopDescriptor();
17151715
Globals.GameShop.Load(packet.ShopData);
17161716
Interface.Interface.EnqueueInGame(gameInterface => gameInterface.NotifyOpenShop());
17171717
}

Intersect.Editor/Forms/Editors/Events/CommandPrinter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ private static string GetCommandText(OpenBankCommand command, MapInstance map)
12161216

12171217
private static string GetCommandText(OpenShopCommand command, MapInstance map)
12181218
{
1219-
return Strings.EventCommandList.openshop.ToString(ShopBase.GetName(command.ShopId));
1219+
return Strings.EventCommandList.openshop.ToString(ShopDescriptor.GetName(command.ShopId));
12201220
}
12211221

12221222
private static string GetCommandText(OpenCraftingTableCommand command, MapInstance map)

Intersect.Editor/Forms/Editors/Events/Event Commands/EventCommand_OpenShop.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public EventCommandOpenShop(OpenShopCommand refCommand, FrmEvent editor)
1919
mEventEditor = editor;
2020
InitLocalization();
2121
cmbShop.Items.Clear();
22-
cmbShop.Items.AddRange(ShopBase.Names);
23-
cmbShop.SelectedIndex = ShopBase.ListIndex(mMyCommand.ShopId);
22+
cmbShop.Items.AddRange(ShopDescriptor.Names);
23+
cmbShop.SelectedIndex = ShopDescriptor.ListIndex(mMyCommand.ShopId);
2424
}
2525

2626
private void InitLocalization()
@@ -35,7 +35,7 @@ private void btnSave_Click(object sender, EventArgs e)
3535
{
3636
if (cmbShop.SelectedIndex > -1)
3737
{
38-
mMyCommand.ShopId = ShopBase.IdFromList(cmbShop.SelectedIndex);
38+
mMyCommand.ShopId = ShopDescriptor.IdFromList(cmbShop.SelectedIndex);
3939
}
4040

4141
mEventEditor.FinishCommandEdit();

Intersect.Editor/Forms/Editors/frmShop.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ namespace Intersect.Editor.Forms.Editors;
1515
public partial class FrmShop : EditorForm
1616
{
1717

18-
private List<ShopBase> mChanged = new List<ShopBase>();
18+
private List<ShopDescriptor> mChanged = new List<ShopDescriptor>();
1919

2020
private string mCopiedItem;
2121

22-
private ShopBase mEditorItem;
22+
private ShopDescriptor mEditorItem;
2323

2424
private List<string> mKnownFolders = new List<string>();
2525

@@ -33,7 +33,7 @@ public FrmShop()
3333
}
3434
private void AssignEditorItem(Guid id)
3535
{
36-
mEditorItem = ShopBase.Get(id);
36+
mEditorItem = ShopDescriptor.Get(id);
3737
UpdateEditor();
3838
}
3939

@@ -42,7 +42,7 @@ protected override void GameObjectUpdatedDelegate(GameObjectType type)
4242
if (type == GameObjectType.Shop)
4343
{
4444
InitEditor();
45-
if (mEditorItem != null && !ShopBase.Lookup.Values.Contains(mEditorItem))
45+
if (mEditorItem != null && !ShopDescriptor.Lookup.Values.Contains(mEditorItem))
4646
{
4747
mEditorItem = null;
4848
UpdateEditor();
@@ -278,7 +278,7 @@ private void btnAddSoldItem_Click(object sender, EventArgs e)
278278
{
279279
var addedItem = false;
280280
var cost = (int) nudSellCost.Value;
281-
var newItem = new ShopItem(
281+
var newItem = new ShopItemDescriptor(
282282
ItemDescriptor.IdFromList(cmbAddSoldItem.SelectedIndex), ItemDescriptor.IdFromList(cmbSellFor.SelectedIndex), cost
283283
);
284284

@@ -315,7 +315,7 @@ private void btnAddBoughtItem_Click(object sender, EventArgs e)
315315
{
316316
var addedItem = false;
317317
var cost = (int) nudBuyAmount.Value;
318-
var newItem = new ShopItem(
318+
var newItem = new ShopItemDescriptor(
319319
ItemDescriptor.IdFromList(cmbAddBoughtItem.SelectedIndex), ItemDescriptor.IdFromList(cmbBuyFor.SelectedIndex), cost
320320
);
321321

@@ -468,15 +468,15 @@ public void InitEditor()
468468
{
469469
//Collect folders
470470
var mFolders = new List<string>();
471-
foreach (var itm in ShopBase.Lookup)
471+
foreach (var itm in ShopDescriptor.Lookup)
472472
{
473-
if (!string.IsNullOrEmpty(((ShopBase) itm.Value).Folder) &&
474-
!mFolders.Contains(((ShopBase) itm.Value).Folder))
473+
if (!string.IsNullOrEmpty(((ShopDescriptor) itm.Value).Folder) &&
474+
!mFolders.Contains(((ShopDescriptor) itm.Value).Folder))
475475
{
476-
mFolders.Add(((ShopBase) itm.Value).Folder);
477-
if (!mKnownFolders.Contains(((ShopBase) itm.Value).Folder))
476+
mFolders.Add(((ShopDescriptor) itm.Value).Folder);
477+
if (!mKnownFolders.Contains(((ShopDescriptor) itm.Value).Folder))
478478
{
479-
mKnownFolders.Add(((ShopBase) itm.Value).Folder);
479+
mKnownFolders.Add(((ShopDescriptor) itm.Value).Folder);
480480
}
481481
}
482482
}
@@ -487,8 +487,8 @@ public void InitEditor()
487487
cmbFolder.Items.Add("");
488488
cmbFolder.Items.AddRange(mKnownFolders.ToArray());
489489

490-
var items = ShopBase.Lookup.OrderBy(p => p.Value?.Name).Select(pair => new KeyValuePair<Guid, KeyValuePair<string, string>>(pair.Key,
491-
new KeyValuePair<string, string>(((ShopBase)pair.Value)?.Name ?? Models.DatabaseObject<ShopBase>.Deleted, ((ShopBase)pair.Value)?.Folder ?? ""))).ToArray();
490+
var items = ShopDescriptor.Lookup.OrderBy(p => p.Value?.Name).Select(pair => new KeyValuePair<Guid, KeyValuePair<string, string>>(pair.Key,
491+
new KeyValuePair<string, string>(((ShopDescriptor)pair.Value)?.Name ?? Models.DatabaseObject<ShopDescriptor>.Deleted, ((ShopDescriptor)pair.Value)?.Folder ?? ""))).ToArray();
492492
lstGameObjects.Repopulate(items, mFolders, btnAlphabetical.Checked, CustomSearch(), txtSearch.Text);
493493
}
494494

Intersect.Editor/Networking/PacketHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,14 @@ public void HandlePacket(IPacketSender packetSender, GameObjectPacket packet)
579579
case GameObjectType.Shop:
580580
if (deleted)
581581
{
582-
var shp = ShopBase.Get(id);
582+
var shp = ShopDescriptor.Get(id);
583583
shp.Delete();
584584
}
585585
else
586586
{
587-
var shp = new ShopBase(id);
587+
var shp = new ShopDescriptor(id);
588588
shp.Load(json);
589-
ShopBase.Lookup.Set(id, shp);
589+
ShopDescriptor.Lookup.Set(id, shp);
590590
}
591591

592592
break;

0 commit comments

Comments
 (0)