@jx3box/jx3box-editor 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-editor",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "JX3BOX Article & Editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/GameText.vue CHANGED
@@ -6,7 +6,7 @@
6
6
  * @Description: 用于渲染游戏内Text标签的文本
7
7
  -->
8
8
  <template>
9
- <span v-html="html"></span>
9
+ <span v-html="html"></span>
10
10
  </template>
11
11
 
12
12
  <script>
@@ -15,170 +15,205 @@ import { getResource } from "../service/resource";
15
15
  import { escape } from "lodash";
16
16
 
17
17
  export default {
18
- name: "GameText",
19
- props: {
20
- text: {
21
- type: String,
22
- default: "",
18
+ name: "GameText",
19
+ props: {
20
+ text: {
21
+ type: String,
22
+ default: "",
23
+ },
24
+ client: {
25
+ type: String,
26
+ default: "std",
27
+ },
23
28
  },
24
- client: {
25
- type: String,
26
- default: "std",
29
+ data: function () {
30
+ return {
31
+ html: "",
32
+ };
27
33
  },
28
- },
29
- data: function () {
30
- return {
31
- html: "",
32
- };
33
- },
34
- methods: {
35
- /**
36
- * 渲染某一个单独的Text标签成Span或链接
37
- * @param {*} school_id
38
- * @returns
39
- */
40
- renderItemHtml: function (item) {
41
- let content = item.text;
42
- let style = ``;
43
- let link = null;
44
- content = content.replace(/\\n/g, "<br />").replace(/\\/g, "");
45
- if ([item.r, item.g, item.b].every((v) => v != undefined && v > 0)) {
46
- style = `color: rgb(${item.r}, ${item.g}, ${item.b});`;
47
- } else if (item.font != undefined && item.font != 100) {
48
- const fonts = require("../assets/data/game_font.json");
49
- for (let color in fonts) {
50
- if (fonts[color].includes(item.font)) {
51
- style = `color: ${color};`;
52
- break;
53
- }
54
- }
55
- }
56
- if (item.name == "iteminfolink" && item.script) {
57
- let item_type = item.script?.match(/this\.dwTabType=(\d+)/i)?.[1];
58
- let item_index = item.script?.match(/this\.dwIndex=(\d+)/i)?.[1];
59
- if (item_type && item_index) {
60
- let item_id = `${item_type}_${item_index}`;
61
- link = getLink("item", item_id);
62
- }
63
- }
64
- if (link) {
65
- return `<a style="${style} text-decoration: none;" target="_blank" href="${link}">${content}</a>`;
66
- } else {
67
- return `<span style="${style}">${content}</span>`;
68
- }
69
- },
70
- /**
71
- * 将一段游戏内文本转换为Html
72
- * @param {Object[]} texts 标签对象
73
- */
74
- renderTextHtml: function (Text) {
75
- let result = Text;
76
- const matches = Text.match(/<Text>(.*?)<\/text>/gimsy);
77
- if (!matches) return Text;
78
- for (let match of matches) {
79
- let text = extractTextContent(match);
80
- let html = this.renderItemHtml(text[0]);
81
- result = result.replace(match, html);
82
- }
83
- return result;
84
- },
85
- /**
86
- * 获取形如<BUFF 110 1 desc>, <ENCHANT 100>的资源字段并转换
87
- */
88
- renderBuffResource: function () {
89
- const matches = this.html.match(/<BUFF (\d+) (\d+) (.*?)>/gim);
90
- if (!matches) return;
91
- let need_replaces = {};
92
- //先统计需要的资源,减少请求数量
93
- for (let match of matches) {
94
- let [token, id, level, type] = match.match(/<BUFF (\d+) (\d+) (.*?)>/i);
95
- let buff_token = `${id}_${level}`;
96
- if (!need_replaces[buff_token]) {
97
- need_replaces[buff_token] = [];
98
- }
99
- need_replaces[buff_token].push({
100
- token,
101
- type,
102
- });
103
- }
104
- //对每一个需要的资源发起请求
105
- for (let buff_token in need_replaces) {
106
- let token_item = need_replaces[buff_token];
107
- getResource(`buff.${buff_token}`, this.client)
108
- .then((res) => {
109
- let data = res.data;
110
- for (let item of token_item) {
111
- item.type = item.type.toLowerCase();
112
- let type_map = {
113
- desc: "Desc",
114
- time: "Interval",
115
- };
116
- let attr = type_map[item.type] || item.type;
117
- let value = data[attr];
118
- if (typeof value == "number" && item.type == "time") {
119
- let time = value / 16;
120
- if (time > 60) {
121
- time = `${Math.floor(time / 60)}分钟`;
122
- } else {
123
- time = `${time}秒`;
34
+ methods: {
35
+ /**
36
+ * 渲染某一个单独的Text标签成Span或链接
37
+ * @param {*} school_id
38
+ * @returns
39
+ */
40
+ renderItemHtml: function (item) {
41
+ let content = item.text;
42
+ let style = ``;
43
+ let link = null;
44
+ content = content.replace(/\\n/g, "<br />").replace(/\\/g, "");
45
+ if ([item.r, item.g, item.b].every(v => v != undefined && v > 0)) {
46
+ style = `color: rgb(${item.r}, ${item.g}, ${item.b});`;
47
+ } else if (item.font != undefined && item.font != 100) {
48
+ const fonts = require("../assets/data/game_font.json");
49
+ for (let color in fonts) {
50
+ if (fonts[color].includes(item.font)) {
51
+ style = `color: ${color};`;
52
+ break;
53
+ }
124
54
  }
125
- this.html = this.html.replace(item.token, time);
126
- return;
127
- }
128
- if (!value) return;
129
- let _matches = value.match(/<BUFF ([0-9a-zA-Z]+)>/gi);
130
- if (!_matches) this.html = this.html.replace(match, value);
131
- for (let _match of _matches) {
132
- let [, _attr] = _match.match(/<BUFF ([0-9a-zA-Z]+)>/i);
133
- for (let i = 1; i < 15; i++) {
134
- if (data[`BeginAttrib${i}`] == _attr) {
135
- value = value.replace(_match, data[`BeginValue${i}A`]);
136
- }
55
+ }
56
+ if (item.name == "iteminfolink" && item.script) {
57
+ let item_type = item.script?.match(
58
+ /this\.dwTabType=(\d+)/i
59
+ )?.[1];
60
+ let item_index =
61
+ item.script?.match(/this\.dwIndex=(\d+)/i)?.[1];
62
+ if (item_type && item_index) {
63
+ let item_id = `${item_type}_${item_index}`;
64
+ link = getLink("item", item_id);
137
65
  }
138
- }
139
- this.html = this.html.replace(item.token, value);
140
66
  }
141
- })
142
- .catch((err) => {
143
- console.log(err);
144
- });
145
- }
146
- },
147
- renderEnchantResource: function () {
148
- const matches = this.html.match(/<ENCHANT (\d+)>/gim);
149
- if(!matches) return;
150
- for (let match of matches) {
151
- let enchant_id = match.match(/<ENCHANT (\d+)>/i)[1];
152
- getResource(`enchant.${enchant_id}`, this.client)
153
- .then((res) => {
154
- let data = res.data;
155
- let time = data.Time;
156
- if (time) time = `,持续${parseInt(time) / 60}分钟。`;
157
- let result = `${data.AttriName}${time ? time : ""}`;
158
- this.html = this.html.replace(match, result);
159
- })
160
- .catch((err) => {
161
- this.html = this.html.replace(match, escape(match));
162
- console.log(err);
163
- });
164
- }
165
- },
166
- renderResource: function () {
167
- this.renderBuffResource();
168
- this.renderEnchantResource();
67
+ if (link) {
68
+ return `<a style="${style} text-decoration: none;" target="_blank" href="${link}">${content}</a>`;
69
+ } else {
70
+ return `<span style="${style}">${content}</span>`;
71
+ }
72
+ },
73
+ /**
74
+ * 将image标签转换为HTML标签
75
+ */
76
+ renderImageHtml: function (Text) {
77
+ // <image>path="fromiconid" frame=1241 w=29 h=29 </image>
78
+ let matches = Text.match(/<image>(.*?)<\/image>/gims);
79
+ console.log(Text, matches);
80
+ if (!matches) return Text;
81
+ for (let match of matches) {
82
+ let icon_id = match.match(/frame=(\d+)/i)?.[1];
83
+ let w = parseInt(match.match(/w=(\d+)/i)?.[1]) / 1.12;
84
+ let h = parseInt(match.match(/h=(\d+)/i)?.[1]) / 1.12;
85
+ let src = `https://icon.jx3box.com/icon/${icon_id}.png`;
86
+ let html = `<img src="${src}" style="width: ${w}px; height: ${h}px; margin-bottom: -5px" />`;
87
+ Text = Text.replace(match, html);
88
+ }
89
+ return Text;
90
+ },
91
+ /**
92
+ * 将一段游戏内文本转换为Html
93
+ * @param {Object[]} texts 标签对象
94
+ */
95
+ renderTextHtml: function (Text) {
96
+ let result = Text;
97
+ result = this.renderImageHtml(result);
98
+ const matches = Text.match(/<Text>(.*?)<\/text>/gims);
99
+ if (!matches) return Text;
100
+ for (let match of matches) {
101
+ let text = extractTextContent(match);
102
+ let html = this.renderItemHtml(text[0]);
103
+ result = result.replace(match, html);
104
+ }
105
+ return result;
106
+ },
107
+ /**
108
+ * 获取形如<BUFF 110 1 desc>, <ENCHANT 100>的资源字段并转换
109
+ */
110
+ renderBuffResource: function () {
111
+ const matches = this.html.match(/<BUFF (\d+) (\d+) (.*?)>/gim);
112
+ if (!matches) return;
113
+ let need_replaces = {};
114
+ //先统计需要的资源,减少请求数量
115
+ for (let match of matches) {
116
+ let [token, id, level, type] = match.match(
117
+ /<BUFF (\d+) (\d+) (.*?)>/i
118
+ );
119
+ let buff_token = `${id}_${level}`;
120
+ if (!need_replaces[buff_token]) {
121
+ need_replaces[buff_token] = [];
122
+ }
123
+ need_replaces[buff_token].push({
124
+ token,
125
+ type,
126
+ });
127
+ }
128
+ //对每一个需要的资源发起请求
129
+ for (let buff_token in need_replaces) {
130
+ let token_item = need_replaces[buff_token];
131
+ getResource(`buff.${buff_token}`, this.client)
132
+ .then(res => {
133
+ let data = res.data;
134
+ for (let item of token_item) {
135
+ item.type = item.type.toLowerCase();
136
+ let type_map = {
137
+ desc: "Desc",
138
+ time: "Interval",
139
+ };
140
+ let attr = type_map[item.type] || item.type;
141
+ let value = data[attr];
142
+ if (
143
+ typeof value == "number" &&
144
+ item.type == "time"
145
+ ) {
146
+ let time = value / 16;
147
+ if (time > 60) {
148
+ time = `${Math.floor(time / 60)}分钟`;
149
+ } else {
150
+ time = `${time}秒`;
151
+ }
152
+ this.html = this.html.replace(item.token, time);
153
+ return;
154
+ }
155
+ if (!value) return;
156
+ let _matches = value.match(
157
+ /<BUFF ([0-9a-zA-Z]+)>/gi
158
+ );
159
+ if (!_matches)
160
+ this.html = this.html.replace(match, value);
161
+ for (let _match of _matches) {
162
+ let [, _attr] = _match.match(
163
+ /<BUFF ([0-9a-zA-Z]+)>/i
164
+ );
165
+ for (let i = 1; i < 15; i++) {
166
+ if (data[`BeginAttrib${i}`] == _attr) {
167
+ value = value.replace(
168
+ _match,
169
+ data[`BeginValue${i}A`]
170
+ );
171
+ }
172
+ }
173
+ }
174
+ this.html = this.html.replace(item.token, value);
175
+ }
176
+ })
177
+ .catch(err => {
178
+ console.log(err);
179
+ });
180
+ }
181
+ },
182
+ renderEnchantResource: function () {
183
+ const matches = this.html.match(/<ENCHANT (\d+)>/gim);
184
+ if (!matches) return;
185
+ for (let match of matches) {
186
+ let enchant_id = match.match(/<ENCHANT (\d+)>/i)[1];
187
+ getResource(`enchant.${enchant_id}`, this.client)
188
+ .then(res => {
189
+ let data = res.data;
190
+ let time = data.Time;
191
+ if (time) time = `,持续${parseInt(time) / 60}分钟。`;
192
+ let result = `${data.AttriName}${time ? time : ""}`;
193
+ this.html = this.html.replace(match, result);
194
+ })
195
+ .catch(err => {
196
+ this.html = this.html.replace(match, escape(match));
197
+ console.log(err);
198
+ });
199
+ }
200
+ },
201
+ renderResource: function () {
202
+ this.renderBuffResource();
203
+ this.renderEnchantResource();
204
+ },
169
205
  },
170
- },
171
- watch: {
172
- text: {
173
- immediate: true,
174
- handler: function (val) {
175
- this.html = this.renderTextHtml(val);
176
- this.renderResource();
177
- },
206
+ watch: {
207
+ text: {
208
+ immediate: true,
209
+ handler: function (val) {
210
+ if (!val) return;
211
+ this.html = this.renderTextHtml(val);
212
+ this.renderResource();
213
+ },
214
+ },
178
215
  },
179
- },
180
216
  };
181
217
  </script>
182
218
 
183
- <style>
184
- </style>
219
+ <style></style>
package/src/Item.vue CHANGED
@@ -63,7 +63,7 @@
63
63
  <div class="u-horse-desc" v-html="attribute.label"></div>
64
64
  </span>
65
65
  <span v-else class="u-value">
66
- <span v-text="attribute.label"></span>
66
+ <game-text :text="attribute.label"></game-text>
67
67
  <!-- <span
68
68
  class="u-yellow"
69
69
  v-text="