var tettool_logicController={init:function init(Label,$tetitem){console.log($tetitem.attr("itemtitle"));var mp=$("#mainPane");var rules=get_tettool_param($tetitem,"Rules")||$tetitem.data("rules")||"";var rulesTable=[];var rulesConditions_forDebuggingMsg=[];var deps=[];var r0,r0Code;var $tetparent=$tetitem.parent();if($tetparent.attr("id")!=="mainPane"){$tetparent=$tetparent.closest(".tetitem")}var logicContextAndScope={$tetparent:$tetparent,tetparent:$tetparent[0],pos_inside:function(a,b){return tet_pos_is_inside(b,a)},action:null,arg:null,$obj:null,obj:null};function fixupRuleCode(rule_idx_debugInfo,src,returnTheVal){function replacer(match,dynvarTFtitle,dynparam){var dt=$tet(dynvarTFtitle);var dep_id=dt.attr("id");if(dynparam!=="n"&&dynparam!=="x"&&dynparam!=="y"&&dynparam!=="w"&&dynparam!=="h"&&dynparam!=="abs_x"&&dynparam!=="abs_y"){deps.push(dep_id)}var dynvarval;switch(dynparam){case"text":dynvarval="$tet_text($('#"+dep_id+"')).text()";break;case"id":dynvarval=dep_id;break;case"i":dynvarval="(diashow['"+dep_id+"'].i+1)";break;case"n":dynvarval="(diashow['"+dep_id+"'].subs.length)";break;case"abs_x":dynvarval="tet_pos($('#"+dep_id+"')).left";break;case"abs_y":dynvarval="tet_pos($('#"+dep_id+"')).top";break;case"x":dynvarval="parseFloat($('#"+dep_id+"').css('left'))";break;case"y":dynvarval="parseFloat($('#"+dep_id+"').css('top'))";break;case"w":dynvarval="tet_width($('#"+dep_id+"'))";break;case"h":dynvarval="tet_height($('#"+dep_id+"'))";break;case"data":dynvarval='dynget("'+dynvarTFtitle+'.data")';break;default:var key=dep_id+"."+dynparam;dynvarval="dynvar_store['"+key+"']";if(!(key in dynvar_store)){dynvar_store[key]=0}break}return dynvarval}if(!src){return null}src=src.trim();if(!src){return null}src=src.replace(/{([\u00C0-\u017F\w]+)\.([\u00C0-\u017F\w]+)}/g,replacer);src=src.replace(/{([\u00C0-\u017F\w]+)}/g,'$tet("$1")');try{if(returnTheVal){src="with(logicContextAndScope){ return (\n"+src+"\n)}"}else{src="with(logicContextAndScope){\n"+src+"\n}"}return new Function(src)}catch(e){$(".errorMsg",$tetitem).html($(".errorMsg",$tetitem).html()+"<span>Rule "+rule_idx_debugInfo+": "+e+"</span>");return new Function()}}function setup_logiccontroller(){var match;var rulesNoComments=rules.replace(/^\s*\/\/.*/gm,"");rulesNoComments=rulesNoComments.replace(/\/\*[\s\S]*?\*\//g,"");var rx=new RegExp("^([\\s\\S]*?)(?:==>|-->|⇒|→)([\\s\\S]*?)$\n?(?!\\s)","gm");var rule_idx_debugInfo=1;$(".errorMsg",$tetitem).html("");while((match=rx.exec(rulesNoComments))!==null){var ruleLeft=fixupRuleCode(rule_idx_debugInfo+"-left",match[1],true);var rr=match[2].trim();if(!rr.length){$(".errorMsg",$tetitem).html($(".errorMsg",$tetitem).html()+"<span>Rule "+rule_idx_debugInfo+": Right Empty </span>");rule_idx_debugInfo++;continue}var rrLine="";rr.split("\n").forEach(function(l){var m=l.match(/^\s*(?:-->|==>|⇒|→)/);if(m){var ruleRight=fixupRuleCode(rule_idx_debugInfo+"-right",rrLine);rulesTable.push([ruleLeft,ruleRight]);rulesConditions_forDebuggingMsg.push(match[1]);rule_idx_debugInfo++;rrLine=l.substring(m[0].length)+"\n"}else{rrLine+=l+"\n"}});var ruleRight=fixupRuleCode(rule_idx_debugInfo+"-right",rrLine);rulesTable.push([ruleLeft,ruleRight]);rulesConditions_forDebuggingMsg.push(match[1]);rule_idx_debugInfo++}dynreg_fcn($tetitem,doLogic,deps);rulesConditions_forDebuggingMsg=rulesConditions_forDebuggingMsg.map(function(x){x=x.replace(/ *action *===?/g,"");return x})}function doLogic(){if(window.layouting_mode){return}if(doLogic.recursionProtection){return}doLogic.recursionProtection=true;logicContextAndScope.action=dynvar_action;logicContextAndScope.arg=dynvar_arg;logicContextAndScope.$obj=dynvar_$source;logicContextAndScope.obj=dynvar_$source&&dynvar_$source.attr("itemtitle");logicContextAndScope.objTitle=dynvar_$source&&dynvar_$source.attr("itemtitle");logicContextAndScope.objLabel=dynvar_$source&&dynvar_$source.attr("tetlabel");window.logicContextAndScope=logicContextAndScope;var lastLeftRuleEvaled=true;for(var ir=0;ir<rulesTable.length;ir++){var r=rulesTable[ir];try{if(r[0]?(lastLeftRuleEvaled=eval(r[0]())):lastLeftRuleEvaled){console.log("logicController-execRule "+(1+ir)+" "+rulesConditions_forDebuggingMsg[ir]);r[1]()}}catch(e){console.error(e);$(".errorMsg",$tetitem).html($(".errorMsg",$tetitem).html()+"<span>Rule "+(1+ir)+" "+rulesConditions_forDebuggingMsg[ir]+": "+e+"</span>")}}doLogic.recursionProtection=false}$tetitem.on("tet:beforedynvar",setup_logiccontroller)}};