Blades Engine loading floor data
This commit is contained in:
@@ -39,6 +39,8 @@
|
|||||||
<haxelib name="kiss"/>
|
<haxelib name="kiss"/>
|
||||||
<haxelib name="kiss-flixel"/>
|
<haxelib name="kiss-flixel"/>
|
||||||
|
|
||||||
|
<haxelib name="hscript"/>
|
||||||
|
|
||||||
<!--In case you want to use the addons package-->
|
<!--In case you want to use the addons package-->
|
||||||
<!--<haxelib name="flixel-addons" />-->
|
<!--<haxelib name="flixel-addons" />-->
|
||||||
|
|
||||||
|
@@ -2,12 +2,15 @@ package;
|
|||||||
|
|
||||||
import flixel.FlxGame;
|
import flixel.FlxGame;
|
||||||
import openfl.display.Sprite;
|
import openfl.display.Sprite;
|
||||||
|
import data.ScenData;
|
||||||
|
|
||||||
class Main extends Sprite
|
class Main extends Sprite
|
||||||
{
|
{
|
||||||
public function new()
|
public function new()
|
||||||
{
|
{
|
||||||
|
var scenData = new ScenData();
|
||||||
|
scenData.load("Data/corescendata.txt");
|
||||||
super();
|
super();
|
||||||
addChild(new FlxGame(0, 0, IsometricMapState));
|
// addChild(new FlxGame(0, 0, IsometricMapState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
projects/blades-engine/source/data/FloorData.hx
Normal file
79
projects/blades-engine/source/data/FloorData.hx
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package data;
|
||||||
|
|
||||||
|
using Type;
|
||||||
|
using Reflect;
|
||||||
|
|
||||||
|
import flixel.input.keyboard.FlxKey;
|
||||||
|
|
||||||
|
enum FloorShimmerType {
|
||||||
|
None;
|
||||||
|
LightToDark;
|
||||||
|
Water;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum FloorSpecialProperty {
|
||||||
|
Nothing;
|
||||||
|
|
||||||
|
// For dice-based properties, special_strength is the size of the dice.
|
||||||
|
FireDamage2Dice;
|
||||||
|
ColdDamage2Dice;
|
||||||
|
MagicDamage2Dice;
|
||||||
|
PoisonLevels1Die50Percent;
|
||||||
|
DiseaseLevels1Die50Percent;
|
||||||
|
|
||||||
|
BlockedToNPCs;
|
||||||
|
NoRest;
|
||||||
|
|
||||||
|
// Call the scenario script with the number special_strength
|
||||||
|
CallScenarioScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FloorData {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function clone():FloorData {
|
||||||
|
var fd = new FloorData();
|
||||||
|
for (field in FloorData.getClassFields()) {
|
||||||
|
fd.setField(field, this.field(field));
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public var name:String = "";
|
||||||
|
public var which_sheet:Int = 0;
|
||||||
|
public var which_icon:Int = 0;
|
||||||
|
public var icon_adjust:Int = 0;
|
||||||
|
public var ed_which_sheet:Int = 0;
|
||||||
|
public var ed_which_icon:Int = 0;
|
||||||
|
private var blocked:Int = 0;
|
||||||
|
public function isBlocked() {
|
||||||
|
return blocked == 1;
|
||||||
|
}
|
||||||
|
public var step_sound:Int = -1;
|
||||||
|
public var light_radius:Int = 0;
|
||||||
|
public var floor_height_pixels:Int = 0;
|
||||||
|
private var special_property:Int = 0;
|
||||||
|
public function specialProperty() {
|
||||||
|
return FloorSpecialProperty.createEnumIndex(special_property);
|
||||||
|
}
|
||||||
|
public var special_strength:Int = 0;
|
||||||
|
public var is_water:Bool = false;
|
||||||
|
public var is_floor:Bool = false;
|
||||||
|
public var is_ground:Bool = false;
|
||||||
|
public var is_rough:Bool = false;
|
||||||
|
public var fly_over:Bool = false;
|
||||||
|
private var shortcut_key:Int = -1;
|
||||||
|
public function shortcutKey() {
|
||||||
|
return if (shortcut_key == -1) {
|
||||||
|
NONE;
|
||||||
|
} else {
|
||||||
|
FlxKey.A + shortcut_key;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public var anim_steps:Int = 0;
|
||||||
|
private var shimmers:Int;
|
||||||
|
public function shimmerType() {
|
||||||
|
return FloorShimmerType.createEnumIndex(shimmers);
|
||||||
|
}
|
||||||
|
public var out_fight_town_used:Int = 1000;
|
||||||
|
}
|
82
projects/blades-engine/source/data/ScenData.hx
Normal file
82
projects/blades-engine/source/data/ScenData.hx
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package data;
|
||||||
|
|
||||||
|
import hscript.Parser;
|
||||||
|
import hscript.Interp;
|
||||||
|
import sys.io.File;
|
||||||
|
|
||||||
|
using StringTools;
|
||||||
|
|
||||||
|
class ScenData {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public var floorData:Map<Int, FloorData> = [];
|
||||||
|
|
||||||
|
public function load(file:String) {
|
||||||
|
var scenDataLines = File.getContent(file).replace("\r", "\n").split("\n");
|
||||||
|
var parser = new Parser();
|
||||||
|
var interp = new Interp();
|
||||||
|
|
||||||
|
var defining = "";
|
||||||
|
var id = -1;
|
||||||
|
var data:Dynamic = null;
|
||||||
|
interp.variables["data"] = null;
|
||||||
|
|
||||||
|
function commitData() {
|
||||||
|
data = interp.variables["data"];
|
||||||
|
if (data == null) return;
|
||||||
|
trace(data);
|
||||||
|
|
||||||
|
switch (defining) {
|
||||||
|
case "floor":
|
||||||
|
floorData[id] = data;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
data = data.clone();
|
||||||
|
}
|
||||||
|
function clear(?type:String) {
|
||||||
|
if (type == null) type = defining;
|
||||||
|
data = switch (type) {
|
||||||
|
case "floor":
|
||||||
|
new FloorData();
|
||||||
|
default:
|
||||||
|
null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function beginDefine(type, tid) {
|
||||||
|
commitData();
|
||||||
|
|
||||||
|
if (defining != type) {
|
||||||
|
clear(type);
|
||||||
|
}
|
||||||
|
interp.variables["data"] = data;
|
||||||
|
|
||||||
|
defining = type;
|
||||||
|
id = tid;
|
||||||
|
}
|
||||||
|
interp.variables["beginDefine"] = beginDefine;
|
||||||
|
interp.variables["beginscendatascript"] = null;
|
||||||
|
interp.variables["clear"] = clear;
|
||||||
|
|
||||||
|
for (line in scenDataLines) {
|
||||||
|
var commentIndex = line.indexOf("//");
|
||||||
|
if (commentIndex != -1) {
|
||||||
|
line = line.substr(0, commentIndex);
|
||||||
|
}
|
||||||
|
line = line.trim();
|
||||||
|
if (line.length > 0) {
|
||||||
|
if (line.startsWith("begindefine")) {
|
||||||
|
line = "beginDefine('" + line.replace("begindefine", "").replace(" ", "',").replace(";", ");");
|
||||||
|
} else if (line.startsWith("fl_")) {
|
||||||
|
line = line.replace("fl_", "data.");
|
||||||
|
} else if (line == "clear;") {
|
||||||
|
line = "clear();";
|
||||||
|
}
|
||||||
|
trace(line);
|
||||||
|
interp.execute(parser.parseString(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit the last data object that was defined:
|
||||||
|
commitData();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user