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 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();
|
||||
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;
|
||||
|
|
@ -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. */
|
||||
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;
|
||||
}
|
||||
|
|
@ -377,4 +379,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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import src.Util;
|
|||
import h3d.Vector;
|
||||
import h3d.Quat;
|
||||
|
||||
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;
|
||||
|
|
@ -105,6 +105,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();
|
||||
|
|
@ -126,7 +130,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;
|
||||
|
|
@ -187,7 +191,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;
|
||||
|
|
@ -219,6 +223,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