Context モジュール
以下のメソッドは JavaScript Utility、JavaScript Shape、JavaScript Deformer、JavaScript Emitter、JavaScript Modifier でのみ利用可能です。このモジュールのすべては ctx 名前空間にあるため、メソッドには ctx. プレフィックスが必要です。例:var index = ctx.index;
メンバー関数
「メンバー関数」という見出しのセクションindex → int
「index → int」という見出しのセクション現在のポイントインデックス。Duplicator(または Connect Shape や Trails などのインデックスを生成するレイヤー)を使用している場合に利用可能。
count → int
「count → int」という見出しのセクションポイントの総数。Duplicator(または Connect Shape や Trails などのインデックスを生成するレイヤー)を使用している場合に利用可能。
positionX → number
「positionX → number」という見出しのセクション現在のポイントの X 位置。Duplicator(または Connect Shape や Trails などのインデックスを生成するレイヤー)を使用している場合に利用可能。
positionY → number
「positionY → number」という見出しのセクション現在のポイントの Y 位置。Duplicator(または Connect Shape や Trails などのインデックスを生成するレイヤー)を使用している場合に利用可能。
attributeId → string
「attributeId → string」という見出しのセクション計算中の Attribute の ID。
layerId → string
「layerId → string」という見出しのセクション計算中のレイヤーの ID。
saveObject(name:string, objectLiteralToSave:object)
「saveObject(name:string, objectLiteralToSave:object)」という見出しのセクション後で使用するためのオブジェクトを保存します。この機能の一般的なユースケースはソルバーの作成です — 例えば、以前の値を知る必要があるスクリプトです。
保存する値はオブジェクトである必要があります。
後で使用するパスを保存する場合は、保存/読み込み時に path.toObject()/ path.fromObject(obj) メソッドを使用してください。
// Simple examplectx.saveObject("test", {"someKey": 10});// A path example// Create a pathvar path = new cavalry.Path();path.moveTo(0.,0.);path.lineTo(0.,-100.);path.lineTo(300.,-100.);// Save itctx.saveObject("path", path.toObject());// Safety check that there is a saved valueif (ctx.hasObject("path")) { // Load the object let previous = ctx.loadObject("path"); // set the path from the object path.fromObject(previous);}loadObject(name:string) → object
「loadObject(name:string) → object」という見出しのセクション保存されたオブジェクトを読み込みます。
ctx.saveObject("test", {"someKey": 10});var textObj = ctx.loadObject("test");console.log(textObj["someKey"])hasObject(name:string) → bool
「hasObject(name:string) → bool」という見出しのセクションname という名前のオブジェクトが保存されており、読み込み可能な場合に true を返します。
ctx.saveObject("test", {"someKey": 10});if (ctx.hasObject("test")) { /// do something}niceName() → string
「niceName() → string」という見出しのセクションJavaScript Utility に値を要求したレイヤーの表示名を取得します。
console.log(ctx.niceName);transformationMatrix() → matrix
「transformationMatrix() → matrix」という見出しのセクション上流のローカル 2D 変換行列を返します。存在しない場合は null。
/*1. Create a Shape.2. On the Shape's Deformers attribute, click the + button and choose JavaScript Deformer.3. Copy the below in the JavaScript Deformer's Expression.*/var tm = ctx.transformationMatrix();console.log(tm.position().x);globalTransformationMatrix() → matrix
「globalTransformationMatrix() → matrix」という見出しのセクション上流のグローバル 2D 変換行列を返します。存在しない場合は null。
/*1. Create a Shape.2. On the Shape's Deformers attribute, click the + button and choose JavaScript Deformer.3. Copy the below into the JavaScript Deformer's Expression.4. Group the Shape.*/var tm = ctx.globalTransformationMatrix();console.log(tm.position().x);