diff --git a/app/assets/tpl/editLayerDefs.html b/app/assets/tpl/editLayerDefs.html index 5c9a49194..d5ed1d424 100644 --- a/app/assets/tpl/editLayerDefs.html +++ b/app/assets/tpl/editLayerDefs.html @@ -231,7 +231,7 @@

- ? + diff --git a/src/electron.renderer/data/def/AutoLayerRuleDef.hx b/src/electron.renderer/data/def/AutoLayerRuleDef.hx index a354a87a9..6bbaa97c6 100644 --- a/src/electron.renderer/data/def/AutoLayerRuleDef.hx +++ b/src/electron.renderer/data/def/AutoLayerRuleDef.hx @@ -60,6 +60,19 @@ class AutoLayerRuleDef { explicitlyRequiredValues.push(v); } + public function updateIntGridValueDef(prev:Int,next:Int) { + // Use get/setPattern so that the usage counts, etc. are updated. + for(cx in 0...size) + for(cy in 0...size) { + if(getPattern(cx,cy) == prev) + setPattern(cx,cy,next); + // Negative values are used to store the logical negation of a tile, so we have to update them too. + if(getPattern(cx,cy) == -prev) + setPattern(cx,cy,-next); + } + updateUsedValues(); + } + public inline function hasAnyPositionOffset() { return tileRandomXMin!=0 || tileRandomXMax!=0 || tileRandomYMin!=0 || tileRandomYMax!=0 || tileXOffset!=0 || tileYOffset!=0; } diff --git a/src/electron.renderer/data/def/LayerDef.hx b/src/electron.renderer/data/def/LayerDef.hx index 73013d477..b2ce50c18 100644 --- a/src/electron.renderer/data/def/LayerDef.hx +++ b/src/electron.renderer/data/def/LayerDef.hx @@ -321,6 +321,13 @@ class LayerDef { return false; } + public function updateIntGridValueDef(prev:Int, next:Int) { + var iv = getIntGridValueDef(prev); + if(iv == null) + return; + iv.value = next; + } + public inline function getIntGridValueDef(value:Int) : Null { var out : Null = null; for(v in intGridValues) @@ -449,6 +456,18 @@ class LayerDef { public inline function countIntGridValues() return intGridValues.length; + public function isIntGridValueValid(value:Int) : Bool { + // Negative values are used to logically invert patterns, so zero and negative values are not allowed. + // AutoLayerRuleDef::isUsingUnknownIntGridValues requires the value be less than or equal to 999. + if ( value <= 0 || value > 999 ) + return false; + + for(v in intGridValues) + if ( v.value == value ) + return false; + return true; + } + public function isIntGridValueIdentifierValid(id:Null) { if( id==null || id=="" ) return true; diff --git a/src/electron.renderer/data/inst/LayerInstance.hx b/src/electron.renderer/data/inst/LayerInstance.hx index 8a4e0f29f..fa8c6828e 100644 --- a/src/electron.renderer/data/inst/LayerInstance.hx +++ b/src/electron.renderer/data/inst/LayerInstance.hx @@ -686,6 +686,27 @@ class LayerInstance { asyncErase(cx,cy); } + public function updateIntGridValue(prev:Int, next:Int, useAsyncRender:Bool) { + requireType(IntGrid); + def.updateIntGridValueDef(prev,next); + for(cy in 0...cHei) + for(cx in 0...cWid) + if ( getIntGrid(cx,cy) == prev ) + setIntGrid(cx,cy,next,useAsyncRender); + + // We update our own level definition separately because we don't appear in our own autoSourceLayerDefUid. + for(rg in def.autoRuleGroups) + for(r in rg.rules) + r.updateIntGridValueDef(prev, next); + + for(ld in _project.defs.layers) + if(ld.autoSourceLayerDefUid == layerDefUid) + for(rg in ld.autoRuleGroups) + for(r in rg.rules) + r.updateIntGridValueDef(prev, next); + + level.invalidateJsonCache(); + } /** ENTITY INSTANCE *******************/ diff --git a/src/electron.renderer/ui/Notification.hx b/src/electron.renderer/ui/Notification.hx index ab76a3efc..b481f95cc 100644 --- a/src/electron.renderer/ui/Notification.hx +++ b/src/electron.renderer/ui/Notification.hx @@ -92,6 +92,10 @@ class Notification extends dn.Process { } } + public static function invalidValue(value:Int) { + error( Lang.t._("The value \"::value::\" isn't valid, or isn't unique.", { value:value }) ); + } + public static function invalidIdentifier(id:String) { error( Lang.t._("The identifier \"::id::\" isn't valid, or isn't unique.", { id:id }) ); } diff --git a/src/electron.renderer/ui/modal/panel/EditLayerDefs.hx b/src/electron.renderer/ui/modal/panel/EditLayerDefs.hx index 2d1ffdf02..c86d9888e 100644 --- a/src/electron.renderer/ui/modal/panel/EditLayerDefs.hx +++ b/src/electron.renderer/ui/modal/panel/EditLayerDefs.hx @@ -681,13 +681,26 @@ class EditLayerDefs extends ui.modal.Panel { jValue.attr("valueId", Std.string(intGridVal.value)); jValue.addClass("value"); jValue.appendTo(jGroup); - jValue.find(".id") - .html( Std.string(intGridVal.value) ) - .css({ - color: C.intToHex( C.toWhite(intGridVal.color,0.5) ), - borderColor: C.intToHex( C.toWhite(intGridVal.color,0.2) ), - backgroundColor: C.intToHex( C.toBlack(intGridVal.color,0.5) ), - }); + + // Value + var i = new form.input.IntInput( + jValue.find("input.id"), + function() return intGridVal.value, + function(value) { + if( value != null ) { + jValue.attr("valueId", Std.string(value)); + editor.curLevel.getLayerInstance(cur).updateIntGridValue(intGridVal.value, value, false); + } + } + ); + i.validityCheck = cur.isIntGridValueValid; + i.validityError = N.invalidValue; + i.onChange = editor.ge.emit.bind(LayerDefChanged(cur.uid, false)); + i.jInput.css({ + color: C.intToHex( C.toWhite(intGridVal.color,0.5) ), + borderColor: C.intToHex( C.toWhite(intGridVal.color,0.2) ), + backgroundColor: C.intToHex( C.toBlack(intGridVal.color,0.5) ), + }); // Tile var jTile = jValue.find(".tile");