// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ // ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ // ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ // Magicbane Emulator Project © 2013 - 2026 // https://www.magicbane.com package engine.parsers.wpak; import engine.parsers.objects.wpak.CompoundCurveTemplate; import org.pmw.tinylog.Logger; import java.util.ArrayList; import java.util.HashMap; // Loads CompoundCurves.cfg. public class CompoundCurveParser { private static final String fileName = "Config/CompoundCurves.cfg"; // Segments run back to back on one line, so the param count per simple curve // is what tells where the next segment starts. private static final HashMap paramCounts = new HashMap<>(); static { paramCounts.put("FlatLine", 0); paramCounts.put("SlopedLine", 1); paramCounts.put("SlopedInitValLine", 1); } public static HashMap parseCompoundCurvesFile() { HashMap curves = new HashMap<>(); ArrayList lines; CompoundCurveTemplate curve; int failedCount = 0; try { lines = WpakFileReader.readLines(fileName); } catch (Exception e) { Logger.error(fileName + ": " + e.getMessage()); return null; } for (WpakLine line : lines) { try { curve = parseCurveLine(line); if (curves.containsKey(curve.name)) throw line.error("duplicate curve " + curve.name); curves.put(curve.name, curve); } catch (WpakFormatException e) { Logger.error(e.getMessage()); failedCount++; } } Logger.info("Loaded " + curves.size() + " of " + lines.size() + " compound curves"); if (failedCount > 0) return null; return curves; } private static CompoundCurveTemplate parseCurveLine(WpakLine line) { CompoundCurveTemplate curve = new CompoundCurveTemplate(); CompoundCurveTemplate.Segment segment; Integer paramCount; int index = 1; curve.name = line.token(0); while (line.has(index)) { segment = new CompoundCurveTemplate.Segment(); segment.down_per_range = line.intToken(index); segment.simple_curve = line.token(index + 1); paramCount = paramCounts.get(segment.simple_curve); if (paramCount == null) throw line.error("unknown simple curve " + segment.simple_curve); segment.params = new float[paramCount]; for (int i = 0; i < paramCount; i++) segment.params[i] = line.floatToken(index + 2 + i); curve.segments.add(segment); index += 2 + paramCount; } if (curve.segments.isEmpty()) throw line.error("curve " + curve.name + " has no segments"); return curve; } }