import { Pager } from "../components/Pager" ; import { AdapterContainer } from "../components/AdapterContainer" ; import { Container } from "pixi.js" ; export class PageAdapter < T > { pager ! : Pager ; _data ! : Array < T > ; _sourceData ! : Array < T > ; _loop : boolean = false ; private _loopCount : number = 1 ; constructor ( data ) { this . data = data ; } set data ( data ) { this . _sourceData = data ; this . loop = this . loop ; } get data ( ) : Array < T > { return this . _data ; } set loopCount ( loopCount ) { let lastLoopCount = this . _loopCount ; let currLoopCount = Math . floor ( loopCount ) ; this . _loopCount = currLoopCount ; if ( this . loop && lastLoopCount != currLoopCount ) { this . loop = this . loop ; } } get loopCount ( ) : number { return this . _loopCount ; } private copyData ( headData ? , tailData ? ) { if ( ! Array . isArray ( this . _data ) ) { this . _data = new Array ( ) ; } this . _data . length = 0 ; if ( Array . isArray ( headData ) ) { headData . forEach ( ( item ) => { this . _data . push ( item ) ; } ) ; } this . _sourceData . forEach ( ( item ) => { this . _data . push ( item ) ; } ) ; if ( Array . isArray ( tailData ) ) { tailData . forEach ( ( item ) => { this . _data . push ( item ) ; } ) ; } } set loop ( loop ) { this . _loop = loop ; let headData = new Array ( ) ; let tailData = new Array ( ) ; if ( loop ) { for ( let j = 0 ; j < this . loopCount ; j ++ ) { for ( let i = 0 ; i < this . _sourceData . length ; i ++ ) { headData . push ( this . _sourceData [ i ] ) ; } for ( let i = 0 ; i < this . _sourceData . length ; i ++ ) { tailData . push ( this . _sourceData [ i ] ) ; } } } this . copyData ( headData , tailData ) ; this . pager && this . pager . draw ( ) ; } get loop ( ) : boolean { return this . _loop ; } /**
     * 总共item个数
     */ getCount ( ) { return this . data . length ; } getSourceCount ( ) { return this . _sourceData . length ; } getLoopSourceCount ( ) { return this . _sourceData . length * this . loopCount ; } param position getItem ( position ) { return this . data [ position ] ; } param position getItemType ( position ) { return 0 ; } /**
     * 测量
     */ getRemeasure ( position , convertView ) { return ; } param position param convertView param parent getAdapterContainer ( position , convertView , parent ) { if ( ! convertView ) { convertView = new AdapterContainer ( ) ; } return convertView ; } }