|  |  |  | // • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
 | 
					
						
							|  |  |  | // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
 | 
					
						
							|  |  |  | // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
 | 
					
						
							|  |  |  | // ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
 | 
					
						
							|  |  |  | // ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
 | 
					
						
							|  |  |  | //      Magicbane Emulator Project © 2013 - 2024
 | 
					
						
							|  |  |  | //                www.magicbane.com
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package engine.wpak;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import engine.gameManager.ConfigManager;
 | 
					
						
							|  |  |  | import engine.wpak.data.PowerActionEntry;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import java.io.IOException;
 | 
					
						
							|  |  |  | import java.nio.file.Files;
 | 
					
						
							|  |  |  | import java.nio.file.Paths;
 | 
					
						
							|  |  |  | import java.util.regex.Matcher;
 | 
					
						
							|  |  |  | import java.util.regex.Pattern;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public class PowerActionParser {
 | 
					
						
							|  |  |  |     private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*");
 | 
					
						
							|  |  |  |     private static final Pattern POWER_ACTION_REGEX = Pattern.compile("(?<=POWERACTIONBEGIN)(.+?)(?=POWERACTIONEND)", Pattern.DOTALL);
 | 
					
						
							|  |  |  |     private static final String powerActionPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/PowerActions.cfg";
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static void parseWpakFile() {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Read .wpak file from disk
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         byte[] fileData;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try {
 | 
					
						
							|  |  |  |             fileData = Files.readAllBytes(Paths.get(powerActionPath));
 | 
					
						
							|  |  |  |         } catch (
 | 
					
						
							|  |  |  |                 IOException e) {
 | 
					
						
							|  |  |  |             throw new RuntimeException(e);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         String fileContents = new String(fileData);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Iterate over power entries from .wpak data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Matcher matcher = POWER_ACTION_REGEX.matcher(fileContents);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         while (matcher.find()) {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             PowerActionEntry powerActionEntry = parsePowerActionEntry(matcher.group().trim());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private static PowerActionEntry parsePowerActionEntry(String powerActionData) {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         PowerActionEntry powerActionEntry = new PowerActionEntry();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return powerActionEntry;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | }
 |