public static GameObjectsHandler WithFilepath(string filepath) { GameObjectsHandler goh = new GameObjectsHandler(); goh.GameObjs = parseJsonSchemaFromFile(filepath); return(goh); }
public void TestGetRecipePass() { // Serialize schema GameObjectsHandler goh = GameObjectsHandler.WithFilepath(getFilepath(itemSchemaV1)); // Create valid list of available objects List <RecipeElement> availables = new List <RecipeElement>(); availables.Add(new RecipeElement(4, 1)); availables.Add(new RecipeElement(5, 1)); // Obtain valid output GameObjectEntry goe = goh.GetRecipe(availables, 7); // Asserts Assert.That(goe.name, Is.EqualTo("steel")); }
public void TestInitialiseGameObjectsHandlerRemote() { GameObjectsHandler goh = GameObjectsHandler.WithRemoteSchema(); //Assert fields are correct Assert.That(goh.GameObjs.items.Count, Is.EqualTo(16)); Assert.That(goh.GameObjs.items[0].item_id, Is.EqualTo(1)); Assert.That(goh.GameObjs.items[0].name, Is.EqualTo("wood")); Assert.That(goh.GameObjs.items[0].type, Is.EqualTo(1)); Assert.That(goh.GameObjs.items[15].item_id, Is.EqualTo(16)); Assert.That(goh.GameObjs.items[15].name, Is.EqualTo("dune buggy")); Assert.That(goh.GameObjs.items[15].type, Is.EqualTo(5)); Assert.That(goh.GameObjs.items[15].blueprint[0].item_id, Is.EqualTo(9)); Assert.That(goh.GameObjs.items[15].blueprint[0].quantity, Is.EqualTo(4)); Assert.That(goh.GameObjs.items[15].blueprint[1].item_id, Is.EqualTo(10)); Assert.That(goh.GameObjs.items[15].blueprint[1].quantity, Is.EqualTo(1)); }
public void TestGetSingleElementBlueprintFail() { // Serialize schema GameObjectsHandler goh = GameObjectsHandler.WithFilepath(getFilepath(itemSchemaV1)); // Create list of available objects, with too few values List <RecipeElement> availables = new List <RecipeElement>(); availables.Add(new RecipeElement(2, 6)); GameObjectEntry goe = goh.GetBlueprint(availables, 7); if (goe != null) { // Failure case // GetBlueprint returns non-null object where null expected Assert.Fail(); } }
public void TestGetSingleElementBlueprintPass() { // Serialize schema GameObjectsHandler goh = GameObjectsHandler.WithFilepath(getFilepath(itemSchemaV1)); // Create list of available objects List <RecipeElement> availables = new List <RecipeElement>(); availables.Add(new RecipeElement(2, 8)); try { GameObjectEntry goe = goh.GetBlueprint(availables, 7); //Assert values are correct Assert.That(goe.name, Is.EqualTo("furnace")); } catch (InvalidDataException e) { // Exception thrown, failure case Assert.Fail(); } }
public void TestGetRecipeFail() { // Serialize schema GameObjectsHandler goh = GameObjectsHandler.WithFilepath(getFilepath(itemSchemaV1)); // Create valid list of available objects List <RecipeElement> availables = new List <RecipeElement>(); availables.Add(new RecipeElement(5, 1)); // Obtain valid output GameObjectEntry goe = goh.GetRecipe(availables, 7); // Asserts if (goe != null) { // Failure case, no objects are valid. Hence goe should be null Assert.Fail(); } }
public static GameObjectsHandler WithRemoteSchema() { GameObjectsHandler goh = new GameObjectsHandler(); // Get schema BlueprintAPI api = BlueprintAPI.DefaultCredentials(); Task.Run(async() => { APIResult <string, JsonError> response = await api.AsyncGetItemSchema(); if (response.isSuccess()) { // Populate GameObjs goh.GameObjs = JsonUtility.FromJson <GameObjects>(response.GetSuccess()); } else { throw new InvalidDataException(response.GetError().error); } }).GetAwaiter().GetResult(); return(goh); }
public int GetItemType(int id) { GameObjectsHandler goh = GameObjectsHandler.WithRemoteSchema(); return(goh.GameObjs.items[id - 1].type); }
public string GetItemName(int id) { GameObjectsHandler goh = GameObjectsHandler.WithRemoteSchema(); return(goh.GameObjs.items[id - 1].name); }