public static TMXColor GetColorFromProperty(this IPropertyCollection collection, string key) { if (collection.TryGetValue <string>(key, out PropertyValue value)) { return(TMXColor.FromString(value)); } return(null); }
public static Location GetOffsetProperties(this IPropertyCollection collection) { int x = 0; int y = 0; if (collection.TryGetValue <int>("@OffsetX", out PropertyValue xValue)) { x = xValue; } if (collection.TryGetValue <int>("@OffsetY", out PropertyValue yValue)) { y = yValue; } return(new Location( x, y )); }
public static bool TryGetValue <T>(this IPropertyCollection collection, string key, out PropertyValue value) { if (collection.TryGetValue(key, out PropertyValue prop) && prop.Type.IsAssignableFrom(typeof(T))) { value = prop; return(true); } value = null; return(false); }
public bool TryGetValue(string key, out PropertyValue propertyValue) { IPropertyCollection tilesheetProperties = m_tileSheet.Properties; return(tilesheetProperties.TryGetValue(IndexKey(key), out propertyValue)); }
/// <summary> /// Checks the tile property for shops, and open them /// </summary> /// <param name="tileProperty"></param> /// <param name="e"></param> private void CheckForShopToOpen(IPropertyCollection tileProperty, StardewModdingAPI.Events.ButtonPressedEventArgs e) { //check if there is a Shop property on clicked tile tileProperty.TryGetValue("Shop", out PropertyValue shopProperty); if (VerboseLogging) { monitor.Log($"Shop Property value is: {shopProperty}"); } if (shopProperty != null) //There was a `Shop` property so attempt to open shop { //check if the property is for a vanilla shop, and gets the shopmenu for that shop if it exists IClickableMenu menu = TileUtility.CheckVanillaShop(shopProperty, out bool warpingShop); if (menu != null) { if (warpingShop) { SourceLocation = Game1.currentLocation; _playerPos = Game1.player.position.Get(); } //stop the click action from going through after the menu has been opened helper.Input.Suppress(e.Button); Game1.activeClickableMenu = menu; } else //no vanilla shop found { //Extract the tile property value string shopName = shopProperty.ToString(); if (ShopManager.ItemShops.ContainsKey(shopName)) { //stop the click action from going through after the menu has been opened helper.Input.Suppress(e.Button); ShopManager.ItemShops[shopName].DisplayShop(); } else { Monitor.Log($"A Shop tile was clicked, but a shop by the name \"{shopName}\" " + $"was not found.", LogLevel.Debug); } } } else //no shop property found { tileProperty.TryGetValue("AnimalShop", out shopProperty); //see if there's an AnimalShop property if (shopProperty != null) //no animal shop found { string shopName = shopProperty.ToString(); if (ShopManager.AnimalShops.ContainsKey(shopName)) { //stop the click action from going through after the menu has been opened helper.Input.Suppress(e.Button); ShopManager.AnimalShops[shopName].DisplayShop(); } else { Monitor.Log($"An Animal Shop tile was clicked, but a shop by the name \"{shopName}\" " + $"was not found.", LogLevel.Debug); } } } //end shopProperty null check }