Improve configData.merge, 'create' fix
This commit is contained in:
@@ -20,44 +20,6 @@ import haxe.ds.StringMap;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function copyFieldsPreferObjectOverValue<T> (source:T, destination:T):T {
|
|
||||||
|
|
||||||
|
|
||||||
for (field in Reflect.fields (source)) {
|
|
||||||
|
|
||||||
var do_copy = true;
|
|
||||||
var exists = Reflect.hasField( destination, field );
|
|
||||||
|
|
||||||
if( exists ) {
|
|
||||||
var value_source = Reflect.field (source, field);
|
|
||||||
var value_dest = Reflect.field (destination, field);
|
|
||||||
var type_source = Type.typeof(value_source).getName();
|
|
||||||
var type_dest = Type.typeof(value_dest).getName();
|
|
||||||
|
|
||||||
// if(LogHelper.verbose) {
|
|
||||||
// LogHelper.println(field + " / existed in dest as " + type_dest + " / " + type_source );
|
|
||||||
// }
|
|
||||||
|
|
||||||
//if trying to copy a non object over an object, don't
|
|
||||||
if(type_source != "TObject" && type_dest == "TObject") {
|
|
||||||
do_copy = false;
|
|
||||||
if(LogHelper.verbose) {
|
|
||||||
LogHelper.println(field + " not merged by preference" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(do_copy) {
|
|
||||||
Reflect.setField (destination, field, Reflect.field (source, field));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return destination;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static function copyMissingFields<T> (source:T, destination:T):T {
|
public static function copyMissingFields<T> (source:T, destination:T):T {
|
||||||
|
|
||||||
|
|||||||
@@ -268,7 +268,65 @@ abstract ConfigData(Dynamic) to Dynamic from Dynamic {
|
|||||||
|
|
||||||
if (other != null) {
|
if (other != null) {
|
||||||
|
|
||||||
ObjectHelper.copyFieldsPreferObjectOverValue (other, this);
|
mergeValues (other, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function mergeValues<T> (source:T, destination:T):Void {
|
||||||
|
|
||||||
|
for (field in Reflect.fields (source)) {
|
||||||
|
|
||||||
|
var doCopy = true;
|
||||||
|
var exists = Reflect.hasField (destination, field);
|
||||||
|
var typeDest = null;
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
|
||||||
|
var valueSource = Reflect.field (source, field);
|
||||||
|
var valueDest = Reflect.field (destination, field);
|
||||||
|
var typeSource = Type.typeof(valueSource).getName ();
|
||||||
|
typeDest = Type.typeof (valueDest).getName ();
|
||||||
|
|
||||||
|
//if trying to copy a non object over an object, don't
|
||||||
|
if (typeSource != "TObject" && typeDest == "TObject") {
|
||||||
|
|
||||||
|
doCopy = false;
|
||||||
|
|
||||||
|
//if (LogHelper.verbose) {
|
||||||
|
//
|
||||||
|
//LogHelper.println (field + " not merged by preference");
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringTools.endsWith (field, "___array")) {
|
||||||
|
|
||||||
|
doCopy = false;
|
||||||
|
var array:Array<Dynamic> = cast Reflect.field (destination, field);
|
||||||
|
array = array.concat (cast Reflect.field (source, field));
|
||||||
|
Reflect.setField (destination, field, array);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doCopy) {
|
||||||
|
|
||||||
|
if (typeDest == "TObject") {
|
||||||
|
|
||||||
|
mergeValues (Reflect.field (source, field), Reflect.field (destination, field));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Reflect.setField (destination, field, Reflect.field (source, field));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,11 +83,16 @@ class CreateTemplate {
|
|||||||
var sampleName = null;
|
var sampleName = null;
|
||||||
var outputName = "SampleProject";
|
var outputName = "SampleProject";
|
||||||
|
|
||||||
if (colonIndex == -1 && words.length > 1) {
|
if (colonIndex == -1) {
|
||||||
|
|
||||||
projectName = words[0];
|
projectName = words[0];
|
||||||
|
|
||||||
|
if (words.length > 1) {
|
||||||
|
|
||||||
sampleName = words[1];
|
sampleName = words[1];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (words.length > 2) {
|
if (words.length > 2) {
|
||||||
|
|
||||||
outputName = words[2];
|
outputName = words[2];
|
||||||
@@ -107,13 +112,25 @@ class CreateTemplate {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (projectName == "project") {
|
||||||
|
|
||||||
|
projectName = "lime";
|
||||||
|
|
||||||
|
if (sampleName != null) {
|
||||||
|
|
||||||
|
outputName = sampleName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (projectName == null || projectName == "") {
|
if (projectName == null || projectName == "") {
|
||||||
|
|
||||||
projectName = "lime";
|
projectName = "lime";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectName != null && projectName != "" && sampleName == "project") {
|
if (projectName != null && projectName != "") {
|
||||||
|
|
||||||
var defines = new Map <String, Dynamic> ();
|
var defines = new Map <String, Dynamic> ();
|
||||||
defines.set ("create", 1);
|
defines.set ("create", 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user