scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
1,108 lines (720 loc) • 93.5 kB
HTML
<!DOCTYPE html>
<html>
<head>
<title>Grid factory</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="../../docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="../core/animationloop.html">
./source/core/animationloop.js
</a>
<a class="source" href="../core/document.html">
./source/core/document.js
</a>
<a class="source" href="../core/events.html">
./source/core/events.js
</a>
<a class="source" href="../core/init.html">
./source/core/init.js
</a>
<a class="source" href="../core/library.html">
./source/core/library.js
</a>
<a class="source" href="../core/random-seed.html">
./source/core/random-seed.js
</a>
<a class="source" href="../core/snippets.html">
./source/core/snippets.js
</a>
<a class="source" href="../core/userInteraction.html">
./source/core/userInteraction.js
</a>
<a class="source" href="../core/utilities.html">
./source/core/utilities.js
</a>
<a class="source" href="action.html">
./source/factory/action.js
</a>
<a class="source" href="anchor.html">
./source/factory/anchor.js
</a>
<a class="source" href="animation.html">
./source/factory/animation.js
</a>
<a class="source" href="bezier.html">
./source/factory/bezier.js
</a>
<a class="source" href="block.html">
./source/factory/block.js
</a>
<a class="source" href="canvas.html">
./source/factory/canvas.js
</a>
<a class="source" href="cell.html">
./source/factory/cell.js
</a>
<a class="source" href="cog.html">
./source/factory/cog.js
</a>
<a class="source" href="color.html">
./source/factory/color.js
</a>
<a class="source" href="conicGradient.html">
./source/factory/conicGradient.js
</a>
<a class="source" href="coordinate.html">
./source/factory/coordinate.js
</a>
<a class="source" href="crescent.html">
./source/factory/crescent.js
</a>
<a class="source" href="element.html">
./source/factory/element.js
</a>
<a class="source" href="emitter.html">
./source/factory/emitter.js
</a>
<a class="source" href="filter.html">
./source/factory/filter.js
</a>
<a class="source" href="filterEngine-bluenoiseData.html">
./source/factory/filterEngine-bluenoiseData.js
</a>
<a class="source" href="filterEngine.html">
./source/factory/filterEngine.js
</a>
<a class="source" href="fontAttributes.html">
./source/factory/fontAttributes.js
</a>
<a class="source" href="gradient.html">
./source/factory/gradient.js
</a>
<a class="source" href="grid.html">
./source/factory/grid.js
</a>
<a class="source" href="group.html">
./source/factory/group.js
</a>
<a class="source" href="imageAsset.html">
./source/factory/imageAsset.js
</a>
<a class="source" href="line.html">
./source/factory/line.js
</a>
<a class="source" href="lineSpiral.html">
./source/factory/lineSpiral.js
</a>
<a class="source" href="loom.html">
./source/factory/loom.js
</a>
<a class="source" href="mesh.html">
./source/factory/mesh.js
</a>
<a class="source" href="net.html">
./source/factory/net.js
</a>
<a class="source" href="noiseAsset.html">
./source/factory/noiseAsset.js
</a>
<a class="source" href="oval.html">
./source/factory/oval.js
</a>
<a class="source" href="palette.html">
./source/factory/palette.js
</a>
<a class="source" href="particle.html">
./source/factory/particle.js
</a>
<a class="source" href="particleForce.html">
./source/factory/particleForce.js
</a>
<a class="source" href="particleHistory.html">
./source/factory/particleHistory.js
</a>
<a class="source" href="particleSpring.html">
./source/factory/particleSpring.js
</a>
<a class="source" href="particleWorld.html">
./source/factory/particleWorld.js
</a>
<a class="source" href="pattern.html">
./source/factory/pattern.js
</a>
<a class="source" href="phrase.html">
./source/factory/phrase.js
</a>
<a class="source" href="picture.html">
./source/factory/picture.js
</a>
<a class="source" href="polygon.html">
./source/factory/polygon.js
</a>
<a class="source" href="polyline.html">
./source/factory/polyline.js
</a>
<a class="source" href="quadratic.html">
./source/factory/quadratic.js
</a>
<a class="source" href="quaternion.html">
./source/factory/quaternion.js
</a>
<a class="source" href="radialGradient.html">
./source/factory/radialGradient.js
</a>
<a class="source" href="rawAsset.html">
./source/factory/rawAsset.js
</a>
<a class="source" href="rdAsset.html">
./source/factory/rdAsset.js
</a>
<a class="source" href="rectangle.html">
./source/factory/rectangle.js
</a>
<a class="source" href="renderAnimation.html">
./source/factory/renderAnimation.js
</a>
<a class="source" href="shape.html">
./source/factory/shape.js
</a>
<a class="source" href="spiral.html">
./source/factory/spiral.js
</a>
<a class="source" href="spriteAsset.html">
./source/factory/spriteAsset.js
</a>
<a class="source" href="stack.html">
./source/factory/stack.js
</a>
<a class="source" href="star.html">
./source/factory/star.js
</a>
<a class="source" href="state.html">
./source/factory/state.js
</a>
<a class="source" href="tetragon.html">
./source/factory/tetragon.js
</a>
<a class="source" href="ticker.html">
./source/factory/ticker.js
</a>
<a class="source" href="tracer.html">
./source/factory/tracer.js
</a>
<a class="source" href="tween.html">
./source/factory/tween.js
</a>
<a class="source" href="unstackedElement.html">
./source/factory/unstackedElement.js
</a>
<a class="source" href="vector.html">
./source/factory/vector.js
</a>
<a class="source" href="videoAsset.html">
./source/factory/videoAsset.js
</a>
<a class="source" href="wheel.html">
./source/factory/wheel.js
</a>
<a class="source" href="../mixin/anchor.html">
./source/mixin/anchor.js
</a>
<a class="source" href="../mixin/asset.html">
./source/mixin/asset.js
</a>
<a class="source" href="../mixin/assetAdvancedFunctionality.html">
./source/mixin/assetAdvancedFunctionality.js
</a>
<a class="source" href="../mixin/assetConsumer.html">
./source/mixin/assetConsumer.js
</a>
<a class="source" href="../mixin/base.html">
./source/mixin/base.js
</a>
<a class="source" href="../mixin/cascade.html">
./source/mixin/cascade.js
</a>
<a class="source" href="../mixin/delta.html">
./source/mixin/delta.js
</a>
<a class="source" href="../mixin/displayShape.html">
./source/mixin/displayShape.js
</a>
<a class="source" href="../mixin/dom.html">
./source/mixin/dom.js
</a>
<a class="source" href="../mixin/entity.html">
./source/mixin/entity.js
</a>
<a class="source" href="../mixin/filter.html">
./source/mixin/filter.js
</a>
<a class="source" href="../mixin/mimic.html">
./source/mixin/mimic.js
</a>
<a class="source" href="../mixin/path.html">
./source/mixin/path.js
</a>
<a class="source" href="../mixin/pattern.html">
./source/mixin/pattern.js
</a>
<a class="source" href="../mixin/pivot.html">
./source/mixin/pivot.js
</a>
<a class="source" href="../mixin/position.html">
./source/mixin/position.js
</a>
<a class="source" href="../mixin/shapeBasic.html">
./source/mixin/shapeBasic.js
</a>
<a class="source" href="../mixin/shapeCurve.html">
./source/mixin/shapeCurve.js
</a>
<a class="source" href="../mixin/shapePathCalculation.html">
./source/mixin/shapePathCalculation.js
</a>
<a class="source" href="../mixin/styles.html">
./source/mixin/styles.js
</a>
<a class="source" href="../mixin/tween.html">
./source/mixin/tween.js
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="section-1">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-1">§</a>
</div>
<h1 id="grid-factory">Grid factory</h1>
<p>The Grid entity is a graphical representation of <strong>a grid with equal width columns and equal height rows</strong>, separated by gutters. Each tile within the grid can be filled with a different color, or a different gradient, or a different Picture entity output.</p>
<ul>
<li>Each grid requires a mimimum of one column and one row; columns will divide into the Grid width evenly, rows divide evenly into the Grid height.</li>
<li>The <strong>tiles</strong> can display as many different colors, or gradients, or Pictures, as are required for the display.</li>
<li>The <strong>gutters</strong> between columns, and between rows, can be different values; gutter fills can also be colors, gradients or Picture entity output.</li>
<li>The display for each tile, and the gutters, can be easily updated.</li>
<li>Grid entity <strong>hit reports</strong> include an extra attribute - an array of tiles that report being hit.</li>
<li>Grids will accept <strong>Filter</strong> objects - filters are applied to the entire Grid, not to individual tiles.</li>
<li>They can use <strong>Anchor</strong> objects for user navigation. </li>
<li>They can be rendered to the canvas by including them in a <strong>Cell</strong> object’s <strong>Group</strong>. </li>
<li>They can be <strong>animated</strong> directly, or using delta animation, or act as the target for <strong>Tween</strong> animations.</li>
<li>Grids can be cloned, and killed.</li>
</ul>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-2">§</a>
</div>
<h4 id="demos">Demos:</h4>
<ul>
<li><a href="../../demo/canvas-022.html">Canvas-022</a> - Grid entity - basic functionality (color, gradients)</li>
<li><a href="../../demo/canvas-023.html">Canvas-023</a> - Grid entity - using picture-based assets (image, video, sprite)</li>
<li><a href="../../demo/packets-002.html">Packets-002</a> - Scrawl-canvas packets - save and load a range of different entitys</li>
</ul>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-3">§</a>
</div>
<h4 id="imports">Imports</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors, entity } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/library.js'</span>;
<span class="hljs-keyword">import</span> { mergeOver, pushUnique, isa_number, isa_obj, λ<span class="hljs-literal">null</span>, xt, xta, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/utilities.js'</span>;
<span class="hljs-keyword">import</span> { requestCell, releaseCell } <span class="hljs-keyword">from</span> <span class="hljs-string">'./cell.js'</span>;
<span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">'../mixin/base.js'</span>;
<span class="hljs-keyword">import</span> entityMix <span class="hljs-keyword">from</span> <span class="hljs-string">'../mixin/entity.js'</span>;</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-4">§</a>
</div>
<h4 id="grid-constructor">Grid constructor</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">Grid</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span> = [];
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileSources</span> = [];
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">entityInit</span>(items);
<span class="hljs-keyword">if</span> (!items.<span class="hljs-property">tileSources</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileSources</span> = [].<span class="hljs-title function_">concat</span>([{
<span class="hljs-attr">type</span>: <span class="hljs-string">'color'</span>,
<span class="hljs-attr">source</span>: <span class="hljs-string">'#000000'</span>,
},
{
<span class="hljs-attr">type</span>: <span class="hljs-string">'color'</span>,
<span class="hljs-attr">source</span>: <span class="hljs-string">'#ffffff'</span>,
}]);
}
<span class="hljs-keyword">if</span> (!items.<span class="hljs-property">tileFill</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>.<span class="hljs-property">length</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">columns</span> * <span class="hljs-variable language_">this</span>.<span class="hljs-property">rows</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>.<span class="hljs-title function_">fill</span>(<span class="hljs-number">0</span>);
}
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(items.<span class="hljs-property">tileFill</span>) && <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>.<span class="hljs-property">length</span> === items.<span class="hljs-property">tileFill</span>.<span class="hljs-property">length</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span> = items.<span class="hljs-property">tileFill</span>;
}
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tilePaths</span> = [];
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileRealCoordinates</span> = [];
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileVirtualCoordinates</span> = [];
<span class="hljs-keyword">if</span> (!items.<span class="hljs-property">dimensions</span>) {
<span class="hljs-keyword">if</span> (!items.<span class="hljs-property">width</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentDimensions</span>[<span class="hljs-number">0</span>] = <span class="hljs-variable language_">this</span>.<span class="hljs-property">dimensions</span>[<span class="hljs-number">0</span>] = <span class="hljs-number">20</span>;
<span class="hljs-keyword">if</span> (!items.<span class="hljs-property">height</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentDimensions</span>[<span class="hljs-number">1</span>] = <span class="hljs-variable language_">this</span>.<span class="hljs-property">dimensions</span>[<span class="hljs-number">1</span>] = <span class="hljs-number">20</span>;
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-5">§</a>
</div>
<h4 id="block-prototype">Block prototype</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">Grid</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span> = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>);
P.<span class="hljs-property">type</span> = <span class="hljs-string">'Grid'</span>;
P.<span class="hljs-property">lib</span> = <span class="hljs-string">'entity'</span>;
P.<span class="hljs-property">isArtefact</span> = <span class="hljs-literal">true</span>;
P.<span class="hljs-property">isAsset</span> = <span class="hljs-literal">false</span>;</pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-6">§</a>
</div>
<h4 id="mixins">Mixins</h4>
<ul>
<li><a href="../mixin/base.html">base</a></li>
<li><a href="../mixin/entity.html">entity</a></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P);
P = <span class="hljs-title function_">entityMix</span>(P);</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-7">§</a>
</div>
<h4 id="grid-attributes">Grid attributes</h4>
<ul>
<li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</strong>.</li>
<li>Attributes defined in the <a href="../mixin/position.html">position mixin</a>: <strong>group, visibility, order, calculateOrder, stampOrder, start, <em>startX</em>, <em>startY</em>, handle, <em>handleX</em>, <em>handleY</em>, offset, <em>offsetX</em>, <em>offsetY</em>, dimensions, <em>width</em>, <em>height</em>, pivoted, mimicked, lockTo, <em>lockXTo</em>, <em>lockYTo</em>, scale, roll, noUserInteraction, noPositionDependencies, noCanvasEngineUpdates, noFilters, noPathUpdates, purge, bringToFrontOnDrag</strong>.</li>
<li>Attributes defined in the <a href="../mixin/delta.html">delta mixin</a>: <strong>delta, noDeltaUpdates</strong>.</li>
<li>Attributes defined in the <a href="../mixin/pivot.html">pivot mixin</a>: <strong>pivot, pivotCorner, addPivotHandle, addPivotOffset, addPivotRotation</strong>.</li>
<li>Attributes defined in the <a href="../mixin/mimic.html">mimic mixin</a>: <strong>mimic, useMimicDimensions, useMimicScale, useMimicStart, useMimicHandle, useMimicOffset, useMimicRotation, useMimicFlip, addOwnDimensionsToMimic, addOwnScaleToMimic, addOwnStartToMimic, addOwnHandleToMimic, addOwnOffsetToMimic, addOwnRotationToMimic</strong>.</li>
<li>Attributes defined in the <a href="../mixin/path.html">path mixin</a>: <strong>path, pathPosition, addPathHandle, addPathOffset, addPathRotation, constantPathSpeed</strong>.</li>
<li>Attributes defined in the <a href="../mixin/entity.html">entity mixin</a>: <strong>method, pathObject, winding, flipReverse, flipUpend, scaleOutline, lockFillStyleToEntity, lockStrokeStyleToEntity, onEnter, onLeave, onDown, onUp, <em>fillStyle, strokeStyle, globalAlpha, globalCompositeOperation, lineWidth, lineCap, lineJoin, lineDash, lineDashOffset, miterLimit, shadowOffsetX, shadowOffsetY, shadowBlur, shadowColor, filter</em></strong>.</li>
<li>Attributes defined in the <a href="../mixin/anchor.html">anchor mixin</a>: <strong>anchor</strong>.</li>
<li>Attributes defined in the <a href="../mixin/filter.html">filter mixin</a>: <strong>filters, isStencil</strong>.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> defaultAttributes = {</pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-8">§</a>
</div>
<p><strong>columns</strong>, <strong>rows</strong> - integer Numbers representing the number of columns and rows in the Grid</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">columns</span>: <span class="hljs-number">2</span>,
<span class="hljs-attr">rows</span>: <span class="hljs-number">2</span>,</pre></div></div>
</li>
<li id="section-9">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-9">§</a>
</div>
<p><strong>columnGutterWidth</strong>, <strong>rowGutterWidth</strong> - float Number distances (measured in px) between tiles in the grid.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">columnGutterWidth</span>: <span class="hljs-number">1</span>,
<span class="hljs-attr">rowGutterWidth</span>: <span class="hljs-number">1</span>,</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-10">§</a>
</div>
<p><strong>tileSources</strong> - Array of Javascript Objects</p>
<ul>
<li>Each Object describes a source which can be used to fill tiles</li>
<li>Available fills include: <code>color</code>, <code>cellGradient</code>, <code>gridGradient</code>, <code>gridPicture</code>, <code>tilePicture</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">tileSources</span>: <span class="hljs-literal">null</span>,</pre></div></div>
</li>
<li id="section-11">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-11">§</a>
</div>
<p><strong>tileFill</strong> - Array of integer Numbers</p>
<ul>
<li>Length of the Array will be <code>rows * columns</code></li>
<li>Tiles are arranged left-to-right, top-to-bottom with tileFill[0] being the top left tile in the grid</li>
<li>Each Number represents the index of the tileSource object to be used to fill this tile</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">tileFill</span>: <span class="hljs-literal">null</span>,</pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-12">§</a>
</div>
<p><strong>gutterColor</strong> - can accept the following sources:</p>
<ul>
<li>A valid CSS color String</li>
<li>The name-String of a Scrawl-canvas Gradient or RadialGradient object, or the object itself</li>
<li>An integer Number representing the index of a tileSource object</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">gutterColor</span>: <span class="hljs-string">'#808080'</span>,
};
P.<span class="hljs-property">defs</span> = <span class="hljs-title function_">mergeOver</span>(P.<span class="hljs-property">defs</span>, defaultAttributes);</pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-13">§</a>
</div>
<h4 id="packet-management">Packet management</h4>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">packetExclusions</span> = <span class="hljs-title function_">pushUnique</span>(P.<span class="hljs-property">packetExclusions</span>, [<span class="hljs-string">'tileSources'</span>]);
P.<span class="hljs-property">finalizePacketOut</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">copy, items</span>) {
<span class="hljs-keyword">let</span> cSources = copy.<span class="hljs-property">tileSources</span> = [],
tSources = <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileSources</span>;
tSources.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">item</span> =></span> {
cSources.<span class="hljs-title function_">push</span>({
<span class="hljs-attr">type</span>: item.<span class="hljs-property">type</span>,
<span class="hljs-attr">source</span>: (<span class="hljs-title function_">isa_obj</span>(item.<span class="hljs-property">source</span>)) ? item.<span class="hljs-property">source</span>.<span class="hljs-property">name</span> : item.<span class="hljs-property">source</span>
});
});
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(copy.<span class="hljs-property">gutterColor</span>)) copy.<span class="hljs-property">gutterColor</span> = copy.<span class="hljs-property">gutterColor</span>.<span class="hljs-property">name</span>;
<span class="hljs-keyword">let</span> stateCopy = <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">parse</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">state</span>.<span class="hljs-title function_">saveAsPacket</span>(items))[<span class="hljs-number">3</span>];
copy = <span class="hljs-title function_">mergeOver</span>(copy, stateCopy);
copy = <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">handlePacketAnchor</span>(copy, items);
<span class="hljs-keyword">return</span> copy;
};</pre></div></div>
</li>
<li id="section-14">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-14">§</a>
</div>
<h4 id="clone-management">Clone management</h4>
<p>No additional clone functionality required</p>
</div>
</li>
<li id="section-15">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-15">§</a>
</div>
<h4 id="kill-management">Kill management</h4>
<p>No additional kill functionality required</p>
</div>
</li>
<li id="section-16">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-16">§</a>
</div>
<h4 id="get-set-deltaset">Get, Set, deltaSet</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> G = P.<span class="hljs-property">getters</span>,
S = P.<span class="hljs-property">setters</span>,
D = P.<span class="hljs-property">deltaSetters</span>;</pre></div></div>
</li>
<li id="section-17">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-17">§</a>
</div>
<p><strong>columns</strong></p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">columns</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(item)) {
<span class="hljs-keyword">if</span> (!<span class="hljs-title class_">Number</span>.<span class="hljs-title function_">isInteger</span>(item)) item = <span class="hljs-built_in">parseInt</span>(item, <span class="hljs-number">10</span>);
<span class="hljs-keyword">if</span> (item !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">columns</span>) {
<span class="hljs-keyword">let</span> i, iz, j,
currentFill = <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>,
currentCols = <span class="hljs-variable language_">this</span>.<span class="hljs-property">columns</span>,
newFill = [];
<span class="hljs-variable language_">this</span>.<span class="hljs-property">columns</span> = item;
<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>, iz = <span class="hljs-variable language_">this</span>.<span class="hljs-property">rows</span>; i < iz; i++) {
<span class="hljs-keyword">for</span> (j = <span class="hljs-number">0</span>; j < item; j++) {
<span class="hljs-keyword">if</span> (j < currentCols) newFill.<span class="hljs-title function_">push</span>(currentFill[(i * currentCols) + j]);
<span class="hljs-keyword">else</span> newFill.<span class="hljs-title function_">push</span>(<span class="hljs-number">0</span>);
}
}
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span> = newFill;
}
}
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPathObject</span> = <span class="hljs-literal">true</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">columns</span> = λ<span class="hljs-literal">null</span>;</pre></div></div>
</li>
<li id="section-18">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-18">§</a>
</div>
<p><strong>rows</strong></p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">rows</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(item)) {
<span class="hljs-keyword">if</span> (!<span class="hljs-title class_">Number</span>.<span class="hljs-title function_">isInteger</span>(item)) item = <span class="hljs-built_in">parseInt</span>(item, <span class="hljs-number">10</span>);
<span class="hljs-keyword">if</span> (item !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">rows</span>) {
<span class="hljs-keyword">let</span> currentRows = <span class="hljs-variable language_">this</span>.<span class="hljs-property">rows</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">rows</span> = item;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>.<span class="hljs-property">length</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">columns</span> * item;
<span class="hljs-keyword">if</span> (currentRows < item) <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>.<span class="hljs-title function_">fill</span>(<span class="hljs-number">0</span>, currentRows * <span class="hljs-variable language_">this</span>.<span class="hljs-property">columns</span>);
}
}
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPathObject</span> = <span class="hljs-literal">true</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>;
};
D.<span class="hljs-property">rows</span> = λ<span class="hljs-literal">null</span>;</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-19">§</a>
</div>
<h4 id="tile-management">Tile management</h4>
</div>
</li>
<li id="section-20">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-20">§</a>
</div>
<p><code>setAllTilesTo</code> - change the fill for all tiles in a Grid </p>
<ul>
<li>Argument is an integer Number representing the index of a tileSource object</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">setAllTilesTo</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(val)) {
<span class="hljs-keyword">if</span> (!<span class="hljs-title class_">Number</span>.<span class="hljs-title function_">isInteger</span>(val)) val = <span class="hljs-built_in">parseInt</span>(val, <span class="hljs-number">10</span>);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>.<span class="hljs-title function_">fill</span>(val);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>;
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-21">§</a>
</div>
<p><code>setTileFill</code> - update the tileFill array</p>
<ul>
<li>The array supplied as an argument must be the same length as current rows * columns</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">setTileFill</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">const</span> { columns, rows } = <span class="hljs-variable language_">this</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(item) && item.<span class="hljs-property">length</span> === columns * rows) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span> = item;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>;
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-22">§</a>
</div>
<p><code>setTilesTo</code> - change the fill for a (set of) tile(s) in a Grid - requires two arguments:</p>
<ul>
<li>First argument is an integer Number representing the position of a tile in the tileFill Array, or an Array of such Numbers</li>
<li>Second argument is an integer Number representing the index of a tileSource object</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">setTilesTo</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">tiles, val</span>) {
<span class="hljs-keyword">let</span> tileFill = <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(tiles) && <span class="hljs-title function_">isa_number</span>(val)) {
<span class="hljs-keyword">if</span> (!<span class="hljs-title class_">Number</span>.<span class="hljs-title function_">isInteger</span>(val)) val = <span class="hljs-built_in">parseInt</span>(val, <span class="hljs-number">10</span>);
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(tiles)) tileFill[tiles] = val;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(tiles)) {
tiles.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">tile</span> =></span> {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(tile)) tileFill[tile] = val;
});
}
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>;
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-23">§</a>
</div>
<p><code>setTileSourceTo</code> - update or replace a tileSource object - requires two arguments:</p>
<ul>
<li>First argument is the integer Number index of the tileSource object to be replaced</li>
<li>Second argument is the new or updated object</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">setTileSourceTo</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">index, obj</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(index) && <span class="hljs-title function_">isa_obj</span>(obj)) {
<span class="hljs-keyword">if</span> (obj.<span class="hljs-property">type</span> && obj.<span class="hljs-property">source</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileSources</span>[index] = obj;
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-24">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-24">§</a>
</div>
<p><code>removeTileSource</code> - remove a tileSource object</p>
<ul>
<li>Argument is an integer Number representing the index of a tileSource object</li>
<li>Object will be replaced with <code>null</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">removeTileSource</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">index</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(index) && index) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileSources</span>[index] = <span class="hljs-literal">null</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>.<span class="hljs-title function_">map</span>(<span class="hljs-function"><span class="hljs-params">item</span> =></span> item === index ? <span class="hljs-number">0</span> : item);
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-25">§</a>
</div>
<p><code>getTileSource</code> - returns the tileSource index Number for the given tile. Function is overloaded:</p>
<ul>
<li>One argument: Number representing the position of a tile in the tileFill Array.</li>
<li>Two arguments: The <code>(row, column)</code> position of the tile in the Grid - both values start from <code>0</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">getTileSource</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">row, col</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_number</span>(row)) {
<span class="hljs-keyword">if</span> (!<span class="hljs-title function_">isa_number</span>(col)) <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">tileFill</span>[row];
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</sp