private static IEnumerable <(string key, IItemFactory itemFactory)> GetItemFactories( IJsonAssetsApi jaApi ) { // Big craftables foreach (var(jaKey, id) in jaApi.GetAllBigCraftableIds()) { var key = $"{ItemTypes.BigCraftable}/{jaKey}"; var itemFactory = new SimpleItemFactory( ItemTypes.BigCraftable, () => new SObject(Vector2.Zero, id) ); yield return(key, itemFactory); } // Clothing foreach (var(jaKey, id) in jaApi.GetAllClothingIds()) { var key = $"{ItemTypes.Clothing}/{jaKey}"; var itemFactory = new SimpleItemFactory(ItemTypes.Clothing, () => new Clothing(id)); yield return(key, itemFactory); } // Hats foreach (var(jaKey, id) in jaApi.GetAllHatIds()) { var key = $"{ItemTypes.Hat}/{jaKey}"; var itemFactory = new SimpleItemFactory(ItemTypes.Hat, () => new Hat(id)); yield return(key, itemFactory); } // Weapons foreach (var(jaKey, id) in jaApi.GetAllWeaponIds()) { var key = $"{ItemTypes.Weapon}/{jaKey}"; var itemFactory = new SimpleItemFactory( ItemTypes.Weapon, () => new MeleeWeapon(id) ); yield return(key, itemFactory); } // Objects foreach (var(jaKey, id) in jaApi.GetAllObjectIds()) { var key = $"{ItemTypes.Object}/{jaKey}"; var itemFactory = new SimpleItemFactory(ItemTypes.Object, () => new SObject(id, 1)); yield return(key, itemFactory); } }
private string[] Token_ObjectId(ITokenString input) { if (input == null) { return(ja.GetAllObjectIds().Values.Select((i) => i.ToString()).ToArray <string>()); } var str = input.Value; int id = ja.GetObjectId(str); if (id == -1) { return new string[] { } } ; return(new[] { id.ToString() }); }
/// <summary> /// Event that gets ran when the game is launched /// </summary> /// <param name="sender">The sender</param> /// <param name="e">Event Args</param> private void OnGameLaunched(object sender, GameLaunchedEventArgs e) { IJsonAssetsApi jsonApi = Helper.ModRegistry.GetApi <IJsonAssetsApi>("spacechase0.JsonAssets"); if (jsonApi != null) { IDictionary <string, int> objectIds = jsonApi.GetAllObjectIds(); IDictionary <string, int> bigCraftIds = jsonApi.GetAllBigCraftableIds(); Monitor.Log($"Checked GetAlObjectIds Found: {objectIds.Count}, GetAllBigCraftables Found: {bigCraftIds.Count}"); foreach (var v in bigCraftIds) { Monitor.Log($"Id: {v.Value}"); } /* * Monitor.Log($"Last ObJect Id: {objectIds.Last().Value}. Last BigCraftable id: {bigCraftIds.Last().Value}."); * HaxorSprinkler.ParentSheetIndex = objectIds.Last().Value + 1; * HaxorScarecrow.ParentSheetIndex = bigCraftIds.Last().Value + 1;*/ } else { Monitor.Log("JsonAssetsApi will null."); } }