Skip to content

Commit

Permalink
Added debug flags
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Jan 9, 2024
1 parent 859b534 commit 228d517
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
21 changes: 20 additions & 1 deletion src/electron.renderer/App.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class App extends dn.Process {
public var pendingUpdate : Null<{ ver:String, github:Bool }>;

public var keyBindings : Array<KeyBinding> = [];
var debugFlags : Map<DebugFlag,Bool> = new Map();

public function new() {
super();
Expand Down Expand Up @@ -1054,6 +1055,24 @@ class App extends dn.Process {
}
}


public function setDebugFlag(f:DebugFlag, active=true) {
clearDebug();
if( active )
debugFlags.set(f, true);
else
debugFlags.remove(f);
}

public function toggleDebugFlag(f:DebugFlag) {
setDebugFlag(f, !hasDebugFlag(f));
}

public inline function hasDebugFlag(f:DebugFlag) {
return debugFlags.exists(f);
}


override function preUpdate() {
super.preUpdate();
_inputFocusCache = null;
Expand Down Expand Up @@ -1083,7 +1102,7 @@ class App extends dn.Process {
}

// Debug print
if( cd.has("debugTools") ) {
if( hasDebugFlag(F_MainDebug) ) {
clearDebug();
debug("-- Misc ----------------------------------------");
debugPre('Electron: ${Const.getElectronVersion()}');
Expand Down
6 changes: 6 additions & 0 deletions src/electron.renderer/EditorTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,10 @@ enum AppCommand {
@k("r") C_ToggleTileRandomMode;
@k("[arrows] s, shift s") C_SaveTileSelection;
@k("shift l") C_LoadTileSelection;
}


enum DebugFlag {
F_MainDebug;
F_IntGridUseCounts;
}
24 changes: 24 additions & 0 deletions src/electron.renderer/page/Editor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2792,5 +2792,29 @@ class Editor extends Page {
// Auto re-hide panel in zen mode
if( settings.v.zenMode && cd.has("pendingZenModeReHide") && !cd.has("zenModeReHideLock") )
setZenModeReveal(false);

if( App.ME.hasDebugFlag(F_IntGridUseCounts) ) {
App.ME.clearDebug();
@:privateAccess
for(li in curLevel.layerInstances) {
if( li.def.type==IntGrid ) {
// Show cached area counts
App.ME.debugPre(li.toString());
App.ME.debugPre(" "+li.areaIntGridUseCount);
}
if( li.def.isAutoLayer() ) {
// Count relevant rules
for(rg in li.def.autoRuleGroups) {
var n = 0;
for(r in rg.rules)
if( r.isRelevantInLayer(li) )
n++;

if( n>0 )
App.ME.debugPre(" => "+rg.toString()+": "+n+" rule(s)");
}
}
}
}
}
}
32 changes: 26 additions & 6 deletions src/electron.renderer/ui/modal/DebugMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ class DebugMenu extends ui.modal.ContextMenu {
addAction({
label: L.untranslated("Toggle debug print"),
cb: ()->{
if( App.ME.cd.has("debugTools") ) {
App.ME.clearDebug();
App.ME.cd.unset("debugTools");
}
else
App.ME.cd.setS("debugTools", Const.INFINITE);
App.ME.clearDebug();
App.ME.toggleDebugFlag(F_MainDebug);
}
});

#if debug
addAction({
label: L.untranslated("Debug flags"),
cb: ()->new DebugMenu("debugFlags"),
});
#end

#if debug
addAction({
label: L.untranslated("Toggle timeline debug"),
Expand Down Expand Up @@ -300,6 +303,23 @@ class DebugMenu extends ui.modal.ContextMenu {



case "debugFlags":
addTitle( L.untranslated("Debug flags") );
for(k in DebugFlag.getConstructors()) {
var f = DebugFlag.createByName(k);
addAction({
label: L.untranslated(k),
iconId: App.ME.hasDebugFlag(f) ? "active" : "inactive",
selectionTick: App.ME.hasDebugFlag(f),
cb: ()->{
App.ME.toggleDebugFlag(f);
new DebugMenu(id);
},
});
}



case "dirs":

addTitle( L.untranslated("Locate dir") );
Expand Down

0 comments on commit 228d517

Please sign in to comment.