Skip to content

Commit

Permalink
Merge commit 'e92e8dde6c8cf029874e12c25d1a800e21069067' into dev-1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Sep 19, 2023
2 parents 67f3052 + e92e8dd commit 44d4add
Show file tree
Hide file tree
Showing 27 changed files with 2,305 additions and 751 deletions.
2 changes: 1 addition & 1 deletion app/assets/css/app.min.css

Large diffs are not rendered by default.

379 changes: 273 additions & 106 deletions app/assets/css/app.scss

Large diffs are not rendered by default.

Binary file modified app/assets/embedAtlas/finalbossblues-icons_full_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 16 additions & 7 deletions app/assets/tpl/editLayerDefs.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,28 @@ <h2>
<label>Grid values</label>
<info>The list of all Integer values that could be painted in this IntGrid layer.</info>
</dt>
<dd class="IntGrid">
<ul class="intGridValues">
<li class="add">
<button type="button" class="gray">+</button>
</li>
</ul>
<dd class="IntGrid intGridValues">
<div class="buttons">
<button class="gray addValue" title="Create an IntGrid value"> <span class="icon add"></span> </button>
<button class="gray addGroup" title="Create a group of IntGrid values"> <span class="icon folder"></span> </button>
</div>
<ul class="intGridValuesGroups"></ul>

<xml id="intGridValuesGroup">
<div class="header">
<span class="icon folderClose groupIcon"></span>
<span class="name"></span>
<!-- <button class="transparent delete" title="Delete this group and ALL its values"> <span class="icon delete red"></span> </button> -->
</div>
<ul class="intGridValuesGroup"></ul>
</xml>

<xml id="intGridValue">
<div class="sortHandle"></div>
<span class="id">?</span>
<input type="color" value="#ffffff"/>
<span class="tile"></span>
<input type="text" class="name" placeholder="Optional value identifier"/>
<input type="color" value="#ffffff"/>
<button class="red remove"><span class="icon delete"></span></button>
</xml>
</dd>
Expand Down
8 changes: 4 additions & 4 deletions app/assets/tpl/ruleEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@


<div class="pattern">
<div class="values" title="This panel shows all the IntGrid values defined in this layer">
<div class="valuePalette" title="This panel shows all the IntGrid values, as defined in this layer">
<button class="transparent displayMode"> <span class="icon gridView"></span> </button>
<ul></ul>
<ul class="groups"></ul>
</div>

<div class="editor">
Expand All @@ -39,8 +39,8 @@
<ul>
<li><span class="icon mouseLeft"></span>: paint "This IntGrid value is required" in a cell</li>
<li><span class="icon mouseRight"></span>: paint "This IntGrid value should NOT be here".</li>
<li><span class="icon mouseMiddle"></span>: clear pattern cell".</li>
<li>Use the <strong>Anything</strong> special value to match "Any IntGrid value" or "No IntGrid value at all"</li>
<li><span class="icon mouseMiddle"></span>: clear pattern cell.</li>
<li>Use the <strong>Any Value</strong> special value to match "Any IntGrid value" or "No IntGrid value at all"</li>
</ul>
<p>
For example, if you want to paint "wall blocks" where you have the IntGrid value "1" in your level, you just put the IntGrid value "1" in the center of this pattern.
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"codemirror": "^5.64.0",
"electron-updater": "^5.3.0",
"simple-color-picker": "^1.0.5",
"sortablejs": "^1.14.0"
"sortablejs": "^1.15.0"
},
"devDependencies": {
"electron": "^24.1.2",
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added a "symetric link" option to Auto-Layer rules offsets
- Increased the max number of columns in Select components
- Fixed out-of-screen color picker window
- Added background behind transparent rule tiles

# 1.3.4

Expand Down
2 changes: 1 addition & 1 deletion src/electron.renderer/Const.hx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Const {
}

public static var AUTO_LAYER_ANYTHING = 1000001;
public static var MAX_AUTO_PATTERN_SIZE = 7;
public static var MAX_AUTO_PATTERN_SIZE = 9;
#end


Expand Down
1 change: 1 addition & 0 deletions src/electron.renderer/data/DataTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef IntGridValueDefEditor = {
var identifier : Null<String>;
var color : dn.Col;
var tile : Null<ldtk.Json.TilesetRect>;
var groupUid : Int;
}

enum ValueWrapper {
Expand Down
18 changes: 17 additions & 1 deletion src/electron.renderer/data/def/AutoLayerRuleDef.hx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ class AutoLayerRuleDef {
for(px in 0...size)
for(py in 0...size) {
v = dn.M.iabs( pattern[px+py*size] );
if( v!=0 && v!=Const.AUTO_LAYER_ANYTHING && !ld.hasIntGridValue(v) )
if( v==0 )
continue;

if( v<=999 && !ld.hasIntGridValue(v) )
return true;

if( v>999 && v!=Const.AUTO_LAYER_ANYTHING && ld.getIntGridGroup( ld.resolveIntGridGroupUidFromRuleValue(v), false )==null )
return true;
}

Expand All @@ -282,6 +288,7 @@ class AutoLayerRuleDef {

// Rule check
var value : Null<Int> = 0;
var valueInf : Null<data.DataTypes.IntGridValueDefEditor> = null;
var radius = Std.int( size/2 );
for(px in 0...size)
for(py in 0...size) {
Expand All @@ -304,6 +311,15 @@ class AutoLayerRuleDef {
if( pattern[coordId]<0 && value!=0 )
return false;
}
else if( dn.M.iabs( pattern[coordId] ) > 999 ) {
// Group checks
valueInf = source.def.getIntGridValueDef(value);
if( pattern[coordId]>0 && ( valueInf==null || valueInf.groupUid != Std.int(pattern[coordId]/1000)-1 ) )
return false;

if( pattern[coordId]<0 && ( valueInf!=null && valueInf.groupUid == Std.int(-pattern[coordId]/1000)-1 ) )
return false;
}
else {
// Specific value checks
if( pattern[coordId]>0 && value != pattern[coordId] )
Expand Down
152 changes: 145 additions & 7 deletions src/electron.renderer/data/def/LayerDef.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class LayerDef {
// IntGrid
@:allow(importer)
var intGridValues : Array<IntGridValueDefEditor> = [];
var intGridValuesGroups : Array<ldtk.Json.IntGridValueGroupDef> = [];

// IntGrid/AutoLayers
public var autoSourceLayerDefUid : Null<Int>;
Expand Down Expand Up @@ -113,18 +114,29 @@ class LayerDef {
o.excludedTags = Tags.fromJson(json.excludedTags);

o.intGridValues = [];
o.intGridValuesGroups = [];
if( o.type==IntGrid ) {
var all : Array<IntGridValueDefEditor> = JsonTools.readArray(json.intGridValues);
// IntGrid values
var allValues : Array<IntGridValueDefEditor> = JsonTools.readArray(json.intGridValues);
var fixedIdx = 1; // fix old projects missing intgrid "value" field
for( v in all ) {
for( v in allValues ) {
o.intGridValues.push({
value: M.isValidNumber(v.value) ? v.value : fixedIdx,
identifier: v.identifier,
color: JsonTools.readColor(v.color),
tile: JsonTools.readTileRect(v.tile, true),
groupUid: JsonTools.readInt(v.groupUid, 0),
});
fixedIdx++;
}
// Groups
if( json.intGridValuesGroups==null )
json.intGridValuesGroups = [];
o.intGridValuesGroups = json.intGridValuesGroups.map(g->{
uid: g.uid,
identifier: g.identifier,
color: g.color,
});
}

o.autoSourceLayerDefUid = JsonTools.readNullableInt(json.autoSourceLayerDefUid);
Expand Down Expand Up @@ -180,6 +192,13 @@ class LayerDef {
identifier: iv.identifier,
color: JsonTools.writeColor(iv.color),
tile: JsonTools.writeTileRect(iv.tile),
groupUid: iv.groupUid,
}),

intGridValuesGroups: intGridValuesGroups.map(g->{
uid: g.uid,
identifier: g.identifier,
color: g.color,
}),

autoRuleGroups: isAutoLayer() ? autoRuleGroups.map( function(rg) return toJsonRuleGroup(rg)) : [],
Expand Down Expand Up @@ -224,18 +243,46 @@ class LayerDef {
}


public function sortIntGridValueDef(from:Int, to:Int) : Null<IntGridValueDefEditor> {
public function sortIntGridValueDef(valueId:Int, fromGroupUid:Int, toGroupUid:Int, fromGroupIdx:Int, toGroupIdx:Int) : Null<IntGridValueDefEditor> {
if( type!=IntGrid )
return null;

if( from<0 || from>=intGridValues.length || from==to )
if( !hasIntGridValue(valueId) || fromGroupUid==toGroupUid && fromGroupIdx==toGroupIdx )
return null;

var groupedValues = getGroupedIntGridValues();
var moved = getIntGridValueDef(valueId);

// Order values
var toGroup = groupedValues.filter( g->g.groupUid==toGroupUid )[0];
if( toGroup.all.length>0 ) {
if( toGroupIdx>=toGroup.all.length || fromGroupUid==toGroupUid && toGroupIdx>fromGroupIdx ) {
var insertAfter = toGroup.all[toGroup.all.length-1];
intGridValues.splice( intGridValues.indexOf(moved), 1 );
intGridValues.insert( intGridValues.indexOf(insertAfter)+1, moved );
}
else {
var insertBefore = toGroup.all[toGroupIdx];
intGridValues.splice( intGridValues.indexOf(moved), 1 );
intGridValues.insert( intGridValues.indexOf(insertBefore), moved );
}
}

// Change group
moved.groupUid = toGroupUid;

return moved;
}

public function sortIntGridValueGroupDef(from:Int, to:Int) : Null<ldtk.Json.IntGridValueGroupDef> {
if( from<0 || from>=intGridValuesGroups.length || from==to )
return null;

if( to<0 || to>=intGridValues.length )
if( to<0 || to>=intGridValuesGroups.length )
return null;

var moved = intGridValues.splice(from,1)[0];
intGridValues.insert(to, moved);
var moved = intGridValuesGroups.splice(from,1)[0];
intGridValuesGroups.insert(to, moved);

return moved;
}
Expand All @@ -259,11 +306,28 @@ class LayerDef {
color: col,
identifier: id,
tile: null,
groupUid: 0,
});

return iv;
}


public function addIntGridGroup() : ldtk.Json.IntGridValueGroupDef {
var uniqUid = 1;
for(g in intGridValuesGroups)
uniqUid = M.imax(uniqUid, g.uid+1);

var g : ldtk.Json.IntGridValueGroupDef = {
uid: uniqUid,
identifier: null,
color: null,
}
intGridValuesGroups.push(g);
return g;
}


public inline function hasIntGridValue(v:Int) {
return getIntGridValueDef(v)!=null;
}
Expand Down Expand Up @@ -307,7 +371,81 @@ class LayerDef {
return false;
}

public function removeIntGridGroup(groupUid:Int) : Bool {
for(iv in intGridValues)
if( iv.groupUid==groupUid )
return false;

for(g in intGridValuesGroups)
if( g.uid==groupUid ) {
intGridValuesGroups.remove(g);
return true;
}

return false;
}

public inline function getAllIntGridValues() return intGridValues;

public function getIntGridGroup(groupUid:Int, returnUngrouped=true) {
for(g in intGridValuesGroups)
if( g.uid==groupUid )
return {
groupUid: g.uid,
displayName: g.identifier==null ? 'Group ${g.uid}' : g.identifier,
color: g.color==null ? null : dn.Col.parseHex(g.color),
groupInf: g,
all: intGridValues.filter( iv->iv.groupUid==g.uid ),
}

if( returnUngrouped )
return {
groupUid: 0,
displayName: "Ungrouped",
color: null,
groupInf: null,
all: intGridValues.filter( iv->iv.groupUid==0 ),
}
else
return null;
}

public inline function resolveIntGridGroupUidFromRuleValue(ruleValue:Int) {
return Std.int(ruleValue/1000)-1;
}

public inline function hasIntGridGroups() {
return intGridValuesGroups.length>0;
}

public function getGroupedIntGridValues() {
var groups : Array<{
groupUid: Int,
displayName: String,
color: Null<dn.Col>,
groupInf:Null<ldtk.Json.IntGridValueGroupDef>,
all:Array<IntGridValueDefEditor>
}> = [];

groups.push({
groupUid: 0,
displayName: "Ungrouped",
color: null,
groupInf: null,
all: intGridValues.filter( iv->iv.groupUid==0 ),
});
for(g in intGridValuesGroups) {
groups.push({
groupUid: g.uid,
displayName: g.identifier==null ? 'Group ${g.uid}' : g.identifier,
color: g.color==null ? null : dn.Col.parseHex(g.color),
groupInf: g,
all: intGridValues.filter( iv->iv.groupUid==g.uid ),
});
}
return groups;
}

public inline function countIntGridValues() return intGridValues.length;

public function isIntGridValueIdentifierValid(id:Null<String>) {
Expand Down
6 changes: 3 additions & 3 deletions src/electron.renderer/data/inst/LayerInstance.hx
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ class LayerInstance {
));
}

inline function runAutoLayerRuleAt(source:LayerInstance, r:data.def.AutoLayerRuleDef, cx:Int, cy:Int) : Bool {
function applyAutoLayerRuleAt(source:LayerInstance, r:data.def.AutoLayerRuleDef, cx:Int, cy:Int) : Bool {
if( !def.autoLayerRulesCanBeUsed() )
return false;
else {
Expand Down Expand Up @@ -907,7 +907,7 @@ class LayerInstance {
def.iterateActiveRulesInEvalOrder( this, (r)->{
for(x in left...right+1)
for(y in top...bottom+1)
runAutoLayerRuleAt(source, r, x,y);
applyAutoLayerRuleAt(source, r, x,y);
});

// Discard using break-on-match flag
Expand Down Expand Up @@ -940,7 +940,7 @@ class LayerInstance {

for(cx in 0...cWid)
for(cy in 0...cHei)
runAutoLayerRuleAt(source, r, cx,cy);
applyAutoLayerRuleAt(source, r, cx,cy);

if( applyBreakOnMatch )
applyBreakOnMatchesEverywhere();
Expand Down
Loading

0 comments on commit 44d4add

Please # to comment.