mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-30 11:52:16 +00:00
fix iso-8859-1
This commit is contained in:
parent
ded22e5e37
commit
db7f7c0cf6
4 changed files with 63 additions and 31 deletions
|
|
@ -49,7 +49,10 @@ class Mission {
|
|||
public function new() {}
|
||||
|
||||
public function load() {
|
||||
var misParser = new MisParser(ResourceLoader.getFileEntry(this.path).entry.getText());
|
||||
var entry = ResourceLoader.getFileEntry(this.path).entry;
|
||||
var misText = Util.toASCII(entry.getBytes());
|
||||
|
||||
var misParser = new MisParser(misText);
|
||||
var contents = misParser.parse();
|
||||
root = contents.root;
|
||||
|
||||
|
|
|
|||
18
src/Util.hx
18
src/Util.hx
|
|
@ -1,5 +1,7 @@
|
|||
package src;
|
||||
|
||||
import haxe.io.BytesBuffer;
|
||||
import haxe.io.Bytes;
|
||||
import h3d.Matrix;
|
||||
import hxd.Key;
|
||||
import h2d.Tile;
|
||||
|
|
@ -217,12 +219,12 @@ class Util {
|
|||
}
|
||||
|
||||
/** Gets the index of a substring like String.prototype.indexOf, but only if that index lies outside of string literals. */
|
||||
public static function indexOfIgnoreStringLiterals(str:String, searchString:String, position = 0, strLiteralToken = '"') {
|
||||
public static function indexOfIgnoreStringLiterals(str:String, searchString:String, position = 0, strLiteralToken:Int = '"'.code) {
|
||||
var inString = false;
|
||||
for (i in position...str.length) {
|
||||
var c = str.charAt(i);
|
||||
var c = StringTools.fastCodeAt(str, i);
|
||||
if (inString) {
|
||||
if (c == strLiteralToken && str.charAt(i - 1) != '\\')
|
||||
if (c == strLiteralToken && StringTools.fastCodeAt(str, i - 1) != '\\'.code)
|
||||
inString = false;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -400,4 +402,14 @@ class Util {
|
|||
return Settings.optionsSettings.isFullScreen;
|
||||
#end
|
||||
}
|
||||
|
||||
public static function toASCII(bytes:haxe.io.Bytes) {
|
||||
var totBytes = new BytesBuffer();
|
||||
for (i in 0...bytes.length) {
|
||||
var utfbytes = Bytes.ofString(String.fromCharCode(bytes.get(i)));
|
||||
totBytes.add(utfbytes);
|
||||
}
|
||||
|
||||
return totBytes.getBytes().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -424,18 +424,6 @@ class PlayMissionGui extends GuiImage {
|
|||
pmDifficultyTopCTab2.vertSizing = Bottom;
|
||||
pmDifficultyTopC2.addChild(pmDifficultyTopCTab2);
|
||||
|
||||
var pmDifficultyUltraCustom = new GuiButtonText(loadButtonImages("data/ui/play/difficulty_highlight-120"), markerFelt24);
|
||||
pmDifficultyUltraCustom.position = new Vector(277, 164);
|
||||
pmDifficultyUltraCustom.ratio = -1 / 16;
|
||||
pmDifficultyUltraCustom.setExtent(new Vector(120, 31));
|
||||
pmDifficultyUltraCustom.txtCtrl.text.text = " Custom";
|
||||
pmDifficultyUltraCustom.pressedAction = (e) -> {
|
||||
currentList = Marbleland.goldMissions;
|
||||
currentCategory = "custom";
|
||||
setCategoryFunc("ultra", "custom");
|
||||
}
|
||||
pmDifficultyCtrl.addChild(pmDifficultyUltraCustom);
|
||||
|
||||
var pmDifficultyUltraAdvanced = new GuiButtonText(loadButtonImages("data/ui/play/difficulty_highlight-120"), markerFelt24);
|
||||
pmDifficultyUltraAdvanced.position = new Vector(277, 134);
|
||||
pmDifficultyUltraAdvanced.ratio = -1 / 16;
|
||||
|
|
@ -472,18 +460,6 @@ class PlayMissionGui extends GuiImage {
|
|||
}
|
||||
pmDifficultyCtrl.addChild(pmDifficultyUltraIntermediate);
|
||||
|
||||
var pmDifficultyGoldCustom = new GuiButtonText(loadButtonImages("data/ui/play/difficulty_highlight-120"), markerFelt24);
|
||||
pmDifficultyGoldCustom.position = new Vector(37, 164);
|
||||
pmDifficultyGoldCustom.ratio = -1 / 16;
|
||||
pmDifficultyGoldCustom.setExtent(new Vector(120, 31));
|
||||
pmDifficultyGoldCustom.txtCtrl.text.text = " Custom";
|
||||
pmDifficultyGoldCustom.pressedAction = (e) -> {
|
||||
currentList = Marbleland.goldMissions;
|
||||
currentCategory = "custom";
|
||||
setCategoryFunc("gold", "custom");
|
||||
}
|
||||
pmDifficultyCtrl.addChild(pmDifficultyGoldCustom);
|
||||
|
||||
var pmDifficultyGoldAdvanced = new GuiButtonText(loadButtonImages("data/ui/play/difficulty_highlight-120"), markerFelt24);
|
||||
pmDifficultyGoldAdvanced.position = new Vector(37, 134);
|
||||
pmDifficultyGoldAdvanced.ratio = -1 / 16;
|
||||
|
|
@ -614,6 +590,42 @@ class PlayMissionGui extends GuiImage {
|
|||
pmGameCustom.extent = new Vector(120, 31);
|
||||
pmDifficultyCtrl.addChild(pmGameCustom);
|
||||
|
||||
var pmDifficultyGoldCustom = new GuiButtonText(loadButtonImages("data/ui/play/difficulty_highlight-120"), markerFelt24);
|
||||
pmDifficultyGoldCustom.position = new Vector(397, 75);
|
||||
pmDifficultyGoldCustom.ratio = -1 / 16;
|
||||
pmDifficultyGoldCustom.setExtent(new Vector(120, 31));
|
||||
pmDifficultyGoldCustom.txtCtrl.text.text = " Gold";
|
||||
pmDifficultyGoldCustom.pressedAction = (e) -> {
|
||||
currentList = Marbleland.goldMissions;
|
||||
currentCategory = "custom";
|
||||
setCategoryFunc("gold", "custom");
|
||||
}
|
||||
pmDifficultyCtrl.addChild(pmDifficultyGoldCustom);
|
||||
|
||||
var pmDifficultyPlatinumCustom = new GuiButtonText(loadButtonImages("data/ui/play/difficulty_highlight-120"), markerFelt24);
|
||||
pmDifficultyPlatinumCustom.position = new Vector(397, 104);
|
||||
pmDifficultyPlatinumCustom.ratio = -1 / 16;
|
||||
pmDifficultyPlatinumCustom.setExtent(new Vector(120, 31));
|
||||
pmDifficultyPlatinumCustom.txtCtrl.text.text = " Platinum";
|
||||
pmDifficultyPlatinumCustom.pressedAction = (e) -> {
|
||||
currentList = Marbleland.goldMissions;
|
||||
currentCategory = "custom";
|
||||
setCategoryFunc("platinum", "custom");
|
||||
}
|
||||
pmDifficultyCtrl.addChild(pmDifficultyPlatinumCustom);
|
||||
|
||||
var pmDifficultyUltraCustom = new GuiButtonText(loadButtonImages("data/ui/play/difficulty_highlight-120"), markerFelt24);
|
||||
pmDifficultyUltraCustom.position = new Vector(397, 134);
|
||||
pmDifficultyUltraCustom.ratio = -1 / 16;
|
||||
pmDifficultyUltraCustom.setExtent(new Vector(120, 31));
|
||||
pmDifficultyUltraCustom.txtCtrl.text.text = " Ultra";
|
||||
pmDifficultyUltraCustom.pressedAction = (e) -> {
|
||||
currentList = Marbleland.goldMissions;
|
||||
currentCategory = "custom";
|
||||
setCategoryFunc("ultra", "custom");
|
||||
}
|
||||
pmDifficultyCtrl.addChild(pmDifficultyUltraCustom);
|
||||
|
||||
var pmDividerR = new GuiImage(ResourceLoader.getResource('data/ui/menu/brown/divider-orange-r.png', ResourceLoader.getImage, this.imageResources)
|
||||
.toTile());
|
||||
pmDividerR.horizSizing = Left;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import h3d.Vector;
|
|||
import h3d.Quat;
|
||||
import src.Console;
|
||||
|
||||
final elementHeadRegEx = ~/new (\w+)\((\w*)\) *{/g;
|
||||
final elementHeadRegEx = ~/new\s+(\w+)\((.*?)\)\s*{/g;
|
||||
final blockCommentRegEx = ~/\/\*(.|\n)*?\*\//g;
|
||||
final lineCommentRegEx = ~/\/\/.*/g;
|
||||
final assignmentRegEx = ~/(\$(?:\w|\d)+)\s*=\s*(.+?);/g;
|
||||
|
|
@ -107,6 +107,10 @@ class MisParser {
|
|||
}
|
||||
}
|
||||
|
||||
var indexOfMissionGroup = this.text.indexOf('new SimGroup(MissionGroup)');
|
||||
if (indexOfMissionGroup != -1)
|
||||
this.index = indexOfMissionGroup;
|
||||
|
||||
var elements = [];
|
||||
while (this.hasNextElement()) {
|
||||
var element = this.readElement();
|
||||
|
|
@ -128,7 +132,7 @@ class MisParser {
|
|||
}
|
||||
|
||||
public function parseMissionInfo() {
|
||||
var missionInfoIndex = this.text.indexOf("new ScriptObject(MissionInfo) {");
|
||||
var missionInfoIndex = this.text.indexOf("new ScriptObject(MissionInfo)");
|
||||
this.index = missionInfoIndex;
|
||||
var mInfo:MissionElementScriptObject = cast readElement();
|
||||
return mInfo;
|
||||
|
|
@ -189,7 +193,7 @@ class MisParser {
|
|||
}
|
||||
|
||||
function hasNextElement() {
|
||||
if (!elementHeadRegEx.matchSub(this.text, this.index))
|
||||
if (!elementHeadRegEx.matchSub(this.text, Std.int(Math.min(this.text.length - 1, this.index))))
|
||||
return false;
|
||||
if (Util.indexOfIgnoreStringLiterals(this.text.substring(this.index, elementHeadRegEx.matchedPos().pos), '}') != -1)
|
||||
return false;
|
||||
|
|
@ -221,6 +225,7 @@ class MisParser {
|
|||
function readValues() {
|
||||
// Values are either strings or string arrays.
|
||||
var obj:Map<String, Array<String>> = new Map();
|
||||
var textSub = this.text.substr(this.index);
|
||||
var endingBraceIndex = Util.indexOfIgnoreStringLiterals(this.text, '};', this.index);
|
||||
if (endingBraceIndex == -1)
|
||||
endingBraceIndex = this.text.length;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue