/// <summary> /// Load frames from WzSubProperty or WzCanvasProperty /// </summary> /// <param name="texturePool"></param> /// <param name="source"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="device"></param> /// <param name="usedProps"></param> /// <param name="spineAni">Spine animation path</param> /// <returns></returns> private static List <IDXObject> LoadFrames(TexturePool texturePool, WzImageProperty source, int x, int y, GraphicsDevice device, ref List <WzObject> usedProps, string spineAni = null) { List <IDXObject> frames = new List <IDXObject>(); source = WzInfoTools.GetRealProperty(source); if (source is WzSubProperty property1 && property1.WzProperties.Count == 1) { source = property1.WzProperties[0]; } if (source is WzCanvasProperty property) //one-frame { bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, spineAni); if (!bLoadedSpine) { string canvasBitmapPath = property.FullPath; Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath); if (textureFromCache != null) { source.MSTag = textureFromCache; } else { source.MSTag = property.GetLinkedWzCanvasBitmap().ToTexture2D(device); // add to cache texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)source.MSTag); } } usedProps.Add(source); if (source.MSTagSpine != null) { WzSpineObject spineObject = (WzSpineObject)source.MSTagSpine; System.Drawing.PointF origin = property.GetCanvasOriginPosition(); frames.Add(new DXSpineObject(spineObject, x, y, origin)); } else if (source.MSTag != null) { Texture2D texture = (Texture2D)source.MSTag; System.Drawing.PointF origin = property.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture)); } else // fallback { Texture2D texture = Properties.Resources.placeholder.ToTexture2D(device); System.Drawing.PointF origin = property.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture)); } } else if (source is WzSubProperty) // animated { WzImageProperty _frameProp; int i = 0; while ((_frameProp = WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null) { if (_frameProp is WzSubProperty) // issue with 867119250 { frames.AddRange(LoadFrames(texturePool, _frameProp, x, y, device, ref usedProps, null)); } else { WzCanvasProperty frameProp; if (_frameProp is WzUOLProperty) // some could be UOL. Ex: 321100000 Mirror world: [Mirror World] Leafre { WzObject linkVal = ((WzUOLProperty)_frameProp).LinkValue; if (linkVal is WzCanvasProperty linkCanvas) { frameProp = linkCanvas; } else { continue; } } else { frameProp = (WzCanvasProperty)_frameProp; } int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100); bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, spineAni); if (!bLoadedSpine) { if (frameProp.MSTag == null) { string canvasBitmapPath = frameProp.FullPath; Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath); if (textureFromCache != null) { frameProp.MSTag = textureFromCache; } else { frameProp.MSTag = frameProp.GetLinkedWzCanvasBitmap().ToTexture2D(device); // add to cache texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)frameProp.MSTag); } } } usedProps.Add(frameProp); if (frameProp.MSTagSpine != null) { WzSpineObject spineObject = (WzSpineObject)frameProp.MSTagSpine; System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); frames.Add(new DXSpineObject(spineObject, x, y, origin, delay)); } else if (frameProp.MSTag != null) { Texture2D texture = (Texture2D)frameProp.MSTag; System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay)); } else { Texture2D texture = Properties.Resources.placeholder.ToTexture2D(device); System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay)); } } } } return(frames); }
/// <summary> /// Map item /// </summary> /// <param name="texturePool"></param> /// <param name="source"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="mapCenterX"></param> /// <param name="mapCenterY"></param> /// <param name="device"></param> /// <param name="usedProps"></param> /// <param name="flip"></param> /// <returns></returns> public static BaseDXDrawableItem CreateMapItemFromProperty(TexturePool texturePool, WzImageProperty source, int x, int y, Point mapCenter, GraphicsDevice device, ref List <WzObject> usedProps, bool flip) { BaseDXDrawableItem mapItem = new BaseDXDrawableItem(LoadFrames(texturePool, source, x, y, device, ref usedProps), flip); return(mapItem); }
/// <summary> /// /// </summary> /// <param name="texturePool"></param> /// <param name="gameParent"></param> /// <param name="portalInstance"></param> /// <param name="device"></param> /// <param name="usedProps"></param> /// <returns></returns> public static PortalItem CreatePortalFromProperty(TexturePool texturePool, WzSubProperty gameParent, PortalInstance portalInstance, GraphicsDevice device, ref List <WzObject> usedProps) { PortalInfo portalInfo = (PortalInfo)portalInstance.BaseInfo; if (portalInstance.pt == PortalType.PORTALTYPE_STARTPOINT || portalInstance.pt == PortalType.PORTALTYPE_INVISIBLE || //portalInstance.pt == PortalType.PORTALTYPE_CHANGABLE_INVISIBLE || portalInstance.pt == PortalType.PORTALTYPE_SCRIPT_INVISIBLE || portalInstance.pt == PortalType.PORTALTYPE_SCRIPT || portalInstance.pt == PortalType.PORTALTYPE_COLLISION || portalInstance.pt == PortalType.PORTALTYPE_COLLISION_SCRIPT || portalInstance.pt == PortalType.PORTALTYPE_COLLISION_CUSTOM_IMPACT || // springs in Mechanical grave 350040240 portalInstance.pt == PortalType.PORTALTYPE_COLLISION_VERTICAL_JUMP) // vertical spring actually { return(null); } List <IDXObject> frames = new List <IDXObject>(); // All frames "stand", "speak" "blink" "hair", "angry", "wink" etc //string portalType = portalInstance.pt; //int portalId = Program.InfoManager.PortalIdByType[portalInstance.pt]; WzSubProperty portalTypeProperty = (WzSubProperty)gameParent[portalInstance.pt]; if (portalTypeProperty == null) { portalTypeProperty = (WzSubProperty)gameParent["pv"]; } else { // Support for older versions of MapleStory where 'pv' is a subproperty for the image frame than a collection of subproperty of frames if (portalTypeProperty["0"] is WzCanvasProperty) { frames.AddRange(LoadFrames(texturePool, portalTypeProperty, portalInstance.X, portalInstance.Y, device, ref usedProps)); portalTypeProperty = null; } } if (portalTypeProperty != null) { WzSubProperty portalImageProperty = (WzSubProperty)portalTypeProperty[portalInstance.image == null ? "default" : portalInstance.image]; if (portalImageProperty != null) { WzSubProperty framesPropertyParent; if (portalImageProperty["portalContinue"] != null) { framesPropertyParent = (WzSubProperty)portalImageProperty["portalContinue"]; } else { framesPropertyParent = (WzSubProperty)portalImageProperty; } if (framesPropertyParent != null) { frames.AddRange(LoadFrames(texturePool, framesPropertyParent, portalInstance.X, portalInstance.Y, device, ref usedProps)); } } } if (frames.Count == 0) { return(null); } return(new PortalItem(portalInstance, frames)); }
/// <summary> /// Load frames from WzSubProperty or WzCanvasProperty /// </summary> /// <param name="texturePool"></param> /// <param name="source"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="device"></param> /// <param name="usedProps"></param> /// <param name="spineAni">Spine animation path</param> /// <returns></returns> private static List <IDXObject> LoadFrames(TexturePool texturePool, WzImageProperty source, int x, int y, GraphicsDevice device, ref List <WzObject> usedProps, string spineAni = null) { List <IDXObject> frames = new List <IDXObject>(); source = WzInfoTools.GetRealProperty(source); if (source is WzSubProperty property1 && property1.WzProperties.Count == 1) { source = property1.WzProperties[0]; } if (source is WzCanvasProperty property) //one-frame { bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, spineAni); if (!bLoadedSpine) { string canvasBitmapPath = property.FullPath; Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath); if (textureFromCache != null) { source.MSTag = textureFromCache; } else { source.MSTag = BoardItem.TextureFromBitmap(device, property.GetLinkedWzCanvasBitmap()); // add to cache texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)source.MSTag); } } usedProps.Add(source); if (source.MSTagSpine != null) { WzSpineObject spineObject = (WzSpineObject)source.MSTagSpine; System.Drawing.PointF origin = property.GetCanvasOriginPosition(); frames.Add(new DXSpineObject(spineObject, x, y, origin)); } else if (source.MSTag != null) { Texture2D texture = (Texture2D)source.MSTag; System.Drawing.PointF origin = property.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture)); } else // fallback { Texture2D texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder); System.Drawing.PointF origin = property.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture)); } } else if (source is WzSubProperty) // animated { WzCanvasProperty frameProp; int i = 0; while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null) { int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100); bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, spineAni); if (!bLoadedSpine) { if (frameProp.MSTag == null) { string canvasBitmapPath = frameProp.FullPath; Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath); if (textureFromCache != null) { frameProp.MSTag = textureFromCache; } else { frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap()); // add to cache texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)frameProp.MSTag); } } } usedProps.Add(frameProp); if (frameProp.MSTagSpine != null) { WzSpineObject spineObject = (WzSpineObject)frameProp.MSTagSpine; System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); frames.Add(new DXSpineObject(spineObject, x, y, origin, delay)); } else if (frameProp.MSTag != null) { Texture2D texture = (Texture2D)frameProp.MSTag; System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay)); } else { Texture2D texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder); System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay)); } } } return(frames); }