/// <summary> /// This finds the best suitable sprite to use when presenting this actor to the user. /// </summary> public StateStructure.FrameInfo FindSuitableSprite() { // Info: actual sprites are resolved in ThingTypeInfo.SetupSpriteFrame() - mxd // Sprite forced? if (HasPropertyWithValue("$sprite")) { string sprite = GetPropertyValueString("$sprite", 0, true); //mxd //mxd. Valid when internal or exists if (sprite.StartsWith(DataManager.INTERNAL_PREFIX, StringComparison.OrdinalIgnoreCase) || General.Map.Data.GetSpriteExists(sprite)) { return new StateStructure.FrameInfo { Sprite = sprite } } ; //mxd. Bitch and moan General.ErrorLogger.Add(ErrorType.Warning, "DECORATE warning in " + classname + ":" + doomednum + ". The sprite \"" + sprite + "\" assigned by the \"$sprite\" property does not exist."); } //mxd. Try to get a suitable sprite from our hardcoded states list foreach (string state in SPRITE_CHECK_STATES) { if (!HasState(state)) { continue; } StateStructure s = GetState(state); StateStructure.FrameInfo info = s.GetSprite(0); if (!string.IsNullOrEmpty(info.Sprite)) { return(info); } } // Still no sprite found? then just pick the first we can find Dictionary <string, StateStructure> list = GetAllStates(); foreach (StateStructure s in list.Values) { StateStructure.FrameInfo info = s.GetSprite(0); if (!string.IsNullOrEmpty(info.Sprite)) { return(info); } } //mxd. No dice... return(null); } #endregion }
/// <summary> /// This finds the best suitable sprite to use when presenting this actor to the user. /// </summary> public StateStructure.FrameInfo FindSuitableSprite() { // Info: actual sprites are resolved in ThingTypeInfo.SetupSpriteFrame() - mxd // Sprite forced? if (HasPropertyWithValue("$sprite")) { string sprite = GetPropertyValueString("$sprite", 0, true); //mxd //mxd. Valid when internal or exists if (sprite.StartsWith(DataManager.INTERNAL_PREFIX, StringComparison.OrdinalIgnoreCase) || General.Map.Data.GetSpriteExists(sprite)) { return new StateStructure.FrameInfo { Sprite = sprite } } ; //mxd. Bitch and moan General.ErrorLogger.Add(ErrorType.Warning, "DECORATE warning in " + classname + ":" + doomednum + ". The sprite \"" + sprite + "\" assigned by the \"$sprite\" property does not exist."); } StateStructure.FrameInfo firstNonTntInfo = null; StateStructure.FrameInfo firstInfo = null; // Pick the first we can find (including and not including TNT1) Dictionary <string, StateStructure> list = GetAllStates(); foreach (StateStructure s in list.Values) { StateStructure.FrameInfo info = s.GetSprite(0); if (string.IsNullOrEmpty(info.Sprite)) { continue; } if (!info.IsEmpty()) { firstNonTntInfo = info; } if (firstInfo == null) { firstInfo = info; } if (firstNonTntInfo != null) { break; } } //mxd. Try to get a suitable sprite from our hardcoded states list StateStructure.FrameInfo lastNonTntInfo = null; StateStructure.FrameInfo lastInfo = null; foreach (string state in SPRITE_CHECK_STATES) { if (!HasState(state)) { continue; } StateStructure s = GetState(state); StateStructure.FrameInfo info = s.GetSprite(0); //if(!string.IsNullOrEmpty(info.Sprite)) return info; if (string.IsNullOrEmpty(info.Sprite)) { continue; } if (!info.IsEmpty()) { lastNonTntInfo = info; } if (lastInfo == null) { lastInfo = info; } if (lastNonTntInfo != null) { break; } } // [ZZ] return whatever is there by priority. try to pick non-TNT1 frames. StateStructure.FrameInfo[] infos = new StateStructure.FrameInfo[] { lastNonTntInfo, lastInfo, firstNonTntInfo, firstInfo }; foreach (StateStructure.FrameInfo info in infos) { if (info != null) { return(info); } } //mxd. No dice... return(null); }