-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathEncode.js
More file actions
174 lines (154 loc) · 4.89 KB
/
Copy pathEncode.js
File metadata and controls
174 lines (154 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Encode.js v3.4.1
import { classmgr } from '../pzpr/classmgr.js';
import Parser from '../pzpr/parser.js';
//---------------------------------------------------------------------------
// ★Encodeクラス URLのエンコード/デコードを扱う
//---------------------------------------------------------------------------
// URLエンコード/デコード
// Encodeクラス
classmgr.makeCommon({
//---------------------------------------------------------
Encode: {
pflag: "",
outpflag: "",
outvariant: null,
outcols: null,
outrows: null,
outbstr: "",
fio: null,
//---------------------------------------------------------------------------
// enc.checkpflag() pflagに指定した文字列が含まれているか調べる
//---------------------------------------------------------------------------
// ぱずぷれApplet->v3でURLの仕様が変わったパズル:
// creek, gokigen, lits (Applet+c===v3, Applet===v3+d)
// 何回かURL形式を変更したパズル:
// icebarn (v3, Applet+c, Applet), slalom (v3+p, v3+d, v3/Applet)
// v3になって以降pidを分離したパズルのうち元パズルのURL形式を変更して短くしたパズル:
// bonsan, kramma (cを付加)
// URL形式は同じで表示形式の情報をもたせているパズル:
// bosanowa, pipelink, yajilin
checkpflag: function(ca) {
return this.pflag.indexOf(ca) >= 0;
},
//---------------------------------------------------------------------------
// enc.decodeURL() parseURL()を行い、各種各パズルのdecode関数を呼び出す
// enc.encodeURL() 各種各パズルのencode関数を呼び出し、URLを出力する
//
// enc.decodePzpr() 各パズルのURL入力用(オーバーライド用)
// enc.encodePzpr() 各パズルのURL出力用(オーバーライド用)
//---------------------------------------------------------------------------
decodeURL: function(url) {
var pzl = Parser.parseURL(url),
puzzle = this.puzzle,
bd = puzzle.board;
if (pzl.type === pzl.URL_PZPRFILE) {
new puzzle.klass.FileIO().filedecode(pzl.body);
return;
}
bd.initBoardSize(pzl.cols, pzl.rows);
if (pzl.variant !== null) {
puzzle.setConfig("variant", true);
puzzle.setConfig("variantid", pzl.variant);
}
if (!!pzl.body) {
this.pflag = pzl.pflag;
this.outbstr = pzl.body;
switch (pzl.type) {
case pzl.URL_PZPRV3:
case pzl.URL_KANPENP:
this.decodePzpr(pzl.URL_PZPRV3);
break;
case pzl.URL_PZPRAPP:
this.decodePzpr(pzl.URL_PZPRAPP);
break;
case pzl.URL_KANPEN:
this.fio = new puzzle.klass.FileIO();
this.fio.dataarray = this.outbstr.replace(/_/g, " ").split("/");
this.decodeKanpen();
this.fio = null;
break;
case pzl.URL_HEYAAPP:
this.decodeHeyaApp();
break;
}
}
bd.rebuildInfo();
},
encodeURL: function(type, mode) {
var puzzle = this.puzzle,
pid = puzzle.pid,
bd = puzzle.board;
var pzl = new Parser.URLData("", mode);
type =
type || pzl.URL_PZPRV3; /* type===pzl.URL_AUTO(0)もまとめて変換する */
if (type === pzl.URL_KANPEN && pid === "lits") {
type = pzl.URL_KANPENP;
}
this.outpflag = null;
var variant = puzzle.getConfig("variant");
this.outvariant = variant ? puzzle.getConfig("variantid") : null;
this.outcols = bd.cols;
this.outrows = bd.rows;
this.outbstr = "";
switch (type) {
case pzl.URL_PZPRV3:
this.encodePzpr(pzl.URL_PZPRV3);
break;
case pzl.URL_PZPRFILE:
var lines = this.puzzle.getFileData(pzl.FILE_PZPRV3).split("\n");
lines = lines.map(encodeURIComponent);
this.outbstr = lines.join("/");
break;
case pzl.URL_PZPRAPP:
throw "no implementation";
case pzl.URL_KANPENP:
if (!puzzle.info.exists.kanpen) {
throw "no implementation";
}
this.encodePzpr(pzl.URL_PZPRAPP);
this.outpflag = this.outpflag || "";
break;
case pzl.URL_KANPEN:
this.fio = new puzzle.klass.FileIO();
this.encodeKanpen();
this.outbstr = this.fio.datastr
.replace(/\r?\n/g, "/")
.replace(/ /g, "_");
this.fio = null;
break;
case pzl.URL_HEYAAPP:
this.encodeHeyaApp();
break;
default:
throw "invalid URL Type";
}
pzl.pid = pid;
pzl.type = type;
pzl.pflag = this.outpflag;
pzl.variant = this.outvariant;
pzl.cols = this.outcols;
pzl.rows = this.outrows;
pzl.body = this.outbstr;
return pzl.generate();
},
// オーバーライド用
decodePzpr: function(type) {
throw "no implementation";
},
encodePzpr: function(type) {
throw "no implementation";
},
decodeKanpen: function() {
throw "no implementation";
},
encodeKanpen: function() {
throw "no implementation";
},
decodeHeyaApp: function() {
throw "no implementation";
},
encodeHeyaApp: function() {
throw "no implementation";
}
}
});