Advertisement
Jousway

Pop'nSys Character.ini Load System

May 12th, 2013
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.98 KB | None | 0 0
  1. function PopnSys(t1, t2) --starting function, t1 for ini parent aka [], t2 for = values like Command=diffuse,1,1,1,1;
  2.     local song = GAMESTATE:GetCurrentSong();
  3.     local RFU = RageFileUtil.CreateRageFile(); -- we are using rage to load the ini files
  4.     local FFU = RageFileUtil.CreateRageFile();
  5.     local CIE = RageFileUtil.CreateRageFile();
  6.  
  7.     if song then
  8.         local songDir = song:GetSongDir(); -- geting song directory :P
  9.         local a;
  10.        
  11.         -- MAIN CODE: PopnSys Character Loader - Jousway
  12.         if CIE:Open(songDir.."Character/Character.ini","1") then -- check if simfile has ini
  13.             RFU:Open(songDir.."Character/Character.ini","1"); -- load actual ini
  14.             a = "true";
  15.         else
  16.             RFU:Open(THEME:GetPathO("","Character/Character.ini"),"1");
  17.             a = "false";
  18.         end;
  19.        
  20.         -- we need these!!
  21.         local ReadChar = {};
  22.         local TempChar;
  23.         local i = 1;
  24.         local v, v2, v3, v4, v5, v6; -- I know, its a lot -.-"
  25.        
  26.         FFU:Open(THEME:GetPathO("","Character/Character.ini"),"1"); -- opening fallback charcter.ini from Other folder in theme
  27.        
  28.         --ini gets loaded as a giant string
  29.         for c in string.gmatch(RFU:Read(),"(.-)%\n") do --change string in to lines and put them in table
  30.             v = string.match(c, "%[%a+%]"); -- Find ini [], Example [Win]
  31.             if v then -- check if [] exists
  32.                 TempChar = v; -- define [] as a temp local
  33.             else
  34.                 v2 = string.match(c, "(.+=.+)"); -- check if = exist, Example Command=diffuse,1,1,1,1
  35.                 if v2 then -- check if = exists
  36.                     ReadChar[i] =  TempChar..v2; -- make table with combine [] and = depending on [], Example [Win] Command=diffuse,1,1,1,1
  37.                     i = i + 1;
  38.                 end;
  39.             end;
  40.         end;
  41.         for c2=1,#ReadChar do -- for every ReadChar value do
  42.             v3 = string.match(ReadChar[c2], "%[(.+)%].+"); -- define the v3 as the [] from ReadChar
  43.             if v3 == t1 then -- Check if [] is value defined by t1 from PopnSys( "Win", "Command")
  44.                 v4 = string.match(ReadChar[c2], "%[.+%](.+)="); -- grab the value before the = and define it
  45.                 if v4 == t2 then -- check if value before the = is Command
  46.                     v5 = string.match(ReadChar[c2], "%[.+%].+=(.+).");
  47.                     v6 = string.match(FFU:Read(), "%["..t1.."%].-"..t2.."=(.-).%\n");--use fallback character.ini  
  48.                     if v5 then -- check if there is a value after the =
  49.                         if a == "true" and CIE:Open(songDir.."Character/"..v5,"1") then
  50.                             PopnSysOutput = v5.."/"..a; -- puts out the value after the =
  51.                         else
  52.                             PopnSysOutput = v6.."/false"; -- puts out the value after the = from fallback
  53.                         end;
  54.                     else
  55.                         PopnSysOutput = v6.."/false"; -- same as above
  56.                     end;
  57.                 end;
  58.             end;
  59.         end;
  60.        
  61.         RFU:destroy(); -- destroying RFU file opening because else sm will crash because to many openned files
  62.         FFU:destroy(); -- same as RFU
  63.     else
  64.         PopnSysOutput = ""; -- in case of no song for ScreenSelectMusic
  65.     end;
  66.     return PopnSysOutput; -- output the code
  67. end;
  68.  
  69. function PopnLoad(t1, t2)
  70.     local song = GAMESTATE:GetCurrentSong();
  71.    
  72.     if song then
  73.         local songDir = song:GetSongDir();
  74.         local FileCheck = RageFileUtil.CreateRageFile();
  75.    
  76.         if string.match(PopnSys(t1,t2), ".-/(.+)") == "true" then
  77.             if FileCheck:Open(songDir.."Character/"..string.match(PopnSys(t1,t2), "(.-)/.+"),"1") then
  78.                 PopnLoadOutput = songDir.."Character/"..string.match(PopnSys(t1,t2), "(.-)/.+");
  79.             else
  80.                 PopnLoadOutput = THEME:GetPathO("","Character/"..string.match(PopnSys(t1,t2), "(.-)/.+"));
  81.             end;
  82.         else
  83.             PopnLoadOutput = THEME:GetPathO("","Character/"..string.match(PopnSys(t1,t2), "(.-)/.+"));
  84.         end;
  85.     end;
  86.     return PopnLoadOutput;
  87. end;
  88.  
  89. function PopnVal(t1, t2)
  90.     local song = GAMESTATE:GetCurrentSong();
  91.    
  92.     if song then
  93.         PopnValOutput = string.match(PopnSys(t1,t2), "(.-)/.+");
  94.     else
  95.         PopnValOutput = "";
  96.     end;
  97.     return PopnValOutput;
  98. end;
  99.  
  100. function PopnCom(t1, t2, self)
  101.     local song = GAMESTATE:GetCurrentSong();
  102.    
  103.     if song then
  104.         for c in string.gmatch(PopnSys(t1,t2), "(.-);*") do
  105.             Com = string.match(c, "(.-),.+");
  106.             Do = string.match(c, ".-,(.-);");
  107.             self:addcommand(tostring(Com),tostring(Do));
  108.         end;
  109.     end;
  110. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement