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_BigCraftableId(ITokenString input) { if (input == null) { return(ja.GetAllBigCraftableIds().Values.Select((i) => i.ToString()).ToArray <string>()); } var str = input.Value; int id = ja.GetBigCraftableId(str); if (id == -1) { return new string[] { } } ; return(new[] { id.ToString() }); }
/// <summary> /// Gets ParentSheetIndex for Expanded Storages from Json Assets API. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private static void OnIdsAssigned(object sender, EventArgs e) { _monitor.Log("Loading Expanded Storage IDs", LogLevel.Info); var ids = _jsonAssetsApi.GetAllBigCraftableIds(); foreach (var expandedStorage in ExpandedStorage) { if (ids.TryGetValue(expandedStorage.StorageName, out var id)) { expandedStorage.ParentSheetIndex = id; } else { _monitor.Log($"Cannot convert {expandedStorage.StorageName} into Expanded Storage. Object is not loaded!", LogLevel.Warn); ExpandedStorage.Remove(expandedStorage); } } ItemExtensions.Init(ExpandedStorage); }
/// <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."); } }