public Sprite getSprite(string spriteSheet, string unityName) { //if it's a proper unityName with offset int uOffset = DmiIcon.getOffsetFromUnityName(unityName); if (!uOffset.Equals(-1)) { return(getSprite(spriteSheet, uOffset)); } //if it's something custom ,like tileconnect handwritten stuff DmiIcon icon = getIconBySheet(spriteSheet); if (!icon.getName().Equals("")) { DmiState dmiState = icon.states.Find(state => state.unityName.Equals(unityName)); if (dmiState != null) { int offset = dmiState.offset; if (icon.spriteSheet.Length > offset && !offset.Equals(-1)) { return(icon.spriteSheet[offset]); } } Logger.LogErrorFormat("Couldn't find sprite by UN: {0}({1}) in {2}", Category.DmMetadata, spriteSheet, unityName, icon.icon); } return(new Sprite()); }
public DmiState searchStateInIcon(string state, string[] icons, int dirs, bool deepSearch) { for (int i = 0; i < icons.Length; i++) { if (icons[i] != "" && state != "") { string s = getIconPath(icons[i]); if (Data.ContainsKey(s)) { DmiIcon icon = Data[s]; /*data.Values.ToList().Find(x => x.icon == s);*/ DmiState foundState = icon.states.Find(x => x.state == state && (dirs == -1 || x.dirs == dirs)); if (foundState != null) { Logger.LogTrace("foundState: " + foundState, Category.DmMetadata); return(foundState); } } } } if (deepSearch) { Logger.LogTrace("Could not find " + state + " in " + icons + ". Deepscanning!", Category.DmMetadata); return(searchState(state, dirs)); } Logger.LogTrace("Couldn't find state " + state + " using shallowSearch", Category.DmMetadata); return(null); }
public Sprite getSpriteFromLegacyName(string spriteSheet, string legacyUnityName) { string iPath = getIconPath(spriteSheet); if (legacyData.ContainsKey(iPath)) { DmiIcon icon = legacyData[iPath]; int legacyOffset = DmiIcon.getOffsetFromUnityName(legacyUnityName); int relativeOffset; DmiState legacyDmiState = icon.getStateAtOffset(legacyOffset, out relativeOffset); if (legacyDmiState != null && Data.ContainsKey(iPath)) { string legacyState = legacyDmiState.state; DmiState newState = Data[iPath].getState(legacyState); //searchStateInIcon(legacyState, spriteSheet, false); if (newState != null) { // if (legacyUnityName.Contains("shuttle_wall")) // { // Logger.Log("found ya!"); // } return(getSprite(spriteSheet, newState.offset + relativeOffset)); } } } Logger.LogErrorFormat("failed to getSpriteFromLegacyName: {0} {1}", Category.DmMetadata, spriteSheet, legacyUnityName); return(new Sprite()); }
/// <summary> /// Getting stuff from whatever states provided /// </summary> /// <param name="states">Expected order is {item_state, item_color, icon_state}</param> /// <returns></returns> private int TryGetClothingOffset(string[] states) { string[] onPlayerClothSheetHier = GetOnPlayerClothSheetHier(itemType); for (int i = 0; i < states.Length; i++) { if (String.IsNullOrEmpty(states[i])) { continue; } var icons = itemType == ItemType.None ? onPlayer : onPlayerClothSheetHier; DmiState state = dmi.searchStateInIcon(states[i], icons, 4, false); if (state == null) { continue; } return(state.offset); } //Logger.LogError("No clothing offset found! ClothHier=" + onPlayerClothSheetHier[0] + ", " + GetItemDebugInfo()); return(-1); }
public DmiState getState(string state) { DmiState foundState = states.Find(x => x.state == state); if (foundState != null) { // Logger.Log("foundState: "+ foundState); return(foundState); } // Logger.LogWarning("Couldn't find dmiIcon by state " + state); return(new DmiState()); }
public DmiIcon getIconByState(string state, bool inLegacy = false) { foreach (DmiIcon dmiIcon in inLegacy ? legacyData.Values : Data.Values) { DmiState foundState = dmiIcon.states.Find(x => x.state.Equals(state)); if (foundState != null) { Logger.LogTrace("foundState: " + foundState, Category.DmMetadata); return(dmiIcon); } } Logger.LogWarning("Couldn't find dmiIcon by state " + state, Category.DmMetadata); return(null); }
public DmiState getStateAtOffset(int offset, out int relativeOffset) { relativeOffset = 0; if (!offset.Equals(-1)) { DmiState foundState = states.Find(x => x.OwnsOffset(offset)); if (foundState != null) { relativeOffset = foundState.GetRelativeOffset(offset); return(foundState); } } return(new DmiState()); }
private /*static*/ int[] tryGetInHand() { if (item_state.Equals("")) { return(new[] { -1, -1 }); } string searchString = getMasterTypeHandsString(masterType); DmiState stateLH = dmi.searchStateInIconShallow(item_state, "mob/inhands/" + searchString + "_lefthand"); DmiState stateRH = dmi.searchStateInIconShallow(item_state, "mob/inhands/" + searchString + "_righthand"); return(new[] { stateLH == null ? -1 : stateLH.offset, stateRH == null ? -1 : stateRH.offset }); }
public DmiIcon getIconByState(string state, string scanPath) { Dictionary <string, DmiIcon> tmpData = Data.Where(p => p.Key.StartsWith(scanPath)).ToDictionary(p => p.Key, p => p.Value); foreach (DmiIcon dmiIcon in tmpData.Values) { DmiState foundState = dmiIcon.states.Find(x => x.state == state); if (foundState != null) { Logger.LogTrace("foundState: " + foundState, Category.DmMetadata); return(dmiIcon); } } Logger.LogTrace("Couldn't find dmiIcon by state " + state + " in " + scanPath + ", deepScanning!", Category.DmMetadata); return(getIconByState(state)); }
private static Sprite tryGetStateSprite(DmiIcon dmiIcon, string icon_state) { if (dmiIcon == null || dmiIcon.getName().Equals("")) { Debug.LogErrorFormat("DmiIcon '{0}' is null, unable to get state '{1}'", dmiIcon, icon_state); return(new Sprite()); } DmiState iState = dmiIcon.getState(icon_state); if (!iState.state.Equals("")) { return(dmiIcon.spriteSheet[iState.offset]); } Debug.LogErrorFormat("Failed to find inventory sprite '{1}' in icon '{0}'", dmiIcon.icon, icon_state); return(new Sprite()); }
public DmiState searchState(string state, int dirs) { if (state != "") { foreach (DmiIcon dmiIcon in Data.Values) { DmiState foundState = dmiIcon.states.Find(x => x.state.Equals(state) && (dirs == -1 || x.dirs == dirs)); if (foundState != null) { Logger.LogTrace("foundState: " + foundState, Category.DmMetadata); return(foundState); } } } Logger.LogWarning("Couldn't find state " + state + " in the entire datafile!", Category.DmMetadata); return(null); }
private int[] TryGetInHand() { if (String.IsNullOrEmpty(item_state)) { return(new[] { -1, -1 }); } string searchString = GetMasterTypeHandsString(spriteType); DmiState stateLH = dmi.searchStateInIconShallow(item_state, $"mob/inhands/{searchString}_lefthand"); DmiState stateRH = dmi.searchStateInIconShallow(item_state, $"mob/inhands/{searchString}_righthand"); return(new[] { stateLH == null ? -1 : stateLH.offset, stateRH == null ? -1 : stateRH.offset }); }
//getting stuff from whatever states provided (expected order is item_state, item_color, icon_state) private /*static*/ int tryGetClothingOffset(string[] states) { string[] onPlayerClothSheetHier = getOnPlayerClothSheetHier(itemType); for (int i = 0; i < states.Length; i++) { if (!states[i].Equals("")) { DmiState state = dmi.searchStateInIcon(states[i], itemType == ItemType.None ? onPlayer : onPlayerClothSheetHier, 4, false); if (state != null) { return(state.offset); } } } //Logger.LogError("No clothing offset found! ClothHier=" + onPlayerClothSheetHier[0] + ", " + getItemDebugInfo()); return(-1); }
private static Sprite tryGetStateSprite(DmiIcon dmiIcon, string icon_state) { if (dmiIcon == null || dmiIcon.getName().Equals("")) { Logger.Log($"DmiIcon '{dmiIcon}' is null, unable to get state '{icon_state}'", Category.DmMetadata); return(new Sprite()); } DmiState iState = dmiIcon.getState(icon_state); if (!iState.state.Equals("")) { return(dmiIcon.spriteSheet[iState.offset]); } Logger.Log($"Failed to find inventory sprite '{icon_state}' in icon '{dmiIcon.icon}'", Category.DmMetadata); return(new Sprite()); }
protected bool Equals(DmiState other) { return(string.Equals(state, other.state) && dirs == other.dirs); }
private void OnEnable() { //todo: make more methods static //randomize clothing! uncomment only if you spawn without any clothes on! randomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierarchy.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { Debug.Log("Item DMI data loading..."); dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { Debug.Log("Item DM data loading..."); dm = Resources.Load("DmObjectData") as DmObjectData; } //raw dictionary of attributes dmDic = dm.getObject(hier); //basic attributes name = tryGetAttr("name"); desc = tryGetAttr("desc"); icon_state = tryGetAttr("icon_state"); item_state = tryGetAttr("item_state"); icon = tryGetAttr("icon"); masterType = getMasterType(hier); iType = getItemType(hier, getInvIconPrefix(masterType)); invSheetPaths = getItemClothSheetHier(iType); // size = getItemSize(tryGetAttr("w_class")); int[] inHandOffsets = tryGetInHand(); inHandLeft = inHandOffsets[0]; inHandRight = inHandOffsets[1]; inventoryIcon = tryGetInventoryIcon(); clothingOffset = tryGetClothingOffset(); //determine item type via sheet name if hier name failed if (iType == ItemType.None) { iType = getItemType(inventoryIcon.getName()); } //inventory item sprite DmiState iState = inventoryIcon.getState(icon_state); Sprite stateSprite = inventoryIcon.spriteSheet[iState.offset]; //finally setting things inHandReferenceLeft = inHandLeft; inHandReferenceRight = inHandRight; clothingReference = clothingOffset; type = iType; itemName = name; itemDescription = desc; GetComponentInChildren <SpriteRenderer>().sprite = stateSprite; Debug.Log(name + " size=" + size + " type=" + type + " spriteType=" + spriteType + " (" + desc + ") : " + icon_state + " / " + item_state + " / C: " + clothingReference + ", L: " + inHandReferenceLeft + ", R: " + inHandReferenceRight + ", I: " + inventoryIcon.icon + '\n' + dmDic.Keys.Aggregate("", (current, key) => current + (key + ": ") + dmDic[key] + "\n")); }