Skip to content

Commit

Permalink
moved source du DuAEF
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Duduf committed Sep 20, 2020
1 parent 63a8f1d commit 4135a82
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 236 deletions.
267 changes: 32 additions & 235 deletions src/DuSan.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,259 +6,56 @@ DuAEF.debug = true;
//polices manquantes

// Main Functions

function checkSave()
{
var proj = app.project;

var f = app.project.file;
var limit = 60000;
if (!(f instanceof File))
{
ui_saveText.setText("CRITICAL (Not saved)");
DuAEF.DuScriptUI.setTextColor(ui_compNamesText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
}
else if (!f.exists)
{
ui_saveText.setText("CRITICAL (Missing file)");
DuAEF.DuScriptUI.setTextColor(ui_compNamesText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
}
else
{
var date = f.modified.getTime();
var now = new Date().getTime();
var elapsed = now - date;
var elapsedStr = Math.round(elapsed/60000) + "mn";
if (elapsed < limit*0.75)
{
ui_saveText.setText("OK (" + elapsedStr + ")");
DuAEF.DuScriptUI.setTextColor(ui_saveText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
else if (elapsed < limit)
{
ui_saveText.setText("WARNING (" + elapsedStr + ")");
DuAEF.DuScriptUI.setTextColor(ui_saveText, DuAEF.DuJS.Color.Colors.YELLOW);
}
else if (elapsed < limit * 1.5)
{
ui_saveText.setText("BAD (" + elapsedStr + ")");
DuAEF.DuScriptUI.setTextColor(ui_saveText, DuAEF.DuJS.Color.Colors.ORANGE);
}
else
{
ui_saveText.setText("CRITICAL (" + elapsedStr + ")");
DuAEF.DuScriptUI.setTextColor(ui_saveText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
}
}
}

function checkCompNames()
{
var duplicatedNames = DuAEF.DuAE.Project.checkCompNames();
if (duplicatedNames.length == 0)
{
ui_compNamesText.setText("OK");
DuAEF.DuScriptUI.setTextColor(ui_compNamesText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
else
{
ui_compNamesText.setText("BAD");
DuAEF.DuScriptUI.setTextColor(ui_compNamesText, DuAEF.DuJS.Color.Colors.ORANGE);
}
}

function checkLayerNames()
{
var duplicatedNames = DuAEF.DuAE.Comp.checkLayerNames();
if (duplicatedNames.length == 0)
{
ui_layerNamesText.setText("OK");
DuAEF.DuScriptUI.setTextColor(ui_layerNamesText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
else
{
ui_layerNamesText.setText("BAD");
DuAEF.DuScriptUI.setTextColor(ui_layerNamesText, DuAEF.DuJS.Color.Colors.ORANGE);
}
}

function checkProjectSize()
{
var size = DuAEF.DuAE.Project.getSize();
var sizeLimit = 10000000;
if (size < 0)
{
ui_projectSizeText.setText("CRITICAL (not saved)");
DuAEF.DuScriptUI.setTextColor(ui_projectSizeText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
}
else if (size < sizeLimit*0.75)
{
ui_projectSizeText.setText("OK (" + DuAEF.DuJS.String.fromSize(size) + ")");
DuAEF.DuScriptUI.setTextColor(ui_projectSizeText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
else if (size < sizeLimit)
{
ui_projectSizeText.setText("WARNING (" + DuAEF.DuJS.String.fromSize(size) + ")");
DuAEF.DuScriptUI.setTextColor(ui_projectSizeText, DuAEF.DuJS.Color.Colors.YELLOW);
}
else if (size < sizeLimit * 1.5)
{
ui_projectSizeText.setText("BAD (" + DuAEF.DuJS.String.fromSize(size) + ")");
DuAEF.DuScriptUI.setTextColor(ui_projectSizeText, DuAEF.DuJS.Color.Colors.ORANGE);
}
else
{
ui_projectSizeText.setText("CRITICAL (" + DuAEF.DuJS.String.fromSize(size) + ")");
DuAEF.DuScriptUI.setTextColor(ui_projectSizeText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
}
}

function checkExpressionEngine()
function checkSanity()
{
var e = DuAEF.DuAE.Project.expressionEngine();
if (e.indexOf("javascript") == 0)
var level = DuAEF.DuSanity.currentLevel;
if (level == DuAEF.DuSanity.Levels.UNKNOWN)
{
ui_expressionText.setText("OK (JS)");
DuAEF.DuScriptUI.setTextColor(ui_expressionText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
ui_sanityButton.label.text = "Sanity level: unknown";
ui_sanityButton.setBackgroundColor(DuAEF.DuJS.Color.Colors.AE_DARK_GREY);
ui_sanityButton.setTextColor(DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
else
else if (level == DuAEF.DuSanity.Levels.OK)
{
ui_expressionText.setText("BAD (ES)");
DuAEF.DuScriptUI.setTextColor(ui_expressionText, DuAEF.DuJS.Color.Colors.ORANGE);
ui_sanityButton.label.text = "Sanity level: OK";
ui_sanityButton.setBackgroundColor(DuAEF.DuJS.Color.Colors.VERY_DARK_GREY);
ui_sanityButton.setTextColor(DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
}

function checkNumItems()
{
var n = app.project.numItems;
var limit = 100;
if (n < limit * 0.75)
else if (level == DuAEF.DuSanity.Levels.WARNING)
{
ui_numItemsText.setText("OK (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_numItemsText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
ui_sanityButton.label.text = "Sanity level: WARNING";
ui_sanityButton.setBackgroundColor(DuAEF.DuJS.Color.Colors.YELLOW);
ui_sanityButton.setTextColor(DuAEF.DuJS.Color.Colors.VERY_DARK_GREY);
}
else if (n < limit)
else if (level == DuAEF.DuSanity.Levels.BAD)
{
ui_numItemsText.setText("WARNING (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_numItemsText, DuAEF.DuJS.Color.Colors.YELLOW);
ui_sanityButton.label.text = "Sanity level: BAD";
ui_sanityButton.setBackgroundColor(DuAEF.DuJS.Color.Colors.ORANGE);
ui_sanityButton.setTextColor(DuAEF.DuJS.Color.Colors.BLACK);
}
else if (n < limit*1.5)
else if (level == DuAEF.DuSanity.Levels.CRITICAL)
{
ui_numItemsText.setText("BAD (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_numItemsText, DuAEF.DuJS.Color.Colors.ORANGE);
ui_sanityButton.label.text = "Sanity level: CRITICAL";
ui_sanityButton.setBackgroundColor(DuAEF.DuJS.Color.Colors.RAINBOX_RED);
ui_sanityButton.setTextColor(DuAEF.DuJS.Color.Colors.WHITE);
}
else
else if (level == DuAEF.DuSanity.Levels.FATAL)
{
ui_numItemsText.setText("CRITICAL (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_numItemsText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
ui_sanityButton.label.text = "Sanity level: FATAL";
ui_sanityButton.setBackgroundColor(DuAEF.DuJS.Color.Colors.LIGHT_PURPLE);
ui_sanityButton.setTextColor(DuAEF.DuJS.Color.Colors.WHITE);
}
}

function checkMemory()
{
var mem = app.memoryInUse;
var limit = 2147483648; //2GB
if (mem < limit * 0.75)
{
ui_memoryText.setText("OK (" + DuAEF.DuJS.String.fromSize(mem) + ")");
DuAEF.DuScriptUI.setTextColor(ui_memoryText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
else if (mem < limit)
{
ui_memoryText.setText("WARNING (" + DuAEF.DuJS.String.fromSize(mem) + ")");
DuAEF.DuScriptUI.setTextColor(ui_memoryText, DuAEF.DuJS.Color.Colors.YELLOW);
}
else if (mem < limit*1.5)
{
ui_memoryText.setText("BAD (" + DuAEF.DuJS.String.fromSize(mem) + ")");
DuAEF.DuScriptUI.setTextColor(ui_memoryText, DuAEF.DuJS.Color.Colors.ORANGE);
}
else
{
ui_memoryText.setText("CRITICAL (" + DuAEF.DuJS.String.fromSize(mem) + ")");
DuAEF.DuScriptUI.setTextColor(ui_memoryText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
}
//UI
var ui_sanityButton = DuAEF.DuScriptUI.addButton(ui.mainGroup, "Sanity level: unknown-------------------------------------");
ui_sanityButton.onClick = function () {
ui.mainGroup.visible = false;
ui.sanityGroup.visible = true;
}

function checkMP()
{
var n = DuAEF.DuAE.Comp.numMasterProperties();
var limit = 20;
if (n < limit * 0.75)
{
ui_MPText.setText("OK (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_MPText, DuAEF.DuJS.Color.Colors.LIGHT_GREY);
}
else if (n < limit)
{
ui_MPText.setText("WARNING (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_MPText, DuAEF.DuJS.Color.Colors.YELLOW);
}
else if (n < limit*1.5)
{
ui_MPText.setText("BAD (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_MPText, DuAEF.DuJS.Color.Colors.ORANGE);
}
else
{
ui_MPText.setText("CRITICAL (" + n + ")");
DuAEF.DuScriptUI.setTextColor(ui_MPText, DuAEF.DuJS.Color.Colors.RAINBOX_RED);
}
}

function refresh()
{
if ( ui_checkCompNamesButton.checked ) checkCompNames();
checkLayerNames();
checkProjectSize();
checkExpressionEngine();
checkNumItems();
checkMemory();
checkMP();
checkSave();
}

// UI Events

function ui_checkButton_clicked()
{
refresh();
}

//Settings
var ui_checkCompNamesButton = DuAEF.DuScriptUI.addCheckBox(ui.settingsGroup, "Check comp names", undefined, "Checks if some compositions in the project share the same name.");
//Main Panel
//Report
var ui_reportMainGroup = DuAEF.DuScriptUI.addGroup(ui.mainGroup, "row");
var ui_reportLeftGroup = DuAEF.DuScriptUI.addGroup(ui_reportMainGroup, "column");
var ui_reportRightGroup = DuAEF.DuScriptUI.addGroup(ui_reportMainGroup, "column");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Composition Names:");
var ui_compNamesText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "----------------------------");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Layer Names:");
var ui_layerNamesText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "----------------------------");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Expression Engine:");
var ui_expressionText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "----------------------------");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Project Size:");
var ui_projectSizeText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "----------------------------");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Project Items:");
var ui_numItemsText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "----------------------------");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Memory in use:");
var ui_memoryText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "----------------------------");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Master properties in active comp:");
var ui_MPText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "----------------------------");
DuAEF.DuScriptUI.addStaticText(ui_reportLeftGroup, "Time since last save:");
var ui_saveText = DuAEF.DuScriptUI.addStaticText(ui_reportRightGroup, "---------------------------------------------");

var ui_checkButton = DuAEF.DuScriptUI.addButton(ui.mainGroup, "Refresh!", undefined, "Runs the sanity tests.");

//Load settings/defaults
ui_checkCompNamesButton.setChecked(true);

ui_checkButton.onClick = ui_checkButton_clicked;
DuAEF.DuScriptUI.addEvent(checkSanity);

//First tests
refresh();
//add to events
DuAEF.DuScriptUI.addEvent(refresh);

#include 'dusan_required/dusan_footer.jsxinc'
1 change: 1 addition & 0 deletions src/dusan_required/dusan_footer.jsxinc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

DuAEF.DuScriptUI.showUI(ui);
DuAEF.enterRunTime();
checkSanity();
})(this);
2 changes: 1 addition & 1 deletion src/dusan_required/dusan_header.jsxinc
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
DuAEF.scriptIconOver = DuAEF.DuBinary.toFile(w18_rx_r);

// _______ UI SETUP _______
var ui = DuAEF.DuScriptUI.createMainPanel(thisObj, true);
var ui = DuAEF.DuScriptUI.createMainPanel(thisObj, true, false, false, true);

0 comments on commit 4135a82

Please sign in to comment.