Skip to content

Instantly share code, notes, and snippets.

@tgck
Created September 2, 2014 16:55
Show Gist options
  • Save tgck/5492c24b4fbe2cd2532f to your computer and use it in GitHub Desktop.
Save tgck/5492c24b4fbe2cd2532f to your computer and use it in GitHub Desktop.
query4Dict2.js // dictオブジェクトのカスタマイズ(desktopScanner向け)
var autowatch = 1;
var d = new Dict("finderItems");
var dd = new Dict("polyIndices");
function bang(){}
//
// Dump受信後, polyを一括してセットアップする関数
// 1. Polyへのメッセージを作成する
// 2. 別辞書(polyIndices)を作成する
// /dumpメッセージを受信した際に1度だけ呼ばれる想定.
// ネタとして, 構築済の辞書を使う(Dict("finderItems"))
// 引数: void
// 戻値: void
//
function setupPoly()
{
var targetList = new Array;
// var d = new Dict("finderItems");
var keys = d.getkeys();
// コマンドのさくせい
for (var idx in keys) {
var val = d.get(keys[idx]);
var command = keys[idx] + " " + val[0] + " " + val[1] + " " + "\n"
// --> "03ScaryMonstersAndSuperCreeps.aif 97 618"
targetList.push(command);
}
// polyへのメッセージ配布
dumpPoly(targetList);
// 別辞書作成
makeDictPolyIndices(targetList);
}
// ファイル名からPolyのインデックスを引く辞書(Dict("polyIndices"))に値をセットする。
// 呼びだしのタイミングは, 初回dump受信時に一括、一度きり。
// 引数: <List>"filename p.x p.y"
// 戻値: void
function makeDictPolyIndices( aList ){
// 辞書をアタッチ
// var dd = new Dict("polyIndices");
var index = 1;
for (var idx in aList) {
var fileinfo = aList[idx].split(" ");
var filename = fileinfo[0];
var record = filename + " " + index;
// output
// post ( ":::" + record + "\n");
dd.set(filename, index );
index++;
}
}
// DUMP route
// dumpPoly --- メッセージの頭にインデクスをつけて, outlet に送信する
// 引数: <List>"filename p.x p.y"
// 戻値: <iterized>"target index, filename p.x p.y"
//
function dumpPoly( aList ){
post("dumpPoly\n");
var index = 1;
for (var i in aList) {
var msgForPoly = "target XXX, ".replace("XXX", index)
+ aList[i];
outlet(0, msgForPoly);
index++;
}
}
//
// UPDATE route
// Dict("polyIndices")を用いて, /diff メッセージから poly~ に送るメッセージを作成する。
// 引数: "index filename p.x p.y"
// "2 03ScaryMonstersAndSuperCreeps.aif 97 362"
// 戻値: void
//
function update ( command ){
post("updatePoly\n");
var fileinfo = command.split(" ");
fileinfo.shift();
var filename = fileinfo[0];
// ファイル名から, polyインデックスを引く
// var dd = new Dict("polyIndices");
var ourIndex = dd.get(filename);
var msgForPoly = "target XXX, ".replace("XXX", ourIndex)
+ fileinfo.join(" ");
outlet(0, msgForPoly);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment