sgreader

package module
v0.0.0-...-0cd0ce4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2014 License: Apache-2.0 Imports: 10 Imported by: 0

README

sgreader

Installation

go get github.com/TheOnly92/sgreader

Documentation

http://godoc.org/github.com/TheOnly92/sgreader

Usage

package main

import (
    "github.com/TheOnly92/sgreader"
)

func main() {
    file := sgreader.ReadFile("C3.sg2")
    err := file.Load()
    if err != nil {
        panic(err)
    }

    bitmaps := file.BitmapCount()
    fmt.Printf("Bitmaps: %d\n", bitmaps)
}

Documentation

Overview

Package sgreader provides functions for reading SG files which are used by City Builder games (Zeus, Caesar 3, Pharaoh etc) to store art assets.

Usage:

file := sgreader.ReadFile("C3.sg2")

Index

Constants

View Source
const (
	ISOMETRIC_TILE_WIDTH        = 58
	ISOMETRIC_TILE_HEIGHT       = 30
	ISOMETRIC_TILE_BYTES        = 1800
	ISOMETRIC_LARGE_TILE_WIDTH  = 78
	ISOMETRIC_LARGE_TILE_HEIGHT = 40
	ISOMETRIC_LARGE_TILE_BYTES  = 3200
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SgBitmap

type SgBitmap struct {
	// contains filtered or unexported fields
}

SgBitmap stores references to a series of images

func (*SgBitmap) AddImage

func (sgBitmap *SgBitmap) AddImage(child *SgImage)

Add an image to the bitmap

func (*SgBitmap) BitmapName

func (sgBitmap *SgBitmap) BitmapName() string

The name of the bitmap without the extension ".bmp"

func (*SgBitmap) CloseFile

func (sgBitmap *SgBitmap) CloseFile() error

Close the .555 file after use

func (*SgBitmap) GetImage

func (sgBitmap *SgBitmap) GetImage(id int) (*image.RGBA, error)

Get an image.RGBA object from the bitmap by the id

func (*SgBitmap) Image

func (sgBitmap *SgBitmap) Image(id int) *SgImage

Get an image from the bitmap referred by the id

func (*SgBitmap) ImageCount

func (sgBitmap *SgBitmap) ImageCount() int

The number of images this bitmap refers

func (*SgBitmap) OpenFile

func (sgBitmap *SgBitmap) OpenFile(isExtern bool) (*os.File, error)

Opens the appropriate .555 file to extract data, returns os.File object

func (*SgBitmap) String

func (sgBitmap *SgBitmap) String() string

Name of the bitmap along with the number of images

type SgBitmapRecord

type SgBitmapRecord struct {
	Filename   [65]byte
	Comment    [51]byte
	Width      uint32
	Height     uint32
	NumImages  uint32
	StartIndex uint32
	EndIndex   uint32
	// contains filtered or unexported fields
}

type SgFile

type SgFile struct {
	// contains filtered or unexported fields
}

SgFile holds data for the bitmaps and images stored in the data file

func ReadFile

func ReadFile(filename string) *SgFile

Returns a new SgFile object that is tied to the file

func (*SgFile) Basename

func (sgFile *SgFile) Basename() string

Get the basename of the file

func (*SgFile) BitmapCount

func (sgFile *SgFile) BitmapCount() int

Get the number of bitmaps stored in the file

func (*SgFile) GetBitmap

func (sgFile *SgFile) GetBitmap(bitmapId int) *SgBitmap

Get the bitmap object within the data file

func (*SgFile) GetBitmapDescription

func (sgFile *SgFile) GetBitmapDescription(bitmapId int) string

Get the name of the bitmap and the number of images

func (*SgFile) ImageCount

func (sgFile *SgFile) ImageCount(bitmapId int) int

Get the number of images stored within a specific bitmap

func (*SgFile) Load

func (sgFile *SgFile) Load() error

Attempts to load the bitmaps and images stored within the sg data file

func (*SgFile) MaxBitmapRecords

func (sgFile *SgFile) MaxBitmapRecords() int

Get the maximum number of bitmap records for this sg file

func (*SgFile) TotalImageCount

func (sgFile *SgFile) TotalImageCount() int

Get the number of images stored in the file

type SgHeader

type SgHeader struct {
	SgFilesize                    uint32
	Version                       uint32
	Unknown1                      uint32
	MaxImageRecords               int32
	NumImageRecords               int32
	NumBitmapRecords              int32
	NumBitmapRecordsWithoutSystem int32
	TotalFilesize                 uint32
	Filesize555                   uint32
	FilesizeExternal              uint32
}

type SgImage

type SgImage struct {
	// contains filtered or unexported fields
}

SgImage stores the metadata of the image

func (*SgImage) BitmapId

func (sgImage *SgImage) BitmapId() int

The ID of the image within the bitmap

func (*SgImage) FullDescription

func (sgImage *SgImage) FullDescription() string

Returns the full information of this image

func (*SgImage) GetImage

func (sgImage *SgImage) GetImage() (*image.RGBA, error)

Get the image.RGBA object for this image

func (*SgImage) InvertOffset

func (sgImage *SgImage) InvertOffset() int32

Retrieves the invert offset

func (*SgImage) SetInvertImage

func (sgImage *SgImage) SetInvertImage(invert *SgImage)

Set the work record of the inverted image

func (*SgImage) SetParent

func (sgImage *SgImage) SetParent(parent *SgBitmap)

Set the parent bitmap of the image

func (*SgImage) String

func (sgImage *SgImage) String() string

Returns the width and height of this image

type SgImageRecord

type SgImageRecord struct {
	Offset             uint32
	Length             uint32
	UncompressedLength uint32

	InvertOffset int32
	Width        int16
	Height       int16

	Type     uint16
	Flags    [4]uint8
	BitmapId uint8

	AlphaOffset uint32
	AlphaLength uint32
	// contains filtered or unexported fields
}

type SgImageRecordNonAlpha

type SgImageRecordNonAlpha struct {
	Offset             uint32
	Length             uint32
	UncompressedLength uint32

	InvertOffset int32
	Width        int16
	Height       int16

	Type     uint16
	Flags    [4]uint8
	BitmapId uint8
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL