mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
fix iso-8859-1
This commit is contained in:
parent
c7b9ae2825
commit
46147a857e
3 changed files with 27 additions and 7 deletions
|
|
@ -36,7 +36,10 @@ class Mission {
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function load() {
|
public function load() {
|
||||||
var misParser = new MisParser(ResourceLoader.fileSystem.get(this.path).getText());
|
var entry = ResourceLoader.fileSystem.get(this.path).entry;
|
||||||
|
var misText = Util.toASCII(getBytes());
|
||||||
|
|
||||||
|
var misParser = new MisParser(misText);
|
||||||
var contents = misParser.parse();
|
var contents = misParser.parse();
|
||||||
root = contents.root;
|
root = contents.root;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
src/Util.hx
18
src/Util.hx
|
|
@ -1,5 +1,7 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import haxe.io.BytesBuffer;
|
||||||
|
import haxe.io.Bytes;
|
||||||
import h3d.Matrix;
|
import h3d.Matrix;
|
||||||
import hxd.Key;
|
import hxd.Key;
|
||||||
import h2d.Tile;
|
import h2d.Tile;
|
||||||
|
|
@ -216,12 +218,12 @@ class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the index of a substring like String.prototype.indexOf, but only if that index lies outside of string literals. */
|
/** 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;
|
var inString = false;
|
||||||
for (i in position...str.length) {
|
for (i in position...str.length) {
|
||||||
var c = str.charAt(i);
|
var c = StringTools.fastCodeAt(str, i);
|
||||||
if (inString) {
|
if (inString) {
|
||||||
if (c == strLiteralToken && str.charAt(i - 1) != '\\')
|
if (c == strLiteralToken && StringTools.fastCodeAt(str, i - 1) != '\\'.code)
|
||||||
inString = false;
|
inString = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -377,4 +379,14 @@ class Util {
|
||||||
return Settings.optionsSettings.isFullScreen;
|
return Settings.optionsSettings.isFullScreen;
|
||||||
#end
|
#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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import src.Util;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
import h3d.Quat;
|
import h3d.Quat;
|
||||||
|
|
||||||
final elementHeadRegEx = ~/new (\w+)\((\w*)\) *{/g;
|
final elementHeadRegEx = ~/new\s+(\w+)\((.*?)\)\s*{/g;
|
||||||
final blockCommentRegEx = ~/\/\*(.|\n)*?\*\//g;
|
final blockCommentRegEx = ~/\/\*(.|\n)*?\*\//g;
|
||||||
final lineCommentRegEx = ~/\/\/.*/g;
|
final lineCommentRegEx = ~/\/\/.*/g;
|
||||||
final assignmentRegEx = ~/(\$(?:\w|\d)+)\s*=\s*(.+?);/g;
|
final assignmentRegEx = ~/(\$(?:\w|\d)+)\s*=\s*(.+?);/g;
|
||||||
|
|
@ -105,6 +105,10 @@ class MisParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var indexOfMissionGroup = this.text.indexOf('new SimGroup(MissionGroup)');
|
||||||
|
if (indexOfMissionGroup != -1)
|
||||||
|
this.index = indexOfMissionGroup;
|
||||||
|
|
||||||
var elements = [];
|
var elements = [];
|
||||||
while (this.hasNextElement()) {
|
while (this.hasNextElement()) {
|
||||||
var element = this.readElement();
|
var element = this.readElement();
|
||||||
|
|
@ -126,7 +130,7 @@ class MisParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseMissionInfo() {
|
public function parseMissionInfo() {
|
||||||
var missionInfoIndex = this.text.indexOf("new ScriptObject(MissionInfo) {");
|
var missionInfoIndex = this.text.indexOf("new ScriptObject(MissionInfo)");
|
||||||
this.index = missionInfoIndex;
|
this.index = missionInfoIndex;
|
||||||
var mInfo:MissionElementScriptObject = cast readElement();
|
var mInfo:MissionElementScriptObject = cast readElement();
|
||||||
return mInfo;
|
return mInfo;
|
||||||
|
|
@ -187,7 +191,7 @@ class MisParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasNextElement() {
|
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;
|
return false;
|
||||||
if (Util.indexOfIgnoreStringLiterals(this.text.substring(this.index, elementHeadRegEx.matchedPos().pos), '}') != -1)
|
if (Util.indexOfIgnoreStringLiterals(this.text.substring(this.index, elementHeadRegEx.matchedPos().pos), '}') != -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -219,6 +223,7 @@ class MisParser {
|
||||||
function readValues() {
|
function readValues() {
|
||||||
// Values are either strings or string arrays.
|
// Values are either strings or string arrays.
|
||||||
var obj:Map<String, Array<String>> = new Map();
|
var obj:Map<String, Array<String>> = new Map();
|
||||||
|
var textSub = this.text.substr(this.index);
|
||||||
var endingBraceIndex = Util.indexOfIgnoreStringLiterals(this.text, '};', this.index);
|
var endingBraceIndex = Util.indexOfIgnoreStringLiterals(this.text, '};', this.index);
|
||||||
if (endingBraceIndex == -1)
|
if (endingBraceIndex == -1)
|
||||||
endingBraceIndex = this.text.length;
|
endingBraceIndex = this.text.length;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue