Skip to content

Commit

Permalink
#1 Updated db entities to use erupe schema from update 9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
HimmDawg committed May 25, 2024
1 parent 2a01655 commit 7511b9d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 26 deletions.
31 changes: 14 additions & 17 deletions Models/RoadshopItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,43 @@ namespace RoadshopEditor.Models
{
public sealed class RoadshopItem
{
[Column("itemhash")]
[Column("id")]
public int ItemHash { get; set; }

[Column("shoptype")]
[Column("shop_type")]
public int? ShopType { get; set; }

[Column("shopid")]
[Column("shop_id")]
public ShopCategory ShopId { get; set; }

[Column("itemid")]
[Column("item_id")]
public int ItemId { get; set; }

[Column("points")]
public ushort? PointCost { get; set; }
[Column("cost")]
public int? PointCost { get; set; }

[Column("tradequantity")]
[Column("quantity")]
public ushort? TradeQuantity { get; set; }

[Column("rankreqlow")]
[Column("min_hr")]
public ushort? LowRankRequirement { get; set; }

[Column("rankreqhigh")]
[Column("min_sr")]
public ushort? HighRankRequirement { get; set; }

[Column("rankreqg")]
[Column("min_gr")]
public ushort? GRankRequirement { get; set; }

[Column("storelevelreq")]
[Column("store_level")]
public ushort? StoreLevelRequirement { get; set; }

[Column("maximumquantity")]
[Column("max_quantity")]
public ushort? MaxQuantity { get; set; }

[Column("boughtquantity")]
public ushort? QuantityBought { get; set; }

[Column("roadfloorsrequired")]
[Column("road_floors")]
public ushort? HuntingRoadLevelRequirement { get; set; }

[Column("weeklyfataliskills")]
[Column("road_fatalis")]
public ushort? WeeklyFatalisKills { get; set; }

[NotMapped]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Navigate to your folder where you have unpacked the archive and locate `appsetti
"ConnectionStrings": {
"RoadshopItemsDatabase": "Host=<host>;Database=erupe;Username=<username>;Password=<password>"
},
"RoadshopItemsTable": "normal_shop_items"
"RoadshopItemsTable": "shop_items"
}
```
Put in the required information for `<host>`, `<username>` and `<password>` and save the file. If your roadshop items tablename should differ from the one I put in, you can of course change it here too.
Put in the required information for `<host>`, `<username>` and `<password>` and save the file. If your roadshop items tablename should differ from the one I put in, you can of course change it here too, provided that the schema stays the same.

# Usage
### Adding items
Expand Down
44 changes: 44 additions & 0 deletions Services/Mapping/CsvConverters/ShopCategoryConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;

using CsvHelper;
using CsvHelper.Configuration;
using CsvHelper.TypeConversion;

using RoadshopEditor.Models;

namespace RoadshopEditor.Services.Mapping.CsvConverters;

internal class ShopCategoryConverter : DefaultTypeConverter
{
public override string? ConvertToString(object? value, IWriterRow row, MemberMapData memberMapData)
{
if (value is null)
{
return string.Empty;
}

if (Enum.TryParse(value.ToString(), out ShopCategory result))
{
return ((int)result).ToString();
}

return string.Empty;
}

public override object? ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData)
{
if (text is null)
{
return (ShopCategory)0;
}

var isValidId = int.TryParse(text, out int result);

if (isValidId)
{
return (ShopCategory)result;
}

return (ShopCategory)0;
}
}
4 changes: 2 additions & 2 deletions Services/Mapping/RoadshopClassMap.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CsvHelper.Configuration;

using RoadshopEditor.Models;
using RoadshopEditor.Services.Mapping.CsvConverters;

namespace RoadshopEditor.Services.Mapping;

Expand All @@ -9,7 +10,7 @@ internal sealed class RoadshopClassMap : ClassMap<RoadshopItem>
internal RoadshopClassMap()
{
Map(m => m.ShopType).Name("shoptype");
Map(m => m.ShopId).Name("shopid");
Map(m => m.ShopId).Name("shopid").TypeConverter<ShopCategoryConverter>();
Map(m => m.ItemHash).Name("itemhash");
Map(m => m.ItemId).Name("itemid");
Map(m => m.PointCost).Name("points");
Expand All @@ -19,7 +20,6 @@ internal RoadshopClassMap()
Map(m => m.GRankRequirement).Name("rankreqg");
Map(m => m.StoreLevelRequirement).Name("storelevelreq");
Map(m => m.MaxQuantity).Name("maximumquantity");
Map(m => m.QuantityBought).Name("boughtquantity");
Map(m => m.HuntingRoadLevelRequirement).Name("roadfloorsrequired");
Map(m => m.WeeklyFatalisKills).Name("weeklyfataliskills");
}
Expand Down
5 changes: 1 addition & 4 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ public async Task AddItem()
MaxQuantity = ushort.TryParse(MaxQuantity, out ushort maxQuantity)
? maxQuantity
: (ushort)0,
QuantityBought = ushort.TryParse(BoughtQuantity, out ushort boughtQuantity)
? boughtQuantity
: (ushort)0,
HuntingRoadLevelRequirement = ushort.TryParse(FloorRequirement, out ushort storeLevelRequirement)
? storeLevelRequirement
: (ushort)0,
Expand Down Expand Up @@ -169,7 +166,7 @@ public void Import(string filePath)
RoadshopItems.Clear();
foreach (var item in items)
{
item.Name = AllItems[item.ItemId];
item.Name = AllItems.GetValueOrDefault(item.ItemId) ?? string.Empty;
RoadshopItems.Add(item);
}
}
Expand Down
1 change: 0 additions & 1 deletion Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
</DataGridTemplateColumn>
<DataGridTextColumn Header="G-Rank Req." Binding="{Binding GRankRequirement}" />
<DataGridTextColumn Header="Max. Quant." Binding="{Binding MaxQuantity}" />
<DataGridTextColumn Header="Bought Quant." Binding="{Binding QuantityBought}" />
<DataGridTextColumn Header="H.Road Floor Req." Binding="{Binding HuntingRoadLevelRequirement}" />
<DataGridTextColumn Header="Fatalis Kills" Binding="{Binding WeeklyFatalisKills}" />
</DataGrid.Columns>
Expand Down

0 comments on commit 7511b9d

Please sign in to comment.