public LuaArgs saveTGA(LuaArgs args) { var image = args.GetObject <LuaImage>(0).Image; var palette = args.GetObject <LuaPalette>(1).Palette; try { if (args.IsNil(2)) { // Save to a string and return it using (var stream = new MemoryStream()) { TGAImage.Encode(image, palette, stream); return(new LuaArgs(stream.ToArray())); } } else { // Save to a stream var file = args.GetObject <LuaFile>(2); CheckFileMode(file, "tga", LuaFileOpenMode.Write, LuaFileContentType.Binary); TGAImage.Encode(image, palette, file.InnerStream); return(LuaArgs.Empty); } } catch (IOException e) { throw new LuaError(e.Message); } }
public LuaArgs drawMap(LuaArgs args) { int startX = args.GetInt(0); int startY = args.GetInt(1); var map = args.GetObject <LuaImage>(2).Image; var tileset = args.GetObject <LuaImage>(3).Image; int scale = args.IsNil(4) ? 1 : args.GetInt(4); if (scale <= 0) { throw new LuaError("Scale must be an integer 1 or greater"); } m_graphics.DrawMap(startX, startY, map, tileset, scale); return(LuaArgs.Empty); }
public LuaArgs output(LuaArgs args) { if (args.IsNil(0)) { return(new LuaArgs(m_output.Value)); } else if (args.IsObject <LuaFile>(0)) { m_output.Value = args.GetObject <LuaFile>(0); return(LuaArgs.Empty); } else { var path = new FilePath(args.GetString(0)); try { m_output.Value = new LuaFile(m_fileSystem.OpenForWrite(path, false)); return(LuaArgs.Empty); } catch (IOException e) { throw new LuaError(e.Message); } } }
public LuaArgs newFont(LuaArgs args) { var image = args.GetObject <LuaImage>(0); var characters = args.GetString(1); var characterWidth = args.GetInt(2); var characterHeight = args.GetInt(3); if (characterWidth <= 0) { throw new LuaError("Character width must be positive"); } if (characterWidth > image.Image.Width) { throw new LuaError("Character width must be less than image width"); } if (characterHeight <= 0) { throw new LuaError("Character height must be positive"); } if (characterHeight > image.Image.Height) { throw new LuaError("Character width must be less than image height"); } var font = new Font(image.Image, characters, characterWidth, characterHeight, true); return(new LuaArgs(new LuaFont(font, image))); }
public LuaArgs boot(LuaArgs args) { var mount = args.GetObject <LuaMount>(0); RequestBoot(mount); throw new LuaYield(LuaArgs.Empty, delegate { return(LuaArgs.Empty); }); }
public LuaArgs blit(LuaArgs args) { int x = args.GetInt(0); int y = args.GetInt(1); var image = args.GetObject <LuaImage>(2).Image; CheckWritable(); Image.Blit(image, x, y); return(LuaArgs.Empty); }
public LuaArgs close(LuaArgs args) { if (args.IsNil(0)) { return(m_output.Value.close(LuaArgs.Empty)); } else { var file = args.GetObject <LuaFile>(0); return(file.close(LuaArgs.Empty)); } }
public LuaArgs xorImage(LuaArgs args) { int startX = args.GetInt(0); int startY = args.GetInt(1); var image = args.GetObject <LuaImage>(2).Image; int scale = args.IsNil(3) ? 1 : args.GetInt(3); if (scale <= 0) { throw new LuaError("Scale must be an integer 1 or greater"); } m_graphics.XorImage(startX, startY, image, scale); return(LuaArgs.Empty); }
public LuaArgs type(LuaArgs args) { if (args.IsObject <LuaFile>(0)) { var file = args.GetObject <LuaFile>(0); if (file.IsOpen) { return(new LuaArgs("file")); } else { return(new LuaArgs("closed file")); } } return(LuaArgs.Nil); }
public LuaArgs setFont(LuaArgs args) { var font = args.IsNil(0) ? null : args.GetObject <LuaFont>(0); if (font != null) { m_graphics.Font = font.Font; m_font.Value = font; } else { m_graphics.Font = null; m_font.Value = null; } return(LuaArgs.Empty); }
public LuaArgs mount(LuaArgs args) { try { var mount = args.GetObject <LuaMount>(0); var path = new FilePath(args.GetString(1)); var subPath = args.IsNil(2) ? FilePath.Empty : new FilePath(args.GetString(2)); var readOnly = args.IsNil(3) ? false : args.GetBool(3); m_fileSystem.Mount(mount, path, subPath, readOnly); return(LuaArgs.Empty); } catch (IOException e) { throw new LuaError(e.Message); } }
public LuaArgs setPalette(LuaArgs args) { var palette = args.IsNil(0) ? null : args.GetObject <LuaPalette>(0); if (m_fixedPalette != null) { throw new LuaError("Cannot change a fixed palette"); } if (palette != null) { m_palette.Value = palette; } else { m_palette.Value = null; } return(LuaArgs.Empty); }
public LuaArgs setImage(LuaArgs args) { var image = args.IsNil(0) ? null : args.GetObject <LuaImage>(0); if (image != null) { if (image.Image.Width != Width || image.Image.Height != Height) { throw new LuaError("Display images must be the same size as the display"); } m_image.Value = image; } else { m_image.Value = null; } return(LuaArgs.Empty); }
public LuaArgs setTarget(LuaArgs args) { var target = args.IsNil(0) ? null : args.GetObject <LuaImage>(0); if (target != null) { if (target.ReadOnly) { throw new LuaError("Cannot target a readonly image"); } m_graphics.Target = target.Image; m_target.Value = target; } else { m_graphics.Target = null; m_target.Value = null; } return(LuaArgs.Empty); }
public LuaArgs unmount(LuaArgs args) { try { if (args.IsString(0)) { var path = new FilePath(args.GetString(0)); m_fileSystem.Unmount(path); } else { var mount = args.GetObject <LuaMount>(0); m_fileSystem.Unmount(mount); } return(LuaArgs.Empty); } catch (IOException e) { throw new LuaError(e.Message); } }
public LuaArgs loadTGA(LuaArgs args) { try { // Load image Image image; Palette palette; if (args.IsString(0)) { // Load from a string var bytes = args.GetByteString(0); using (var stream = new MemoryStream(bytes)) { image = TGAImage.Decode(stream, m_computer.Memory, out palette); } } else { // Load from a stream var file = args.GetObject <LuaFile>(0); CheckFileMode(file, "tga", LuaFileOpenMode.Read, LuaFileContentType.Binary); image = TGAImage.Decode(file.InnerStream, m_computer.Memory, out palette); } // Return image return(new LuaArgs( new LuaImage(image, m_computer.Memory), new LuaPalette(palette, m_computer.Memory) )); } catch (OutOfMemoryException) { throw new LuaError("not enough memory"); } catch (IOException e) { throw new LuaError(e.Message); } }