Skip to content

Commit a1cccdd

Browse files
author
Justin
committed
Fixed bugs where parsing hero abilities was sort of broken. Added support for hero ability requires scepter.
1 parent 36c2e71 commit a1cccdd

File tree

6 files changed

+77
-62
lines changed

6 files changed

+77
-62
lines changed

src/SourceSchemaParser/DOTA2/DotaAbilitySpecialSchemaItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ internal class DotaAbilitySpecialSchemaItem
66
public string Value { get; set; }
77
public string VarType { get; set; }
88
public string LinkedSpecialBonus { get; set; }
9+
public bool RequiresScepter { get; set; }
910
}
1011
}

src/SourceSchemaParser/DotaSchemaMapperProfile.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@ public class DotaSchemaMapperProfile : Profile
88
{
99
public DotaSchemaMapperProfile()
1010
{
11-
CreateMap<DotaHeroSchemaItem, HeroSchemaModel>();
12-
CreateMap<DotaSchema, Steam.Models.DOTA2.SchemaModel>();
13-
CreateMap<DotaSchemaGameInfo, SchemaGameInfoModel>();
14-
CreateMap<DotaSchemaRarity, SchemaRarityModel>();
15-
CreateMap<DotaSchemaColor, SchemaColorModel>();
16-
CreateMap<DotaSchemaItem, Steam.Models.DOTA2.SchemaItemModel>();
17-
CreateMap<DotaSchemaPrefab, SchemaPrefabModel>();
18-
CreateMap<DotaSchemaItemSet, Steam.Models.DOTA2.SchemaItemSetModel>();
19-
CreateMap<DotaSchemaPrefab, SchemaPrefabModel>();
20-
CreateMap<DotaSchemaItemAutograph, SchemaItemAutographModel>();
21-
CreateMap<DotaSchemaQuality, SchemaQualityModel>();
22-
CreateMap<DotaSchemaPrefabCapability, SchemaPrefabCapabilityModel>();
23-
CreateMap<DotaSchemaItemTool, SchemaItemToolModel>();
24-
CreateMap<DotaSchemaItemToolUsage, SchemaItemToolUsageModel>();
25-
CreateMap<DotaSchemaItemPriceInfo, SchemaItemPriceInfoModel>();
26-
CreateMap<DotaSchemaItemStaticAttribute, SchemaItemStaticAttributeModel>();
27-
CreateMap<DotaItemAbilitySchemaItem, ItemAbilitySchemaItemModel>();
28-
CreateMap<DotaAbilitySpecialSchemaItem, AbilitySpecialSchemaItemModel>();
29-
CreateMap<DotaAbilitySchemaItem, AbilitySchemaItemModel>();
30-
CreateMap<DotaItemBuildSchemaItem, ItemBuildSchemaItemModel>();
31-
CreateMap<DotaItemBuildGroupSchemaItem, ItemBuildGroupSchemaItemModel>();
11+
CreateMap<DotaHeroSchemaItem, Hero>();
12+
CreateMap<DotaSchema, Schema>();
13+
CreateMap<DotaSchemaGameInfo, SchemaGameInfo>();
14+
CreateMap<DotaSchemaRarity, SchemaRarity>();
15+
CreateMap<DotaSchemaColor, SchemaColor>();
16+
CreateMap<DotaSchemaItem, SchemaItem>();
17+
CreateMap<DotaSchemaPrefab, SchemaPrefab>();
18+
CreateMap<DotaSchemaItemSet, SchemaItemSet>();
19+
CreateMap<DotaSchemaItemAutograph, SchemaItemAutograph>();
20+
CreateMap<DotaSchemaQuality, SchemaQuality>();
21+
CreateMap<DotaSchemaPrefabCapability, SchemaPrefabCapability>();
22+
CreateMap<DotaSchemaItemTool, SchemaItemTool>();
23+
CreateMap<DotaSchemaItemToolUsage, SchemaItemToolUsage>();
24+
CreateMap<DotaSchemaItemPriceInfo, SchemaItemPriceInfo>();
25+
CreateMap<DotaSchemaItemStaticAttribute, SchemaItemStaticAttribute>();
26+
CreateMap<DotaItemAbilitySchemaItem, ItemAbility>();
27+
CreateMap<DotaAbilitySpecialSchemaItem, HeroAbilitySpecial>();
28+
CreateMap<DotaAbilitySchemaItem, HeroAbility>();
29+
CreateMap<DotaItemBuildSchemaItem, ItemBuild>();
30+
CreateMap<DotaItemBuildGroupSchemaItem, ItemBuildGroup>();
3231
CreateMap<DotaLeague, LeagueModel>();
3332
}
3433
}

src/SourceSchemaParser/ISchemaParser.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace SourceSchemaParser
55
{
66
public interface ISchemaParser
77
{
8-
IReadOnlyCollection<AbilitySchemaItemModel> GetDotaHeroAbilities(IEnumerable<string> vdf);
9-
IReadOnlyCollection<HeroSchemaModel> GetDotaHeroes(IEnumerable<string> vdf);
10-
IReadOnlyCollection<ItemAbilitySchemaItemModel> GetDotaItemAbilities(IEnumerable<string> vdf);
11-
ItemBuildSchemaItemModel GetDotaItemBuild(IEnumerable<string> vdf);
12-
IReadOnlyCollection<SchemaPrefabModel> GetDotaItemPrefabs(IEnumerable<string> vdf);
8+
IReadOnlyCollection<HeroAbility> GetDotaHeroAbilities(IEnumerable<string> vdf);
9+
IReadOnlyCollection<Hero> GetDotaHeroes(IEnumerable<string> vdf);
10+
IReadOnlyCollection<ItemAbility> GetDotaItemAbilities(IEnumerable<string> vdf);
11+
ItemBuild GetDotaItemBuild(IEnumerable<string> vdf);
12+
IReadOnlyCollection<SchemaPrefab> GetDotaItemPrefabs(IEnumerable<string> vdf);
1313
IReadOnlyCollection<LeagueModel> GetDotaLeaguesFromFile(string itemSchemaFilePath, string localizationFilePath);
1414
IReadOnlyCollection<LeagueModel> GetDotaLeaguesFromText(IEnumerable<string> itemSchemaVdfText, IEnumerable<string> localizationVdfText);
1515
IReadOnlyDictionary<string, string> GetDotaPanoramaLocalizationKeys(IEnumerable<string> vdf);
1616
IReadOnlyDictionary<string, string> GetDotaPublicLocalizationKeys(IEnumerable<string> vdf);
17-
SchemaModel GetDotaSchema(IEnumerable<string> vdf);
17+
Schema GetDotaSchema(IEnumerable<string> vdf);
1818
}
1919
}

src/SourceSchemaParser/JsonConverters/DotaAbilitySpecialSchemaItemJsonConverter.cs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
3636
continue;
3737
}
3838

39-
string currentVarType = String.Empty;
40-
string currentLinkedSpecialBonus = String.Empty;
39+
string abilityName = string.Empty;
40+
string abilityValue = string.Empty;
41+
string abilityVarType = string.Empty;
42+
string abilityLinkedSpecialBonus = string.Empty;
43+
bool abilityRequiresScepter = false;
4144

4245
// we need to go through all the actual values of the special properties
4346
var abilitySpecialIndividualProperties = abilitySpecialProperty.Value.Children<JProperty>();
@@ -47,26 +50,38 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
4750
// record the var_type of this special
4851
if (abilitySpecialIndividualProperty.Name == "var_type")
4952
{
50-
currentVarType = abilitySpecialIndividualProperty.Value.ToString();
51-
continue;
53+
abilityVarType = abilitySpecialIndividualProperty.Value.ToString();
5254
}
53-
54-
if (abilitySpecialIndividualProperty.Name == "LinkedSpecialBonus")
55+
else if (abilitySpecialIndividualProperty.Name == "LinkedSpecialBonus")
5556
{
56-
currentLinkedSpecialBonus = abilitySpecialIndividualProperty.Value.ToString();
57-
continue;
57+
abilityLinkedSpecialBonus = abilitySpecialIndividualProperty.Value.ToString();
5858
}
59-
60-
// construct the special attribute
61-
DotaAbilitySpecialSchemaItem abilitySpecial = new DotaAbilitySpecialSchemaItem()
59+
else if (abilitySpecialIndividualProperty.Name == "RequiresScepter")
6260
{
63-
Name = abilitySpecialIndividualProperty.Name,
64-
Value = abilitySpecialIndividualProperty.Value.ToString(),
65-
VarType = currentVarType
66-
};
67-
68-
abilitySpecials.Add(abilitySpecial);
61+
abilityRequiresScepter = abilitySpecialIndividualProperty.Value.ToString() == "1";
62+
}
63+
else if (abilitySpecialProperty.Name == "LinkedSpecialBonusOperation")
64+
{
65+
// no op until we want to handle this
66+
}
67+
else
68+
{
69+
abilityName = abilitySpecialIndividualProperty.Name;
70+
abilityValue = abilitySpecialIndividualProperty.Value.ToString();
71+
}
6972
}
73+
74+
// construct the special attribute
75+
DotaAbilitySpecialSchemaItem abilitySpecial = new DotaAbilitySpecialSchemaItem()
76+
{
77+
Name = abilityName,
78+
Value = abilityValue,
79+
VarType = abilityVarType,
80+
LinkedSpecialBonus = abilityLinkedSpecialBonus,
81+
RequiresScepter = abilityRequiresScepter
82+
};
83+
84+
abilitySpecials.Add(abilitySpecial);
7085
}
7186

7287
return abilitySpecials;

src/SourceSchemaParser/SchemaParser.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public SchemaParser(IVDFConvert vdfConvert, IMapper mapper)
2626

2727
#region Dota Main Item Schema
2828

29-
public SchemaModel GetDotaSchema(IEnumerable<string> vdf)
29+
public Schema GetDotaSchema(IEnumerable<string> vdf)
3030
{
3131
ValidateInput(vdf);
3232

3333
var schemaContainer = vdfConvert.DeserializeObject<DotaSchemaContainer>(vdf.ToList());
34-
return mapper.Map<DotaSchema, SchemaModel>(schemaContainer.Schema);
34+
return mapper.Map<DotaSchema, Schema>(schemaContainer.Schema);
3535
}
3636

37-
public IReadOnlyCollection<ItemAbilitySchemaItemModel> GetDotaItemAbilities(IEnumerable<string> vdf)
37+
public IReadOnlyCollection<ItemAbility> GetDotaItemAbilities(IEnumerable<string> vdf)
3838
{
3939
ValidateInput(vdf);
4040

@@ -44,8 +44,8 @@ public IReadOnlyCollection<ItemAbilitySchemaItemModel> GetDotaItemAbilities(IEnu
4444
if (schema.TryGetValue("DOTAAbilities", out item))
4545
{
4646
var itemAbilities = JsonConvert.DeserializeObject<IList<DotaItemAbilitySchemaItem>>(item.ToString(), new SchemaItemToDotaItemAbilityJsonConverter());
47-
var itemAbilityModels = mapper.Map<IList<DotaItemAbilitySchemaItem>, IList<ItemAbilitySchemaItemModel>>(itemAbilities);
48-
return new ReadOnlyCollection<ItemAbilitySchemaItemModel>(itemAbilityModels);
47+
var itemAbilityModels = mapper.Map<IList<DotaItemAbilitySchemaItem>, IList<ItemAbility>>(itemAbilities);
48+
return new ReadOnlyCollection<ItemAbility>(itemAbilityModels);
4949
}
5050
else
5151
{
@@ -75,7 +75,7 @@ public IReadOnlyDictionary<string, string> GetDotaPublicLocalizationKeys(IEnumer
7575

7676
#region Dota Heroes
7777

78-
public IReadOnlyCollection<AbilitySchemaItemModel> GetDotaHeroAbilities(IEnumerable<string> vdf)
78+
public IReadOnlyCollection<HeroAbility> GetDotaHeroAbilities(IEnumerable<string> vdf)
7979
{
8080
ValidateInput(vdf);
8181

@@ -85,16 +85,16 @@ public IReadOnlyCollection<AbilitySchemaItemModel> GetDotaHeroAbilities(IEnumera
8585
if (schema.TryGetValue("DOTAAbilities", out item))
8686
{
8787
var abilities = JsonConvert.DeserializeObject<IList<DotaAbilitySchemaItem>>(item.ToString(), new SchemaItemToDotaAbilityJsonConverter());
88-
var abilityModels = mapper.Map<IList<DotaAbilitySchemaItem>, IList<AbilitySchemaItemModel>>(abilities);
89-
return new ReadOnlyCollection<AbilitySchemaItemModel>(abilityModels);
88+
var abilityModels = mapper.Map<IList<DotaAbilitySchemaItem>, IList<HeroAbility>>(abilities);
89+
return new ReadOnlyCollection<HeroAbility>(abilityModels);
9090
}
9191
else
9292
{
9393
throw new ArgumentException("You supplied a VDF file, but it wasn't the expected Dota Heroes Abilities schema file.");
9494
}
9595
}
9696

97-
public IReadOnlyCollection<HeroSchemaModel> GetDotaHeroes(IEnumerable<string> vdf)
97+
public IReadOnlyCollection<Hero> GetDotaHeroes(IEnumerable<string> vdf)
9898
{
9999
ValidateInput(vdf);
100100

@@ -104,16 +104,16 @@ public IReadOnlyCollection<HeroSchemaModel> GetDotaHeroes(IEnumerable<string> vd
104104
if (schema.TryGetValue("DOTAHeroes", out item))
105105
{
106106
var heroes = JsonConvert.DeserializeObject<IList<DotaHeroSchemaItem>>(item.ToString(), new SchemaItemToDotaHeroJsonConverter());
107-
var heroModels = mapper.Map<IList<DotaHeroSchemaItem>, IList<HeroSchemaModel>>(heroes);
108-
return new ReadOnlyCollection<HeroSchemaModel>(heroModels);
107+
var heroModels = mapper.Map<IList<DotaHeroSchemaItem>, IList<Hero>>(heroes);
108+
return new ReadOnlyCollection<Hero>(heroModels);
109109
}
110110
else
111111
{
112112
throw new ArgumentException("You supplied a VDF file, but it wasn't the expected Dota Heroes schema file.");
113113
}
114114
}
115115

116-
public ItemBuildSchemaItemModel GetDotaItemBuild(IEnumerable<string> vdf)
116+
public ItemBuild GetDotaItemBuild(IEnumerable<string> vdf)
117117
{
118118
ValidateInput(vdf);
119119

@@ -123,7 +123,7 @@ public ItemBuildSchemaItemModel GetDotaItemBuild(IEnumerable<string> vdf)
123123
if (schema.TryGetValue("itembuilds", out item))
124124
{
125125
var itemBuild = item.ToObject<DotaItemBuildSchemaItem>();
126-
var itemBuildModel = mapper.Map<DotaItemBuildSchemaItem, ItemBuildSchemaItemModel>(itemBuild);
126+
var itemBuildModel = mapper.Map<DotaItemBuildSchemaItem, ItemBuild>(itemBuild);
127127
return itemBuildModel;
128128
}
129129
else
@@ -238,7 +238,7 @@ private IReadOnlyCollection<DotaLeague> FlattenDotaSchemaItemLeagues(IReadOnlyCo
238238

239239
#endregion
240240

241-
public IReadOnlyCollection<SchemaPrefabModel> GetDotaItemPrefabs(IEnumerable<string> vdf)
241+
public IReadOnlyCollection<SchemaPrefab> GetDotaItemPrefabs(IEnumerable<string> vdf)
242242
{
243243
ValidateInput(vdf);
244244

@@ -253,9 +253,9 @@ public IReadOnlyCollection<SchemaPrefabModel> GetDotaItemPrefabs(IEnumerable<str
253253

254254
var prefabs = JsonConvert.DeserializeObject<IList<DotaSchemaPrefab>>(item.ToString(), new DotaSchemaPrefabJsonConverter());
255255

256-
var prefabModels = mapper.Map<IList<DotaSchemaPrefab>, IList<SchemaPrefabModel>>(prefabs);
256+
var prefabModels = mapper.Map<IList<DotaSchemaPrefab>, IList<SchemaPrefab>>(prefabs);
257257

258-
return new ReadOnlyCollection<SchemaPrefabModel>(prefabModels);
258+
return new ReadOnlyCollection<SchemaPrefab>(prefabModels);
259259
}
260260
else
261261
{

src/SourceSchemaParser/SourceSchemaParser.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Parses Valve Source Engine game schema files into easy to use object oriented structures.</Description>
5-
<VersionPrefix>3.0.3</VersionPrefix>
5+
<VersionPrefix>3.1.0</VersionPrefix>
66
<Authors>Justin Skiles</Authors>
77
<AssemblyName>SourceSchemaParser</AssemblyName>
88
<PackageId>SourceSchemaParser</PackageId>
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="automapper" Version="9.0.0" />
1616
<PackageReference Include="newtonsoft.json" Version="12.0.3" />
17-
<PackageReference Include="SteamWebAPI2" Version="4.1.3" />
17+
<PackageReference Include="SteamWebAPI2" Version="4.2.0" />
1818
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.3" />
1919
</ItemGroup>
2020

0 commit comments

Comments
 (0)