kopia lustrzana https://github.com/backface/turtlestitch
1 wiersz
14 KiB
XML
1 wiersz
14 KiB
XML
<blocks app="Snap! 6.0 beta, https://snap.berkeley.edu" version="1"><block-definition s="create %'scope' var %'names'" type="command" category="variables"><comment x="0" y="0" w="146" collapsed="false">This block creates new variables on the selected scope: global (for all sprites), sprite (for this sprite only) or script (only for that blocks stack) with the names given (in 'names' list).

If there is already a variable with that name in that scope, it does nothing: no errors and no overwrites.</comment><header></header><code></code><translations>pt:cria as variáveis _ _
ca:crea les _ variables _
es:crear las _ variables _
de:erstellen _ var _
</translations><inputs><input type="%s" readonly="true">global<options>global
sprite
script</options></input><input type="%mult%txt"></input></inputs><script><block s="doIfElse"><block s="reportEquals"><block var="scope"/><l>script</l></block><script><block s="doForEach"><l>each item</l><block var="names"/><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l>if ((typeof varName) != "string" || varName === "") {
 throw new Error("name isn't a string: " + varName);
}
if (!proc.homeContext.variables.vars[varName]) proc.homeContext.variables.addVar(varName);</l></block><list><block var="each item"/></list></block></script></block></script><script><block s="doDeclareVariables"><list><l>global</l></list></block><block s="doIfElse"><block s="reportEquals"><block var="scope"/><l>sprite</l></block><script><block s="doSetVar"><l>global</l><block s="reportBoolean"><l><bool>false</bool></l></block></block></script><script><block s="doSetVar"><l>global</l><block s="reportBoolean"><l><bool>true</bool></l></block></block></script></block><block s="doForEach"><l>each item</l><block var="names"/><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>global</l><l>proc</l></list><l>if ((typeof varName) != "string" || varName === "") {
 throw new Error("name isn't a string: " + varName);
}
if (global && !proc.homeContext.variables.parentFrame.parentFrame.vars[varName]) this.addVariable(varName, true);
if (!global && !proc.homeContext.variables.parentFrame.vars[varName]) this.addVariable(varName, false);</l></block><list><block var="each item"/><block var="global"/></list></block></script></block><block s="doRun"><block s="reportJSFunction"><list></list><l>var ide = this.parentThatIsA(IDE_Morph);
ide.flushBlocksCache('variables'); // b/c of inheritance
ide.refreshPalette();</l></block><list></list></block></script></block></script></block-definition><block-definition s="delete var %'names'" type="command" category="variables"><comment x="0" y="0" w="217" collapsed="false">This block deletes all the variables with the names given (inside input list).

Each name will make only one variable deletion, and this will be the variable found following the scope order: 'script' -> 'sprite' -> 'global'.

If we have a "testing" sprite variable and also a "testing" global one, deleting "testing" will delete only the sprite one (Yes! we can also do "delete var (testing, testing)" to delete both.

If one variable does not exists (in any scope) an error happens, stopping block action in that point. You can check it before with the "does var (name) exists?"block. </comment><header></header><code></code><translations>pt:remove as variáveis _
ca:esborra les variables _
es:borrar variables _
de:löschen var _
</translations><inputs><input type="%mult%txt"></input></inputs><script><block s="doForEach"><l>each item</l><block var="names"/><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l>if ((typeof varName) != "string" || varName === "") {
 throw new Error("name isn't a string: " + varName);
}
if (typeof proc.homeContext.variables.vars[varName] !== 'undefined') {
 delete proc.homeContext.variables.vars[varName];
} else if (this.deletableVariableNames().indexOf(varName) != -1) {
 this.deleteVariable(varName);
} else {
 throw new Error("variable doesn't exist: " + varName);
}</l></block><list><block var="each item"/></list></block></script></block><block s="doRun"><block s="reportJSFunction"><list></list><l>var ide = this.parentThatIsA(IDE_Morph);
ide.flushBlocksCache('variables'); // b/c of inheritance
ide.refreshPalette();</l></block><list></list></block></script></block-definition><block-definition s="set var %'name' to %'value'" type="command" category="variables"><comment x="0" y="0" w="240.4931640625" collapsed="false">This block sets the given value (last input) to the variable named with the name givent (var input).

It looks for that variable following the scope order 'script' -> 'sprite' -> 'global' (the first match it finds).

If that variable does not exist (in any scope) an error happens, stopping their script. You can check it before using the "does var (name) exists?" block. </comment><header></header><code></code><translations>ca:assigna a _ el valor _
es:asignar a _ el valor _
pt:altera _ para _
de:setze var _ auf _
</translations><inputs><input type="%s"><options>§_getVarNamesDict</options></input><input type="%s"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>value</l><l>proc</l></list><l>if ((typeof varName) != "string") {
 throw new Error("name isn't a string: " + varName);
}
proc.homeContext.variables.setVar(varName, value);</l></block><list><block var="name"/><block var="value"/></list></block></script></block-definition><block-definition s="var %'name'" type="reporter" category="variables"><comment x="0" y="0" w="178.00000000000003" collapsed="false">This block reports the value of the variable with the name given.

It looks for that variable following the scope order 'script' -> 'sprite' -> 'global' (the first match it finds).

If that variable does not exist (in any scope) an error happens, stopping their script. You can check it before using the "does var (name) exists?" block. </comment><header></header><code></code><translations>pt:o valor de _
</translations><inputs><input type="%s"><options>§_getVarNamesDict</options></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l>if ((typeof varName) != "string") {
 throw new Error("name isn't a string: " + varName);
}
return proc.homeContext.variables.getVar(varName);</l></block><list><block var="name"/></list></block></block></script></block-definition><block-definition s="does var %'name' exist?" type="predicate" category="variables"><comment x="0" y="0" w="146" collapsed="false">This block reports "true" if there is a variable with this given name (input slot) in that context.

It can be a global, sprite or script variable.

Otherwise it reports "false".</comment><header></header><code></code><translations>pt:a variável _ existe
ca:existeix la variable _ ?
es:existe la variable _ ?
de:existiert var _ ?
</translations><inputs><input type="%s"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l>if ((typeof varName) != "string" || varName === "") {
 throw new Error("name isn't a string: " + varName);
}
return proc.homeContext.variables.silentFind(varName)? true:false;</l></block><list><block var="name"/></list></block></block></script></block-definition><block-definition s="show var %'name'" type="command" category="variables"><comment x="0" y="0" w="181" collapsed="false">This block turns on (show) the watcher view on stage (if it was not already activated) of the variable with the given name (slot input).

It can only access to the closest variable scope (if there different variables with the same name in different scopes) following the order 'script' -> 'sprite' -> 'global'.

No errors if that variable does not exist.</comment><header></header><code></code><translations>ca:mostra la variable _
es:mostrar variable _
pt:mostra a variável _
de:zeige var _
</translations><inputs><input type="%s"><options>§_getVarNamesDict</options></input></inputs><script><block s="doIf"><custom-block s="does var %s exist?"><block var="name"/></custom-block><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l> var varFrame = proc.homeContext.variables,
 stage,
 watcher,
 target,
 label,
 others,
 isGlobal,
 name = varName;

 if (name instanceof Context) {
 if (name.expression.selector === 'reportGetVar') {
 name = name.expression.blockSpec;
 } else {
 proc.doChangePrimitiveVisibility(name.expression, false);
 return;
 }
 }
 if (proc.homeContext.receiver) {
 stage = proc.homeContext.receiver.parentThatIsA(StageMorph);
 if (stage) {
 target = varFrame.silentFind(name);
 if (!target) {return; }
 // first try to find an existing (hidden) watcher
 watcher = detect(
 stage.children,
 morph => morph instanceof WatcherMorph &&
 morph.target === target &&
 morph.getter === name
 );
 if (watcher !== null) {
 watcher.show();
 watcher.fixLayout(); // re-hide hidden parts
 return;
 }
 // if no watcher exists, create a new one
 isGlobal = contains(
 proc.homeContext.receiver.globalVariables().names(),
 varName
 );
 if (isGlobal || target.owner) {
 label = name;
 } else {
 label = name + ' ' + localize('(temporary)');
 }
 watcher = new WatcherMorph(
 label,
 SpriteMorph.prototype.blockColor.variables,
 target,
 name
 );
 watcher.setPosition(stage.position().add(10));
 others = stage.watchers(watcher.left());
 if (others.length > 0) {
 watcher.setTop(others[others.length - 1].bottom());
 }
 stage.add(watcher);
 watcher.fixLayout();
 }
 }</l></block><list><block var="name"/></list></block></script></block></script></block-definition><block-definition s="hide var %'name'" type="command" category="variables"><comment x="0" y="0" w="181" collapsed="false">This block turns off (hide) the watcher view on stage (if it was not already activated) of the variable with the given name (slot input).

It can only access to the closest variable scope (if there different variables with the same name in different scopes) following the order 'script' -> 'sprite' -> 'global'.

No errors if that variable does not exist.</comment><header></header><code></code><translations>ca:amaga la variable _
es:esconder variable _
pt:esconde a variável _
de:verstecke var _
</translations><inputs><input type="%s"><options>§_getVarNamesDict</options></input></inputs><script><block s="doIf"><custom-block s="does var %s exist?"><block var="name"/></custom-block><script><block s="doRun"><block s="reportJSFunction"><list><l>varName</l><l>proc</l></list><l> // to delete all temporary watchers, use the primitive "hide" with no inputs
 var varFrame = proc.homeContext.variables,
 stage,
 watcher,
 target,
 name = varName;

 if (name instanceof Context) {
 if (name.expression.selector === 'reportGetVar') {
 name = name.expression.blockSpec;
 } else {
 proc.doChangePrimitiveVisibility(name.expression, true);
 return;
 }
 }
 if (!name) {
 proc.doRemoveTemporaries();
 return;
 }
 if (proc.homeContext.receiver) {
 stage = proc.homeContext.receiver.parentThatIsA(StageMorph);
 if (stage) {
 target = varFrame.find(name);
 watcher = detect(
 stage.children,
 morph => morph instanceof WatcherMorph &&
 morph.target === target &&
 morph.getter === name
 );
 if (watcher !== null) {
 if (watcher.isTemporary()) {
 watcher.destroy();
 } else {
 watcher.hide();
 }
 }
 }
 }
</l></block><list><block var="name"/></list></block></script></block></script></block-definition></blocks> |