From 5ee3082a3902ec60f661d9ed0f4485d2408b9563 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 20 Oct 2014 10:48:39 -0700 Subject: [PATCH] Improve configData.merge, 'create' fix --- tools/helpers/ObjectHelper.hx | 38 ---------------------- tools/project/ConfigData.hx | 60 ++++++++++++++++++++++++++++++++++- tools/utils/CreateTemplate.hx | 23 ++++++++++++-- 3 files changed, 79 insertions(+), 42 deletions(-) diff --git a/tools/helpers/ObjectHelper.hx b/tools/helpers/ObjectHelper.hx index 9ef27a0d1..22539644c 100644 --- a/tools/helpers/ObjectHelper.hx +++ b/tools/helpers/ObjectHelper.hx @@ -20,44 +20,6 @@ import haxe.ds.StringMap; } - public static function copyFieldsPreferObjectOverValue (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 (source:T, destination:T):T { diff --git a/tools/project/ConfigData.hx b/tools/project/ConfigData.hx index 3f9c0a545..8e88f203f 100644 --- a/tools/project/ConfigData.hx +++ b/tools/project/ConfigData.hx @@ -268,7 +268,65 @@ abstract ConfigData(Dynamic) to Dynamic from Dynamic { if (other != null) { - ObjectHelper.copyFieldsPreferObjectOverValue (other, this); + mergeValues (other, this); + + } + + } + + + private function mergeValues (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 = 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)); + + } + + } } diff --git a/tools/utils/CreateTemplate.hx b/tools/utils/CreateTemplate.hx index 2a37dd637..84217d5cf 100644 --- a/tools/utils/CreateTemplate.hx +++ b/tools/utils/CreateTemplate.hx @@ -83,10 +83,15 @@ class CreateTemplate { var sampleName = null; var outputName = "SampleProject"; - if (colonIndex == -1 && words.length > 1) { + if (colonIndex == -1) { projectName = words[0]; - sampleName = words[1]; + + if (words.length > 1) { + + sampleName = words[1]; + + } if (words.length > 2) { @@ -107,13 +112,25 @@ class CreateTemplate { } + if (projectName == "project") { + + projectName = "lime"; + + if (sampleName != null) { + + outputName = sampleName; + + } + + } + if (projectName == null || projectName == "") { projectName = "lime"; } - if (projectName != null && projectName != "" && sampleName == "project") { + if (projectName != null && projectName != "") { var defines = new Map (); defines.set ("create", 1);