Skip to content

Commit

Permalink
Added ruiles biome support
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Nov 29, 2023
1 parent 1af0b20 commit a2c8b36
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/assets/css/app.min.css

Large diffs are not rendered by default.

43 changes: 34 additions & 9 deletions app/assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,7 @@ select {
cursor: pointer;
}

&.isNull,
&.gray {
border: 1px dashed $bgLight;
padding: 8px;
Expand Down Expand Up @@ -3725,12 +3726,27 @@ textarea {
strong {
color: $orangeLight;
}
.icon {
.icon:not(.selectionTick) {
opacity: 0.7;
width: 18px;
height: 18px;
margin-right: 3px;
}
img {
margin-right: 3px;
}
.icon.selectionTick {
width: 24px;
height: 24px;
margin-left: 3px;
}
&.selected {
background-color: $bgMed;
color: white;
* {
color: white;
}
}
.sub {
display: block;
margin-top: 2px;
Expand Down Expand Up @@ -3780,7 +3796,10 @@ textarea {
box-shadow: none;
}
button:not(.contextMenuOpen) {
opacity: 0.3;
opacity: 0.2;
}
button.contextMenuOpen {
opacity: 0.5;
}
}

Expand Down Expand Up @@ -8401,20 +8420,20 @@ body.sorting ul.collapsedSortTarget {

&.inactive {
header {
opacity: 0.5;
opacity: 0.35;
.name:hover .text {
color: $almostWhite;
}
}
&:not(.optional) header {
background-color: $bgDark;
background-image: url("../img/stripes.png");
background-color: $bgDark !important;
// background-image: url("../img/stripes.png");
.name {
color: $bgLighter;
color: $bgLight;
}
}
&.optional header {
background-color: #0f4973;
background-color: #0f4973 !important;
background-image: url("../img/stripes.png");
}
ul.ruleGroup {
Expand Down Expand Up @@ -8539,8 +8558,14 @@ body.sorting ul.collapsedSortTarget {
background-color: $red;
}

&.groupActive .icon {
width: 100%;
&.groupActive {
img {
width: 30px !important;
height: auto !important;
}
.icon {
width: 30px;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/assets/tpl/editAllAutoLayerRules.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2><span class="icon rule"></span> Rules: ::layer::</h2>
<div class="text"></div>
</div>
<input type="text" class="name"/>
<button class="groupActive transparent"> <span class="icon"></span> </button>
<button class="groupActive transparent"></button>
<button class="useWizard">EDIT</button>
<button class="addRule"><span class="icon add"></span></button>
</header>
Expand Down
12 changes: 12 additions & 0 deletions app/assets/tpl/editLayerDefs.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ <h2>
</dd>


<dt class="IntGrid AutoLayer">
<label>Biome enum</label>
<info>
You can use an Enum field from your level custom fields as a "biome selector".
Auto-layer rule groups may then be individually enabled when a certain biome is picked.
</info>
</dt>
<dd class="IntGrid AutoLayer">
<select name="biomeField"></select>
</dd>


<dt class="Entities">
<label>Required tags</label>
<info>
Expand Down
2 changes: 1 addition & 1 deletion src/electron.renderer/data/DataTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef AutoLayerRuleGroup = {
var rules : Array<data.def.AutoLayerRuleDef>;
var isOptional : Bool;
var usesWizard : Bool;
var biomeFieldUid : Int;
var biomeEnumValues : Array<String>;
}

typedef GridTileInfos = {
Expand Down
8 changes: 8 additions & 0 deletions src/electron.renderer/data/Level.hx
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ class Level {
return fieldInstances.get(fd.uid);
}

public function getFieldInstanceByUid(fdUid:Int, createIfMissing:Bool) : Null<data.inst.FieldInstance> {
if( createIfMissing && !fieldInstances.exists(fdUid) ) {
fieldInstances.set( fdUid, new data.inst.FieldInstance(_project, fdUid) );
invalidateJsonCache();
}
return fieldInstances.get(fdUid);
}


public function getSmartColor(bright:Bool) : dn.Col {
inline function _adjust(c:Int) {
Expand Down
10 changes: 7 additions & 3 deletions src/electron.renderer/data/def/LayerDef.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class LayerDef {
public var parallaxFactorY : Float = 0.;
public var parallaxScaling : Bool = true;
public var tilesetDefUid : Null<Int>;
public var biomeFieldUid : Null<Int>;

// Entities
public var requiredTags : Tags;
Expand Down Expand Up @@ -109,6 +110,7 @@ class LayerDef {
o.parallaxFactorX = JsonTools.readFloat(json.parallaxFactorX, 0);
o.parallaxFactorY = JsonTools.readFloat(json.parallaxFactorY, 0);
o.parallaxScaling = JsonTools.readBool(json.parallaxScaling, true);
o.biomeFieldUid = JsonTools.readNullableInt(json.biomeFieldUid);

o.requiredTags = Tags.fromJson(json.requiredTags);
o.excludedTags = Tags.fromJson(json.excludedTags);
Expand Down Expand Up @@ -207,6 +209,8 @@ class LayerDef {
tilesetDefUid: tilesetDefUid,
tilePivotX: tilePivotX,
tilePivotY: tilePivotY,

biomeFieldUid: biomeFieldUid,
}
}

Expand All @@ -220,7 +224,7 @@ class LayerDef {
isOptional: rg.isOptional,
rules: rg.rules.map( function(r) return r.toJson(this) ),
usesWizard: rg.usesWizard,
biomeFieldUid: rg.biomeFieldUid,
biomeEnumValues: rg.biomeEnumValues,
}
}

Expand All @@ -238,7 +242,7 @@ class LayerDef {
});
rg.collapsed = true;
rg.usesWizard = JsonTools.readBool( ruleGroupJson.usesWizard, false );
rg.biomeFieldUid = JsonTools.readInt( ruleGroupJson.biomeFieldUid, -1 );
rg.biomeEnumValues = JsonTools.readArray( ruleGroupJson.biomeEnumValues, [] );
return rg;
}

Expand Down Expand Up @@ -573,7 +577,7 @@ class LayerDef {
collapsed: false,
isOptional: false,
usesWizard: false,
biomeFieldUid: -1,
biomeEnumValues: [],
rules: [],
}
if( index!=null )
Expand Down
10 changes: 10 additions & 0 deletions src/electron.renderer/data/inst/FieldInstance.hx
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,16 @@ class FieldInstance {
}
}


public function getEnumValueTileRect(arrayIdx:Int) : Null<ldtk.Json.TilesetRect> {
require( F_Enum(null) );
var v = getEnumValue(arrayIdx);
if( v==null )
return null;
else
return def.getEnumDefinition().getValue(v).tileRect;
}

public function getPointStr(arrayIdx:Int) : Null<String> {
require( F_Point );
return isUsingDefault(arrayIdx) ? def.getPointDefault() : switch internalValues[arrayIdx] {
Expand Down
13 changes: 12 additions & 1 deletion src/electron.renderer/data/inst/LayerInstance.hx
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,18 @@ class LayerInstance {



public inline function isRuleGroupActiveHere(rg:AutoLayerRuleGroup) {
public function isRuleGroupActiveHere(rg:AutoLayerRuleGroup) {
if( rg.biomeEnumValues.length>0 ) {
var fi = level.getFieldInstanceByUid(def.biomeFieldUid, false);
if( fi!=null ) {
for(idx in 0...fi.getArrayLength())
for(bid in rg.biomeEnumValues)
if( bid==fi.getEnumValue(idx) )
return true;
return false;
}
}

return rg.active && !rg.isOptional || optionalRules.exists(rg.uid);
}

Expand Down
19 changes: 17 additions & 2 deletions src/electron.renderer/misc/JsTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,31 @@ class JsTools {
}


public static function createValuesSelect<T>(?jSelect:js.jquery.JQuery, cur:T, allValues:Array<T>, ?def:T, ?printer:T->String, onSelect:T->Void) {
public static function createValuesSelect<T>(?jSelect:js.jquery.JQuery, cur:Null<T>, allValues:Array<T>, allowNull:Bool, ?def:T, ?printer:T->String, onSelect:T->Void) {
if( jSelect==null )
jSelect = new J('<select/>');
else
else {
jSelect.empty().off();
jSelect.removeClass("isNull");
}

// Ensure cur is part of allValues
if( !allValues.contains(cur) )
cur = def;

// "None" option
if( allowNull ) {
var jOpt = new J("<option/>");
jSelect.prepend(jOpt);
jOpt.text( printer==null ? Lang.t._("(none)") : printer(null) );
jOpt.attr("value", "");
if( cur==null ) {
jSelect.addClass("isNull");
jOpt.attr("selected","selected");
}
}

// Values
var i = 0;
for(v in allValues) {
var jOpt = new J('<option value="$i"/>');
Expand Down
25 changes: 20 additions & 5 deletions src/electron.renderer/ui/modal/ContextMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import dn.data.GetText.LocaleString;
typedef ContextActions = Array<ContextAction>;
typedef ContextAction = {
var label : LocaleString;
var ?icon : String;
var ?icon : String; // TODO rename iconId
var ?jHtmlImg : js.jquery.JQuery;
var ?subText : Null<LocaleString>;
var ?className : String;
var ?cb : Void->Void;
var ?show : Void->Bool;
var ?enable : Void->Bool;
var ?separatorBefore: Bool;
var ?separatorAfter: Bool;
var ?subActions: ContextActions;
var ?subMenu: Void->ContextActions;
var ?selectionTick : Bool;
}

class ContextMenu extends ui.Modal {
Expand Down Expand Up @@ -133,7 +135,11 @@ class ContextMenu extends ui.Modal {
if( a.show!=null && !a.show() )
return jButton;
jButton.appendTo(jContent);
if( a.icon!=null )
if( a.jHtmlImg!=null ) {
jButton.prepend(a.label);
jButton.prepend(a.jHtmlImg);
}
else if( a.icon!=null )
jButton.prepend('<span class="icon ${a.icon}"></span> ${a.label}');
else
jButton.html(a.label);
Expand All @@ -148,15 +154,15 @@ class ContextMenu extends ui.Modal {
jButton.addClass(a.className);

jButton.click( (_)->{
if( a.subActions==null )
if( a.subMenu==null )
closeAll();
else {
addClass("subMenuOpen");
var c = new ContextMenu(jButton, true);
c.onCloseCb = ()->{
removeClass("subMenuOpen");
}
for(subAction in a.subActions)
for(subAction in a.subMenu())
c.add(subAction);
}
if( a.cb!=null )
Expand All @@ -169,6 +175,15 @@ class ContextMenu extends ui.Modal {
if( a.separatorAfter )
jButton.addClass("separatorAfter");

if( a.selectionTick!=null ) {
if( a.selectionTick ) {
jButton.addClass("selected");
jButton.append('<span class="icon selectionTick active"></span>');
}
else
jButton.append('<span class="icon selectionTick inactive"></span>');
}

applyAnchor();
return jButton;
}
Expand Down
1 change: 1 addition & 0 deletions src/electron.renderer/ui/modal/dialog/EditAppSettings.hx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class EditAppSettings extends ui.modal.Dialog {
jForm.find("#singleLayerModeIntensity"),
settings.v.singleLayerModeIntensity,
allValues,
false,
0.9,
(v)->Std.string(v*100)+"%",
(v)->{
Expand Down
Loading

0 comments on commit a2c8b36

Please sign in to comment.