public static Template ConstructTemplate(TemplateDoc tmpd, MixTemplate mixt, Size sizTile) { Bitmap bm = new Bitmap(mixt.XTileCount * sizTile.Width, mixt.YTileCount * sizTile.Height); Graphics g = Graphics.FromImage(bm); g.Clear(Color.FromArgb(255, 0, 255)); Bitmap bmNew = new Bitmap(sizTile.Width, sizTile.Height, PixelFormat.Format24bppRgb); Graphics gNew = Graphics.FromImage(bmNew); for (int tx = 0; tx < mixt.XTileCount; tx++) { for (int ty = 0; ty < mixt.YTileCount; ty++) { Bitmap bmT = mixt.TileBitmaps[tx + ty * mixt.XTileCount]; if (bmT == null) { continue; } gNew.DrawImage(bmT, 0, 0, sizTile.Width, sizTile.Height); g.DrawImageUnscaled(bmNew, tx * sizTile.Width, ty * sizTile.Height, sizTile.Width, sizTile.Height); } } gNew.Dispose(); bmNew.Dispose(); g.Dispose(); bm.RotateFlip(RotateFlipType.RotateNoneFlipX); return(new Template(tmpd, bm, mixt.Index.ToString())); }
public TemplatePos(MixTemplate mixt, int txOrigin, int tyOrigin, bool[,] afMapped) { m_mixt = mixt; m_txOrigin = txOrigin; m_tyOrigin = tyOrigin; m_afMapped = afMapped; }
public MixMap(Stream stm, MixTemplate[] amixt) { m_amixt = amixt; BinaryReader brdr = new BinaryReader(stm); m_acell = new Cell[64,64]; for (int iCell = 0; iCell < 64 * 64; iCell++) { m_acell[iCell / 64, iCell % 64].iTemplate = (uint)brdr.ReadByte(); m_acell[iCell / 64, iCell % 64].iTile = (uint)brdr.ReadByte(); } brdr.Close(); }
TemplatePos[] GetTemplatePositions() { bool[,] afCellTaken = new bool[64, 64]; ArrayList alsTemplPos = new ArrayList(); for (int ty = 0; ty < 64; ty++) { for (int tx = 0; tx < 64; tx++) { if (afCellTaken[ty, tx]) { continue; } if (m_acell[ty, tx].iTemplate == 255) { continue; } // Find out what part of this template matches MixTemplate mixt = m_amixt[m_acell[ty, tx].iTemplate]; // scg03ea has an invalid iTemplate outside the map bounds if (mixt == null) { continue; } int ctxTmpl = mixt.XTileCount; int ctyTmpl = mixt.YTileCount; bool[,] afMapped = new bool[ctyTmpl, ctxTmpl]; int txTmpl = (int)m_acell[ty, tx].iTile % ctxTmpl; int tyTmpl = (int)m_acell[ty, tx].iTile / ctxTmpl; int txOrigin = tx - txTmpl; int tyOrigin = ty - tyTmpl; for (tyTmpl = 0; tyTmpl < ctyTmpl; tyTmpl++) { for (txTmpl = 0; txTmpl < ctxTmpl; txTmpl++) { int txT = txOrigin + txTmpl; int tyT = tyOrigin + tyTmpl; if (txT < 0 || tyT < 0 || txT >= 64 || tyT >= 64) { continue; } if (afCellTaken[tyT, txT]) { continue; } Cell cell = m_acell[tyT, txT]; if (cell.iTemplate == 255) { continue; } if (cell.iTemplate != m_acell[ty, tx].iTemplate) { continue; } if (cell.iTile != tyTmpl * ctxTmpl + txTmpl) { continue; } afMapped[tyTmpl, txTmpl] = true; afCellTaken[tyT, txT] = true; } } alsTemplPos.Add(new TemplatePos(mixt, txOrigin, tyOrigin, afMapped)); } } return((TemplatePos[])alsTemplPos.ToArray(typeof(TemplatePos))); }
public static MixMap LoadMap(Stream stm, MixTemplate[] amixt) { MixReader mixr = new MixReader("general.mix"); MixMap map = new MixMap(stm, amixt); mixr.Dispose(); return map; }
public static int ImportTemplates(MixTemplate[] amixt, TemplateDoc tmpd) { Size sizTile = tmpd.TileSize; ArrayList alsTmpl = new ArrayList(); int cImages = 0; foreach (MixTemplate mixt in amixt) { if (mixt == null) continue; cImages += mixt.ImageCount; alsTmpl.Add(ConstructTemplate(tmpd, mixt, sizTile)); } tmpd.AddTemplates((Template[])alsTmpl.ToArray(typeof(Template))); return cImages; }
public static Template ConstructTemplate(TemplateDoc tmpd, MixTemplate mixt, Size sizTile) { Bitmap bm = new Bitmap(mixt.XTileCount * sizTile.Width, mixt.YTileCount * sizTile.Height); Graphics g = Graphics.FromImage(bm); g.Clear(Color.FromArgb(255, 0, 255)); Bitmap bmNew = new Bitmap(sizTile.Width, sizTile.Height, PixelFormat.Format24bppRgb); Graphics gNew = Graphics.FromImage(bmNew); for (int tx = 0; tx < mixt.XTileCount; tx++) { for (int ty = 0; ty < mixt.YTileCount; ty++) { Bitmap bmT = mixt.TileBitmaps[tx + ty * mixt.XTileCount]; if (bmT == null) continue; gNew.DrawImage(bmT, 0, 0, sizTile.Width, sizTile.Height); g.DrawImageUnscaled(bmNew, tx * sizTile.Width, ty * sizTile.Height, sizTile.Width, sizTile.Height); } } gNew.Dispose(); bmNew.Dispose(); g.Dispose(); bm.RotateFlip(RotateFlipType.RotateNoneFlipX); return new Template(tmpd, bm, mixt.Index.ToString()); }