Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load the card with specific language #171

Open
chucklu opened this issue Jul 30, 2019 · 6 comments
Open

Load the card with specific language #171

chucklu opened this issue Jul 30, 2019 · 6 comments

Comments

@chucklu
Copy link
Contributor

chucklu commented Jul 30, 2019

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

@chucklu
Copy link
Contributor Author

chucklu commented Jul 30, 2019

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.

@rnilva
Copy link
Contributor

rnilva commented Jul 30, 2019

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.

@chucklu
Copy link
Contributor Author

chucklu commented Jul 30, 2019

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.

@rnilva
Copy link
Contributor

rnilva commented Jul 30, 2019

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?

@chucklu
Copy link
Contributor Author

chucklu commented Jul 30, 2019

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.

@chucklu
Copy link
Contributor Author

chucklu commented Jul 30, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants