Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TouhouDanmakufu
- #Title[TTHTest]
- #Text[Testing for reading CtC TTH files]
- #Player[FREE]
- #ScriptVersion[2]
- script_enemy_main {
- #include_function ".\DATA\TT.dnh" //For InitializePreLoadTTH, plus constants
- #include_function ".\Font.dnh" //For __CreateTexTextCache, AddTexTextHandle, AddTexTextHandleList, plus some constants
- let ImgBoss = "script\img\ExRumia.png"; //default Rumia graphic
- let CSD = GetCurrentScriptDirectory;
- let prefix = CSD ~ "DATA\TTH_";
- let suffix = [ "MENU", "ED", "SPELL", "KOUMA", "EIYA", "KAEI", "LOTUS", "EXPH"];
- let filelist = [];
- ascent(i in 0..length(suffix)){
- filelist = filelist ~ [(prefix ~ suffix[i] ~ ".DAT")];
- }
- let category = "TEX_TEXT_CACHE";
- let filenum = 0;
- let item = 0;
- let item_str = "0";
- let length_str = "0";
- let itema = [];
- let itemaa = [];
- let itemaastr = [];
- let frame = 0;
- let DIR_CL_IMAGE_FONT = CSD ~ "IMAGE\FONT\";
- let IMAGE_CL_FONT_ASCII = DIR_CL_IMAGE_FONT ~ "Font.png";
- let IMAGE_CL_FONT_SJIS16 = [
- DIR_CL_IMAGE_FONT ~ "Sjis16_1.png",
- DIR_CL_IMAGE_FONT ~ "Sjis16_2.png",
- DIR_CL_IMAGE_FONT ~ "Sjis16_3.png"];
- @Initialize {
- CreateDebugWindow;
- CreateCommonDataArea(CL_CDNS_MESSAGE);
- FontInitialize( IMAGE_CL_FONT_ASCII, IMAGE_CL_FONT_SJIS16);
- LoadTTC(filenum);
- SetLife(50000);
- //SetTimer(50);
- SetScore(1000000);
- AddGraze(100);
- SetMovePosition02(GetCenterX, GetCenterY - 100, 120);
- LoadGraphic(ImgBoss); // this loads the boss's graphic
- SetTexture(ImgBoss);
- SetGraphicRect(0, 0, 64, 64); // this sets the dimensions of the boss's graphic
- LoadGraphic(m_szCLFontImageAscii);
- ascent(let i in 0..3){LoadGraphic(m_aszCLFontImageSjis16[i]);}
- SetRateScoreSystemEnable(false);
- RefreshStrings();
- }
- @MainLoop {
- SetCollisionA(GetX, GetY, 32);
- SetCollisionB(GetX, GetY, 0);
- if(frame>0){
- if(GetKeyState(VK_USER)==KEY_PUSH){
- filenum = (filenum + 1) % 8;
- LoadTTC(filenum);
- item %= length(m_aCLTTCBeUsed);
- RefreshStrings();
- }
- if(GetKeyState(VK_RIGHT)==KEY_HOLD){
- item++;
- if(item==length( m_aCLTTCBeUsed )){item = 0;}
- RefreshStrings();
- frame = [0,-20][GetKeyState(VK_SLOWMOVE)==KEY_HOLD];
- break;
- }
- if(GetKeyState(VK_LEFT)==KEY_HOLD){
- item--;
- if(item<0){item += length( m_aCLTTCBeUsed );}
- RefreshStrings();
- frame = [0,-20][GetKeyState(VK_SLOWMOVE)==KEY_HOLD];
- break;
- }
- }
- frame++;
- }
- @DrawLoop {
- DrawText(filelist[filenum],48,48,16,255);
- DrawText(item_str,48,80,16,255);
- DrawText(length_str,148,80,16,255);
- ascent(i in 0..7){DrawText(itemaastr[i],40+32*i,112,16,255);}
- DrawText(length_str,148,80,16,255);
- //DrawGraphic(GetX, GetY); // this draws the boss's graphic
- DrawTexTextOnCache( item, 0, 0, [42, 64][itemaa[4]>32] , GetCenterY() - 16);
- }
- @Finalize {
- DeleteGraphic(ImgBoss); // unloads the boss's graphic
- DeleteGraphic(m_szCLFontImageAscii);
- ascent(let i in 0..3){DeleteGraphic(m_aszCLFontImageSjis16[i]);}
- }
- function RefreshStrings(){
- item_str = ToIntString(item);
- length_str = ToIntString(length(m_aCLTTCBeUsed));
- itema = m_aCLTTCValue[item];
- itemaa = [];
- itemaastr = [];
- ascent(let i in 0..7){ itemaa = itemaa ~ [ itema[i][0] ];}
- ascent(let i in 0..7){ itemaastr = itemaastr ~ [ToIntString(itemaa[i])];}
- }
- function ToIntString(let n1){
- let n1_str = ToString(n1);
- loop(7){n1_str = erase(n1_str, length(n1_str)-1);}
- return n1_str;
- }
- // Copied from IO.dnh - CL_CDNS_MESSAGE and CL_CD_TTC are defined in TT.dnh
- function LoadTTC( let nCDID ){
- InitializePreLoadTTH( nCDID );
- LoadCommonDataEx( CL_CDNS_MESSAGE, filelist[nCDID] );
- ClearTexTextHandle();
- AddTexTextHandleList( GetCommonDataDefaultEx( CL_CDNS_MESSAGE, CL_CD_TTC, [] ) );
- DeleteCommonDataEx( CL_CDNS_MESSAGE, CL_CD_TTC );
- }
- // given TTC, return string - this is key to reading, but doability is questionable
- function DecodeTexTextCache( let aszImageID, let anSrcX, let anSrcY ){
- let szText = "";
- let i = 0;
- while(i < length( aszImageID)){
- let nGap = 0;
- alternative( anSrcX[ i ] )
- case( CL_FONT_CODE_SPACE ){
- szText = szText ~ " ";
- }
- case( CL_FONT_CODE_CRLF ){
- szText = szText ~ "\n";
- }
- others {
- if( aszImageID[ i ] == -1 ){ // ASCII
- // compute ASCII value
- }
- else { // SJIS
- // compute SJIS value
- }
- }
- }
- // return szText;
- }
- function Max(let n1, let n2){return [n1, n2][n2 > n1];}
- function Min(let n1, let n2){return [n1, n2][n2 < n1];}
- function MinMax(let n, let min, let max){ return Min(Max(n, min), max) }
- function Animation(let n1, let n2, let n3, let n4, let a5) { return (n1+n2)/2; } // dummy function, only used in DrawTexTextOnCacheEx
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement