SabberStone
SabberStone copied to clipboard
Load the card with specific language
Currently we did not have a chance to set the default language, it's hard coded in https://github.com/HearthSim/SabberStone/blob/master/SabberStoneCore/src/Loader/CardLoader.cs#L109
We also need add support for the FromName method of Cards https://github.com/HearthSim/SabberStone/blob/master/SabberStoneCore/src/Model/Cards.cs#L333
The following method should use First instead of FirstOrDefault
public static Card FromName(string cardName)
{
return Data.Cards.FirstOrDefault(x => x.Value.Name == cardName && x.Value.Collectible).Value;
}
Currently when I switch the language of Cards to zhCN https://github.com/HearthSim/SabberStone/blob/master/SabberStoneCoreTest/src/CardSets/LootapaloozaCardsGenTest.cs#L2084
var game = new Game(new GameConfig
{
StartPlayer = 1,
Player1HeroClass = CardClass.PRIEST,
Player1Deck = new List<Card>()
{
Cards.FromName("Lesser Diamond Spellstone"),
},
Player2HeroClass = CardClass.PRIEST,
Shuffle = false,
FillDecks = true,
FillDecksPredictably = true
});
The above code Player1Deck will get a deck list with a null item in it.
If you change it to First it throws an exception instead of returning null.
I would like to add functionality that allows users to have some controls over parsing cards, for example, someone may want to load only specific cardsets etc. I am considering which form would we have for the functionality.
Yes, I think it should throw exception if we can not find the card. Otherwise it's too late when I find the card is null. If someone want to load cards from specific card set, we might provide another method with two parameters, card name and card set.
How do you think about the language setting for Cards?
Currently, the cards were loaded in static constructor static Cards(), I did not have a chance to modify it outside the Cards class.
Currently static class Cards would implicitly be constructed when the first time it is called, using the static constructor you mentioned. I think if we have an explicit generator function for Cards it would work... like Cards.Generate() and make users call it before creating his/her first Game object and otherwise, it should be called implicitly like the current scheme. Maybe there are more neat designs?
Maybe we can get the language from App.config in static constructor? Add a app setting with key Language or CardLanguage, then read it from config file.
Otherwise we need provide a reload method for Cards class, and the method with one parameter language.
From another repository, I find the card implementation https://github.com/HearthSim/HearthDb/blob/master/HearthDb/Card.cs#L26 It supports the language setting on card level, we might take this design.