1
0
Fork 0

Moved debug formatting to debug plugin

This commit is contained in:
Joost De Cock 2018-09-23 13:05:45 +02:00
parent 7f7688c566
commit 74ef91fe08
3 changed files with 10 additions and 36 deletions

View file

@ -39,7 +39,7 @@ Part.prototype.macroClosure = function(args) {
self[macro](args); self[macro](args);
} else { } else {
self.debug( self.debug(
utils.debugStyle("warning", "🔎 Macro not found"), { style: "warning", label: "🔍 Macro not found" },
`Macro ${macro.substr(7)} is not registered` `Macro ${macro.substr(7)} is not registered`
); );
} }

View file

@ -1,4 +1,4 @@
import { macroName, debugStyle, round, sampleStyle } from "./utils"; import { macroName, round, sampleStyle } from "./utils";
import Part from "./part"; import Part from "./part";
import Point from "./point"; import Point from "./point";
import Path from "./path"; import Path from "./path";
@ -156,7 +156,6 @@ Pattern.prototype.sampleOption = function(optionName) {
let parts = this.sampleParts(); let parts = this.sampleParts();
let option = this.config.options[optionName]; let option = this.config.options[optionName];
if (typeof option.list === "object") { if (typeof option.list === "object") {
console.log("sampling list");
return this.sampleListOption(optionName); return this.sampleListOption(optionName);
} }
if (typeof option.min === "undefined" || typeof option.max === "undefined") { if (typeof option.min === "undefined" || typeof option.max === "undefined") {
@ -170,7 +169,7 @@ Pattern.prototype.sampleOption = function(optionName) {
for (let run = 1; run < 11; run++) { for (let run = 1; run < 11; run++) {
this.options[optionName] = val; this.options[optionName] = val;
this.debug( this.debug(
debugStyle("info", "🔬 Sample run"), { style: "info", label: "🔬 Sample run" },
`Sampling option ${optionName} with value ${round(val)}` `Sampling option ${optionName} with value ${round(val)}`
); );
this.sampleRun(parts, anchors, run, 10); this.sampleRun(parts, anchors, run, 10);
@ -190,7 +189,7 @@ Pattern.prototype.sampleListOption = function(optionName) {
for (let val of option.list) { for (let val of option.list) {
this.options[optionName] = val; this.options[optionName] = val;
this.debug( this.debug(
debugStyle("info", "🔬 Sample run"), { style: "info", label: "🔬 Sample run" },
`Sampling option ${optionName} with value ${round(val)}` `Sampling option ${optionName} with value ${round(val)}`
); );
this.sampleRun(parts, anchors, run, runs); this.sampleRun(parts, anchors, run, runs);
@ -214,7 +213,7 @@ Pattern.prototype.sampleMeasurement = function(measurementName) {
for (let run = 1; run < 11; run++) { for (let run = 1; run < 11; run++) {
this.settings.measurements[measurementName] = val; this.settings.measurements[measurementName] = val;
this.debug( this.debug(
debugStyle("info", "🔬 Sample run"), { style: "info", label: "🔬 Sample run" },
`Sampling measurement ${measurementName} with value ${round(val)}` `Sampling measurement ${measurementName} with value ${round(val)}`
); );
this.sampleRun(parts, anchors, run, 10); this.sampleRun(parts, anchors, run, 10);
@ -236,7 +235,10 @@ Pattern.prototype.sampleModels = function(models, focus = false) {
for (let l in models) { for (let l in models) {
run++; run++;
this.settings.measurements = models[l]; this.settings.measurements = models[l];
this.debug(debugStyle("info", "🔬 Sample run"), `Sampling model ${l}`); this.debug(
{ style: "info", label: "🔬 Sample run" },
`Sampling model ${l}`
);
let className = l === focus ? "sample-focus" : ""; let className = l === focus ? "sample-focus" : "";
this.sampleRun(parts, anchors, run, runs, className); this.sampleRun(parts, anchors, run, runs, className);
} }
@ -276,7 +278,7 @@ Pattern.prototype.on = function(hook, method) {
Pattern.prototype.with = function(plugin) { Pattern.prototype.with = function(plugin) {
this.debug( this.debug(
debugStyle("success", "🔌 Plugin loaded"), { style: "success", label: "🔌 Plugin loaded" },
`${plugin.name} v${plugin.version}` `${plugin.name} v${plugin.version}`
); );
if (plugin.hooks) this.loadPluginHooks(plugin); if (plugin.hooks) this.loadPluginHooks(plugin);

View file

@ -2,34 +2,6 @@ import Point from "./point";
import Attributes from "./attributes"; import Attributes from "./attributes";
import Bezier from "bezier-js"; import Bezier from "bezier-js";
/* Returns an object to style debug output */
export function debugStyle(type, text) {
const color = {
info: "#FFF",
warning: "#FFF",
error: "#FFF",
success: "#FFF"
};
const background = {
info: "#29ABE0",
warning: "#F47C3C",
error: "#d9534f",
success: "#4caf50"
};
let style = new Attributes();
style.set("color", color[type]);
style.set("background", background[type]);
style.set("font-weight", "bold;");
style.set("padding", "5px");
style.set("border-radius", "10px");
return {
debug: "custom",
text,
style: style.renderAsCss()
};
}
/** Returns internal hook name for a macro */ /** Returns internal hook name for a macro */
export function macroName(name) { export function macroName(name) {
return `_macro_${name}`; return `_macro_${name}`;