import PixelImage from '../model/PixelImage' ; import GraphicMode from '../model/GraphicMode' ; type PixelImageFactory = ( props ? : Record < string , unknown > ) => PixelImage ; export default class GraphicModes { public static bitmap : PixelImageFactory = ( props ) : PixelImage => { const { hires , nomaps } = props ; const width = hires ? 320 : 160 ; const gm = new GraphicMode ( 'bitmap' , width , 200 ) ; gm . pixelWidth = hires ? 1 : 2 ; const result = new PixelImage ( gm ) ; if ( ! hires ) { result . addColorMap ( ) ; } if ( nomaps ) { result . addColorMap ( ) ; result . addColorMap ( ) ; if ( ! hires ) { result . addColorMap ( ) ; } } else { result . addColorMap ( gm . pixelsPerByte ( ) , gm . rowsPerCell ) ; result . addColorMap ( gm . pixelsPerByte ( ) , gm . rowsPerCell ) ; if ( ! hires ) { result . addColorMap ( gm . pixelsPerByte ( ) , gm . rowsPerCell ) ; } } return result ; } ; public static c64FLI : PixelImageFactory = ( props ) : PixelImage => { if ( props . hires ) { return GraphicModes . createHiresFLI ( ) ; } return GraphicModes . createMulticolorFLI ( ) ; } ; private static createMulticolorFLI ( ) { const gm = new GraphicMode ( 'fli' , 160 , 200 ) ; gm . pixelWidth = 2 ; gm . fliBugSize = 3 * 4 ; gm . indexMap = { 0 : 0 , 1 : 3 , 2 : 2 , 3 : 1 } ; const result = new PixelImage ( gm ) ; result . addColorMap ( ) ; result . addColorMap ( 4 , 8 ) ; result . addColorMap ( 4 , 1 ) ; result . addColorMap ( 4 , 1 ) ; return result ; } private static createHiresFLI ( ) { const gm = new GraphicMode ( 'fli' , 320 , 200 ) ; gm . fliBugSize = 3 * 8 ; const result = new PixelImage ( gm ) ; result . addColorMap ( 8 , 1 ) ; result . addColorMap ( 8 , 1 ) ; return result ; } public static c64Sprites : PixelImageFactory = ( props ) : PixelImage => { const { rows , columns , hires , nomaps } = props ; const nrRows = Number ( rows ) ; const nrColumns = Number ( columns ) ; const pixelsPerColumn = hires ? 24 : 12 ; const height = nrRows * 21 ; const width = nrColumns * pixelsPerColumn ; const gm = new GraphicMode ( 'sprites' , width , height ) ; gm . pixelWidth = hires ? 1 : 2 ; gm . bytesPerCellRow = 3 ; gm . rowsPerCell = 21 ; gm . indexMap = { 0 : 0 , 1 : 1 , 2 : 3 , 3 : 2 } ; const result = new PixelImage ( gm ) ; result . addColorMap ( ) ; if ( ! hires ) { result . addColorMap ( ) ; result . addColorMap ( ) ; } if ( nomaps ) { result . addColorMap ( ) ; } else { result . addColorMap ( pixelsPerColumn , 21 ) ; } return result ; } ; public static all = { bitmap : GraphicModes . bitmap , fli : GraphicModes . c64FLI , sprites : GraphicModes . c64Sprites } ; }