public static Spritesheet Load(string filename) { string lowerFilename = filename.ToLower(); if (cache.ContainsKey(lowerFilename)) { return(cache[lowerFilename]); } Spritesheet spritesheet = null; try { var dcc = DCC.Load(filename + ".dcc"); spritesheet = dcc; spritesheet.directionCount = dcc.directionCount; } catch (System.IO.FileNotFoundException) { var dc6 = DC6.Load(filename + ".dc6"); spritesheet = dc6; spritesheet.directionCount = dc6.directionCount; } cache.Add(lowerFilename, spritesheet); return(spritesheet); }
static DC6 Load(Stream stream, BinaryReader reader, byte[] bytes, int textureSize = -1, bool loadAllDirections = false) { var dc6 = new DC6(); reader.ReadInt32(); dc6.directionCount = reader.ReadInt32(); dc6.framesPerDirection = reader.ReadInt32(); dc6.directions = new Direction[dc6.directionCount]; dc6.offsets = new int[dc6.directionCount * dc6.framesPerDirection]; dc6.bytes = bytes; dc6.textureSize = textureSize; for (int i = 0; i < dc6.offsets.Length; ++i) { dc6.offsets[i] = reader.ReadInt32(); } if (loadAllDirections) { for (int i = 0; i < dc6.directionCount; ++i) { dc6.LoadDirection(stream, reader, i); } } return(dc6); }
static public DC6 Load(string filename, bool mpq = true, int textureSize = -1, bool loadAllDirections = false) { UnityEngine.Profiling.Profiler.BeginSample("DC6.DecodeDirection"); try { Palette.LoadPalette(0); var bytes = mpq ? Mpq.ReadAllBytes(filename) : File.ReadAllBytes(filename); using (var stream = new MemoryStream(bytes)) using (var reader = new BinaryReader(stream)) { int version1 = reader.ReadInt32(); var version2 = reader.ReadInt32(); var version3 = reader.ReadInt32(); if (version1 != 6 || version2 != 1 || version3 != 0) { Debug.LogWarning("Unknown dc6 version " + version1 + " " + version2 + " " + version3); return(null); } DC6 dc6 = Load(stream, reader, bytes, textureSize, loadAllDirections); return(dc6); } } finally { UnityEngine.Profiling.Profiler.EndSample(); } }
static public void ConvertDC6ToPNG() { var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); Palette.LoadPalette(0); DC6 dc6 = DC6.Load(assetPath, loadAllDirections: true, mpq: false); SaveTextures(assetPath, dc6.textures); }
private void OnHandsItemChanged(Item item) { if (item != null) { var dc6 = DC6.Load(item.invFile, palette, loadAllDirections: true); var texture = dc6.textures[0]; var frame = dc6.directions[0].frames[0]; var hotSpot = new Vector2(frame.width / 2, frame.height / 2); SoftwareCursor.SetCursor(texture, hotSpot); Cursor.visible = false; } else { SoftwareCursor.SetCursor(null); Cursor.visible = true; } }
public static Pickup Create(Vector3 position, string flippyFile, string name, string title = null, int dir = 0) { position = Iso.MapToIso(position); if (!CollisionMap.Fit(position, out position, mask: CollisionLayers.Item)) { Debug.LogError("Can't fit pickup"); return(null); } position = Iso.MapToWorld(position); var gameObject = new GameObject(name); gameObject.transform.position = position; var spritesheet = DC6.Load(flippyFile); var animator = gameObject.AddComponent <SpriteAnimator>(); animator.sprites = spritesheet.GetSprites(dir); animator.loop = false; var pickup = gameObject.AddComponent <Pickup>(); pickup.title = title; return(pickup); }
public static Loot Create(Vector3 position, string flippyFile, string name, string title = null, int dir = 0) { position = Iso.MapToIso(position); if (!CollisionMap.Fit(position, out position, mask: CollisionLayers.Item)) { Debug.LogError("Can't fit loot"); return(null); } position = Iso.MapToWorld(position); var gameObject = new GameObject(name); gameObject.transform.position = position; var palette = Palette.GetPalette(PaletteType.Act1); var spritesheet = DC6.Load(flippyFile, palette); var animator = gameObject.AddComponent <SpriteAnimator>(); animator.SetSprites(spritesheet.GetSprites(dir)); animator.loop = false; var loot = gameObject.AddComponent <Loot>(); loot.title = title; return(loot); }
public static Spritesheet Load(string filename, PaletteType paletteType = PaletteType.Act1) { string lowerFilename = filename.ToLower(); if (cache.ContainsKey(lowerFilename)) { return(cache[lowerFilename]); } var palette = Palette.GetPalette(paletteType); Spritesheet spritesheet = null; try { var dcc = DCC.Load(filename + ".dcc", palette); spritesheet = dcc; spritesheet.directionCount = dcc.directionCount; } catch (System.IO.FileNotFoundException) { try { var dc6 = DC6.Load(filename + ".dc6", palette); spritesheet = dc6; spritesheet.directionCount = dc6.directionCount; } catch (System.IO.FileNotFoundException) { Debug.LogWarning(filename + " not found in MPQ"); } } cache.Add(lowerFilename, spritesheet); return(spritesheet); }
static public void CreateFontFromDC6() { var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); var name = Path.GetFileNameWithoutExtension(assetPath); int textureSize = 1024; if (name.Contains("font16") || name.Contains("font24") || name.Contains("font30")) { textureSize = 512; } var dc6 = DC6.Load(assetPath, mpq: false, textureSize: textureSize, loadAllDirections: true); if (dc6.textures.Count != 1) { Debug.LogError("Font not fit into a single texture"); return; } var metrics = File.ReadAllText(Path.GetDirectoryName(assetPath) + "/" + name + ".txt").Split(','); var frames = dc6.directions[0].frames; var characterInfo = new CharacterInfo[dc6.framesPerDirection]; for (int i = 0; i < frames.Length; i++) { //int glyphHeight = int.Parse(metrics[i * 2].Trim()); // font16 - all 10, should be used as a line height calculations (like advance for horizontal axis) int glyphWidth = int.Parse(metrics[i * 2 + 1].Trim()); var frame = frames[i]; characterInfo[i].index = i; characterInfo[i].advance = glyphWidth; characterInfo[i].minX = 0; characterInfo[i].maxX = glyphWidth; characterInfo[i].minY = 0; characterInfo[i].maxY = frame.height; // doesn't seem to change anything characterInfo[i].glyphWidth = glyphWidth; characterInfo[i].glyphHeight = frame.height; var uv = new Rect( frame.textureX / (float)textureSize, (textureSize - frame.textureY - frame.height) / (float)textureSize, glyphWidth / (float)textureSize, frame.height / (float)textureSize); characterInfo[i].uvBottomLeft = new Vector2(uv.xMin, uv.yMin); characterInfo[i].uvBottomRight = new Vector2(uv.xMax, uv.yMin); characterInfo[i].uvTopLeft = new Vector2(uv.xMin, uv.yMax); characterInfo[i].uvTopRight = new Vector2(uv.xMax, uv.yMax); } var filepath = "Assets/Fonts/" + name; var texture = dc6.textures[0]; var pngData = texture.EncodeToPNG(); Object.DestroyImmediate(texture); var texturePath = filepath + ".png"; File.WriteAllBytes(texturePath, pngData); AssetDatabase.ImportAsset(texturePath); var fontPath = filepath + ".fontsettings"; var font = AssetDatabase.LoadAssetAtPath <Font>(fontPath); if (font) { font.characterInfo = characterInfo; EditorUtility.SetDirty(font); AssetDatabase.SaveAssets(); } else { font = new Font(name); font.characterInfo = characterInfo; AssetDatabase.CreateAsset(font, fontPath); AssetDatabase.ImportAsset(fontPath); } var serializedFont = File.ReadAllBytes(fontPath); File.WriteAllText(fontPath, ""); AssetDatabase.ImportAsset(fontPath); File.WriteAllBytes(fontPath, serializedFont); }