mpagd

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlockTypeToId = map[string]uint8{
	"EMPTYBLOCK":    0,
	"PLATFORMBLOCK": 1,
	"WALLBLOCK":     2,
	"LADDERBLOCK":   3,
	"FODDERBLOCK":   4,
	"DEADLYBLOCK":   5,
}

BlockTypeToId maps block type names to their corresponding block IDs.

View Source
var GetKeyState = user32_dll.NewProc("GetKeyState")
View Source
var IdToBlockType = map[uint8]string{
	0: "EMPTYBLOCK",
	1: "PLATFORMBLOCK",
	2: "WALLBLOCK",
	3: "LADDERBLOCK",
	4: "FODDERBLOCK",
	5: "DEADLYBLOCK",
}

IdToBlockType maps block IDs to their corresponding block type names.

Functions

func AddFileToTar added in v0.1.3

func AddFileToTar(tarWriter *tar.Writer, filePath string) error

addFileToTar adds a file to the tar archive

func CSVToIntSlice

func CSVToIntSlice(csv string) []int

CSVToIntSlice converts a CSV string to a slice of integers. csv: string - the input CSV string. Returns a slice of integers.

func CalcImageOffSet

func CalcImageOffSet(Index, startIndex uint8, columns, size int) (int, int)

CalcImageOffSet calculates the offset of a sprite in the image layout. Index: uint8 - the index of the sprite. startIndex: uint8 - the starting index of the sprites. columns: int - the number of columns in the layout. size: int - the size of each sprite. Returns the x and y offsets of the sprite.

func CalcImageSize

func CalcImageSize(startIndex, endIndex uint8, columns, size int) (int, int)

CalcImageSize calculates the dimensions of an image based on sprite layout. startIndex: uint8 - the starting index of the sprites. endIndex: uint8 - the ending index of the sprites. columns: int - the number of columns in the layout. size: int - the size of each sprite. Returns the width and height of the image.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from the source path to the destination filepath. src: string - the source file filepath. dst: string - the destination file filepath. Returns an error if the operation fails.

func CreateProjectFromTemplate

func CreateProjectFromTemplate(projectFile string, templateName string) error

CreateProjectFromTemplate creates a new project file from a specified template.

func GetBlockTypeByTypeID added in v0.1.6

func GetBlockTypeByTypeID(id uint8) string

GetBlockTypeByID returns the block type name for a given block ID. If the ID does not exist, it returns "UNKNOWN".

func GetBlockTypeIDByType added in v0.1.6

func GetBlockTypeIDByType(blockType string) uint8

GetBlockIDByType returns the block ID for a given block type name. If the block type does not exist, it returns 0 as the default value.

func IsESCKeyPressed added in v0.1.3

func IsESCKeyPressed() bool

IsKeyPressed checks if a specific key is pressed.

func LogMessage

func LogMessage(element, message, level string, noColor bool)

LogMessage displays a log message with a specific format and color-coded output. element: string - the element being logged. message: string - the log message. level: string - the log level ("ok", "warning", "error").

func SpectrumAttrToColors

func SpectrumAttrToColors(attr uint8) (fg color.Color, bg color.Color)

SpectrumAttrToColors converts a Spectrum attribute byte to foreground and background colors. attr: uint8 - the Spectrum attribute byte. Returns the foreground and background colors as color.Color.

Types

type APJData

type APJData struct {
	EnterpriseBias uint8 // EnterpriseBias is a single-byte value representing the enterprise bias setting.
}

APJData represents the data structure for APJ files, including the EnterpriseBias setting.

type APJFile

type APJFile struct {
	FilePath       string
	Description    string
	Windows        Windows
	Header         []uint8
	Version        uint32
	AsmPath        []uint8
	Blocks         []Block
	NrOfBlocks     uint8
	Screens        []Screen
	NrOfScreens    uint8
	EnterpriseBias uint8
	LivesScore     LivesScore
	Map            Map
	State          State
	Fonts          []Font
	Keys           []uint8
	Objects        []Object
	NrOfObjects    uint8
	SpriteInfo     []SpriteInfo
	Sprites        []Sprite
	NrOfSprites    uint8
	ULAPalette     ULAPalette
	// contains filtered or unexported fields
}

APJFile represents the structure of an APJ file with all its components.

func NewAPJFile

func NewAPJFile(filePath string) *APJFile

NewAPJFile creates a new APJFile instance with default values.

func (*APJFile) ASMPathInit

func (apj *APJFile) ASMPathInit()

ASMPathInit initializes the ASM path as an empty slice.

func (*APJFile) BackupProjectFile

func (apj *APJFile) BackupProjectFile(code bool) error

Backup creates a backup of the APJ file in the same directory as the original file

func (*APJFile) BlockDefault

func (apj *APJFile) BlockDefault()

BlockDefault sets up default blocks if none exist. It initializes one block with default values.

func (*APJFile) BlockInit

func (apj *APJFile) BlockInit(overwrite bool)

BlockInit initializes the Blocks slice. If overwrite is true, it resets the Blocks and NrOfBlocks.

func (*APJFile) BlockTo2DArray

func (apj *APJFile) BlockTo2DArray(data []uint8) ([][]uint8, error)

BlockTo2DArray converts block data to a 2D array.

func (*APJFile) CalcOffset

func (apj *APJFile) CalcOffset()

CalcImageSize calculates the image size based on the number of sprites and layout

func (*APJFile) CompareData

func (apj *APJFile) CompareData(other *APJFile) map[string]interface{}

CompareData compares the data in the current APJFile with another APJFile and returns a map of differences.

func (*APJFile) CreateBlank

func (apj *APJFile) CreateBlank()

CreateBlank initializes a blank APJ file with default values.

func (*APJFile) CreateState

func (apj *APJFile) CreateState() State

CreateState initializes and returns a default State object.

func (*APJFile) DeleteObject

func (apj *APJFile) DeleteObject(objectID int)

DeleteObject removes a specific object by its ID.

func (*APJFile) DeleteObjects

func (apj *APJFile) DeleteObjects()

DeleteObjects clears all objects from the APJFile.

func (*APJFile) Display

func (apj *APJFile) Display()

Display prints the details of the APJFile instance in a structured format.

func (*APJFile) DisplayStats

func (apj *APJFile) DisplayStats()

GetStats returns statistics about the project.

func (*APJFile) FontDefault

func (apj *APJFile) FontDefault()

create fonts with default values

func (*APJFile) FontInit

func (apj *APJFile) FontInit(overwrite bool)

FontInit initializes the Font slice in apj.Data

func (*APJFile) GetReorderedBlocks

func (apj *APJFile) GetReorderedBlocks(order []int, offset int) ([]Block, error)

GetReorderedBlocks returns a new slice of blocks reordered based on the provided order.

func (*APJFile) GetReorderedSprites

func (apj *APJFile) GetReorderedSprites(order []int, offset int) ([]Sprite, error)

GetReorderedSprites returns a reordered list of sprites based on the provided order and offset

func (*APJFile) HeaderInit

func (apj *APJFile) HeaderInit()

HeaderInit initializes the APJFile with default header and version values.

func (*APJFile) ImportAGD

func (apj *APJFile) ImportAGD(agdFilePath string, options ImportOptions) error

ImportAGD imports data from an AGD file into the APJ file.

func (*APJFile) ImportBlocks

func (apj *APJFile) ImportBlocks(lines []string) error

ImportBlocks imports block data from a slice of strings.

func (*APJFile) ImportFont

func (apj *APJFile) ImportFont(lines []string) error

ImportFont imports font data from lines and populates apj.Data["Font"]

func (*APJFile) ImportMap

func (apj *APJFile) ImportMap(lines []string) error

func (*APJFile) ImportObjects

func (apj *APJFile) ImportObjects(lines []string) error

ImportObjects parses object definitions and data from a list of strings.

func (*APJFile) ImportScreens

func (apj *APJFile) ImportScreens(lines []string) error

func (*APJFile) ImportSpritePos

func (apj *APJFile) ImportSpritePos(screenId uint8, lines []string) error

ImportSpritePos parses sprite position data from a list of strings and associates it with a specific screen ID.

func (*APJFile) ImportSprites

func (apj *APJFile) ImportSprites(lines []string) error

ImportSprites imports sprite data from a list of strings

func (*APJFile) ImportULAPalette

func (apj *APJFile) ImportULAPalette(lines []string) error

ImportULAPalette imports ULAPlus palette data from a slice of strings. Each string represents a line of palette data, and the function parses and updates the palette colors.

func (*APJFile) KeysInit

func (apj *APJFile) KeysInit(overwrite bool)

KeysInit initializes the Keys field with default values if it is empty or if overwrite is true.

func (*APJFile) ListBackupProjectFiles

func (apj *APJFile) ListBackupProjectFiles(backupDir string) ([]string, error)

List the backup files in the backup directory

func (*APJFile) LivesScoreInit

func (apj *APJFile) LivesScoreInit(overwrite bool)

LivesScoreInit initializes the LivesScore struct with default values. If overwrite is true, it resets the values to defaults.

func (*APJFile) LoadYAML

func (apj *APJFile) LoadYAML(filePath string) error

LoadYAML loads the APJ file from a YAML file

func (*APJFile) LoadYAMLFromString

func (apj *APJFile) LoadYAMLFromString(yamlString []byte) error

func (*APJFile) MapDefault

func (apj *APJFile) MapDefault()

func (*APJFile) MapInit

func (apj *APJFile) MapInit(overwrite bool)

func (*APJFile) MonitorFileChanges

func (apj *APJFile) MonitorFileChanges(code bool)

MonitorFileChanges monitors the specified file for changes and creates a backup when changes are detected. It uses a polling mechanism to check the file's last modified time every 5 seconds.

func (*APJFile) ObjectDefault

func (apj *APJFile) ObjectDefault()

ObjectDefault initializes the Objects slice with a single default object if it is empty.

func (*APJFile) ObjectInit

func (apj *APJFile) ObjectInit(overwrite bool)

ObjectInit initializes or resets the Objects slice based on the overwrite flag.

func (*APJFile) PurgeBackupFiles

func (apj *APJFile) PurgeBackupFiles(backupDir string) error

PurgeBackupFiles purges the backup files in the backup directory

func (*APJFile) ReadAPJ

func (apj *APJFile) ReadAPJ() error

ReadAPJ reads the entire APJ file and processes its components sequentially.

func (*APJFile) RemapScreens

func (apj *APJFile) RemapScreens(screenIndex uint8, BlockOffSet uint8)

make a copy of the screen data then remap the blocks

func (*APJFile) RenderBlockToBitmap

func (apj *APJFile) RenderBlockToBitmap(startIndex, endIndex uint8, filePath string, reorder []int, offset int) error

RenderBlockToBitmap renders blocks to a bitmap file.

func (*APJFile) RenderBlockToTerminal

func (apj *APJFile) RenderBlockToTerminal(start, end int, reorder []int) error

renderBlockToTerminal renders blocks to the terminal.

func (*APJFile) RenderScreenToBitmap

func (apj *APJFile) RenderScreenToBitmap(screenIndex uint8, filePath string) error

RenderScreenToBitmap renders the specified screen to a bitmap and saves it as a PNG file.

func (*APJFile) RenderSpriteToBitmap

func (apj *APJFile) RenderSpriteToBitmap(startIndex, endIndex uint8, filePath string, reorder []int, offset int) error

RenderSpriteToBitmap renders a range of sprites to a bitmap file

func (*APJFile) RenderSpriteToTerminal

func (apj *APJFile) RenderSpriteToTerminal(startIndex, endIndex uint8, reorder []int, offset int) error

RenderSpriteToTerminal renders a range of sprites to the terminal using tcg This function assumes that the terminal supports 2x3 pixel characters

func (*APJFile) ReorderBlocks

func (apj *APJFile) ReorderBlocks(order []int, offset int) error

ReorderBlocks reorders the blocks based on the provided order.

func (*APJFile) ReorderScreens added in v0.1.4

func (apj *APJFile) ReorderScreens(order []int) error

ReorderScreens reorders the screens based on the provided order slice. The order slice should contain the new indices for the screens.

func (*APJFile) ReorderSprites added in v0.1.4

func (apj *APJFile) ReorderSprites(order []int, offset int) error

ReorderSprites reorders the sprites based on the provided order and offset It updates the sprite IDs in the SpriteInfo array accordingly

func (*APJFile) ResetState

func (apj *APJFile) ResetState()

ResetState resets the APJ file's state to its default values.

func (*APJFile) RestoreLastBackup

func (apj *APJFile) RestoreLastBackup(backupDir string, code bool) (string, error)

Restore the last backup file

func (*APJFile) RotateBlock

func (apj *APJFile) RotateBlock(blockIndex uint8, ccw bool, retain bool) (uint8, error)

RotateBlock rotates a block's Spectrum data 90 degrees counter-clockwise or clockwise.

func (*APJFile) RotateSprite

func (apj *APJFile) RotateSprite(spriteIndex uint8, ccw bool, retain bool) (uint8, error)

RotateSprite rotates a sprite by 90 degrees clockwise or counter-clockwise

func (*APJFile) SaveAsYAML

func (apj *APJFile) SaveAsYAML(filePath string) error

add a function to save the APJ file as a yaml file

func (*APJFile) ScreensDefault

func (apj *APJFile) ScreensDefault()

func (*APJFile) ScreensInit

func (apj *APJFile) ScreensInit(force bool)

func (*APJFile) SetFrameDefaults

func (apj *APJFile) SetFrameDefaults(sprite *Sprite)

SetFrameDefaults initializes the frame data for a sprite

func (*APJFile) SetNoColorOutput added in v0.1.4

func (apj *APJFile) SetNoColorOutput(noColor bool)

func (*APJFile) SpriteDefault

func (apj *APJFile) SpriteDefault()

SpriteDefault initializes the default sprite data structure

func (*APJFile) SpriteInfoInit

func (apj *APJFile) SpriteInfoInit(overwrite bool)

SpriteInfoInit initializes the SpriteInfo slice. If `overwrite` is true, it clears the existing data.

func (*APJFile) SpriteInit

func (apj *APJFile) SpriteInit(overwrite bool)

SpriteInit initializes the sprite data structure

func (*APJFile) SpriteTo2DArray

func (apj *APJFile) SpriteTo2DArray(data []uint8) ([][]uint8, error)

SpriteTo2DArray converts a sprite's image data into a 2D array representation It assumes the sprite is 16x16 pixels and each pixel is represented by a bit in the byte array.

func (*APJFile) ULAPaletteInit

func (apj *APJFile) ULAPaletteInit(overwrite bool)

ULAPaletteInit initializes the ULAPlus palette with default values. If the overwrite flag is true, it will reset the palette even if it already contains data.

func (*APJFile) WriteAPJ

func (apj *APJFile) WriteAPJ(outputFilePath string) error

writeAPJ writes the APJ file to the specified output file path

type Block

type Block struct {
	ID         uint8   // Unique identifier for the block
	Type       uint8   // Unique identifier for the block
	Spectrum   []uint8 // Spectrum platform data
	Timex      []uint8 // Timex platform data
	CPC        []uint8 // CPC platform data
	Atom       []uint8 // Atom platform data
	MSX        []uint8 // MSX platform data
	AtomColour []uint8 // Atom color data
}

Block represents a game block with various platform-specific data.

type Font

type Font struct {
	ID   int
	Data []uint8
}

type ImportOptions

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

ImportOptions defines options for importing various components. Each field represents whether to overwrite or ignore a specific component during import.

func CreateImportOptions

func CreateImportOptions() ImportOptions

CreateImportOptions initializes an ImportOptions instance with default values (all false).

func (*ImportOptions) SetIgnoreOptions

func (o *ImportOptions) SetIgnoreOptions(ignoreWindow, ignoreKeys, ignoreBlocks, ignoreSprites, ignoreObjects, ignoreScreens, ignoreMaps, ignoreFonts, ignoreULAPalette bool)

SetIgnoreOptions sets the ignore options for all components.

func (*ImportOptions) SetIgnoreOptionsFalse

func (o *ImportOptions) SetIgnoreOptionsFalse()

SetIgnoreOptionsFalse disables ignore for all components.

func (*ImportOptions) SetIgnoreOptionsTrue

func (o *ImportOptions) SetIgnoreOptionsTrue()

SetIgnoreOptionsTrue enables ignore for all components.

func (*ImportOptions) SetOwOptions

func (o *ImportOptions) SetOwOptions(owWindow, owKeys, owBlocks, owSprites, owObjects, owScreens, owMaps, owFonts, owULAPalette bool)

SetOwOptions sets the overwrite options for all components.

func (*ImportOptions) SetOwOptionsFalse

func (o *ImportOptions) SetOwOptionsFalse()

SetOwOptionsFalse disables overwrite for all components.

func (*ImportOptions) SetOwOptionsTrue

func (o *ImportOptions) SetOwOptionsTrue()

SetOwOptionsTrue enables overwrite for all components.

type LivesScore

type LivesScore struct {
	ScoreTop   uint8
	ScoreLeft  uint8
	LivesTop   uint8
	LivesLeft  uint8
	HighTop    uint8
	HighLeft   uint8
	TimeTop    uint8
	TimeLeft   uint8
	EnergyTop  uint8
	EnergyLeft uint8
}

LivesScore holds the positions of various game elements like score, lives, etc.

type Map

type Map struct {
	Height      uint8
	Width       uint8
	StartRow    uint8
	StartColumn uint8
	StartScreen uint8
	Map         [][]uint8
}

MapData holds map-related data

type Object

type Object struct {
	ID         uint8   // Unique identifier for the object
	Spectrum   []uint8 // Data specific to the Spectrum platform
	Timex      []uint8 // Data specific to the Timex platform
	CPC        []uint8 // Data specific to the CPC platform
	Atom       []uint8 // Data specific to the Atom platform
	MSX        []uint8 // Data specific to the MSX platform
	AtomColour []uint8 // Colour data for the Atom platform
	VZColour   []uint8 // Colour data for the VZ platform
}

Object represents the structure of an object with various platform-specific data.

type Screen

type Screen struct {
	ScreenID   uint8
	ScreenData [][]uint8
}

Define a strong type for APJFile data

type Sprite

type Sprite struct {
	SpriteID   uint8
	OffSet     uint8
	Frames     uint8
	Spectrum   []SpriteFrame
	Timex      []SpriteFrame
	CPC        []SpriteFrame
	Atom       []SpriteFrame
	AtomColour []SpriteFrame
	VZColour   []SpriteFrame
}

Sprite represents the structure of a sprite

type SpriteFrame

type SpriteFrame struct {
	Frame     int
	ImageData []uint8
}

SpriteFrame represents a single frame of sprite data

type SpriteInfo

type SpriteInfo struct {
	Type    uint8 // Type of the sprite
	Image   uint8 // Image ID associated with the sprite
	Unknown uint8 // Placeholder for unknown data
	Screen  uint8 // Screen ID where the sprite is located
	X       uint8 // X-coordinate of the sprite
	Y       uint8 // Y-coordinate of the sprite
}

SpriteInfo represents the structure of a sprite's position data.

type State

type State struct {
	FilePath       bool
	Windows        bool
	Header         bool
	Version        bool
	AsmPath        bool
	Blocks         bool
	Screens        bool
	EnterpriseBias bool
	LivesScore     bool
	Map            bool
	Fonts          bool
	Keys           bool
	Objects        bool
	SpriteInfo     bool
	Sprites        bool
	ULAPalette     bool
	BlocksOffSet   uint8
}

State represents the state of an APJ file with various flags and settings.

type Template

type Template struct {
	Name        string
	FileName    string
	Type        string
	Description string
}

Template represents a template with metadata such as name, file name, type, and description.

func CreateTemplate

func CreateTemplate(fileName, templateType, description string) Template

CreateTemplate creates a new Template instance by extracting the name from the file name.

func ListTemplates

func ListTemplates() ([]Template, error)

ListTemplates lists all available templates in the embedded templates directory.

type ULAPalette

type ULAPalette struct {
	Colors []uint8
}

ULAPalette represents the ULAPlus palette data. The ULAPlus palette is a 16-color palette used in the ULAPlus graphics system. The palette is represented as a slice of uint8 values, where each value corresponds to a color index.

Jump to

Keyboard shortcuts

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