@jx3box/jx3box-editor 1.4.9 → 1.4.10

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/GameText.vue +157 -118
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-editor",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "description": "JX3BOX Article & Editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/GameText.vue CHANGED
@@ -2,141 +2,180 @@
2
2
  * @Author: X3ZvaWQ
3
3
  * @Date: 2022-08-20 20:23:57
4
4
  * @LastEditors: X3ZvaWQ
5
- * @LastEditTime: 2022-08-20 23:12:34
5
+ * @LastEditTime: 2022-08-23 20:36:40
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>
13
13
  import { extractTextContent, getLink } from "@jx3box/jx3box-common/js/utils";
14
14
  import { getResource } from "../service/resource";
15
+ import { escape } from "lodash";
15
16
 
16
17
  export default {
17
- name: "GameText",
18
- props: {
19
- text: {
20
- type: String,
21
- default: "",
22
- },
23
- client: {
24
- type: String,
25
- default: "std",
26
- },
18
+ name: "GameText",
19
+ props: {
20
+ text: {
21
+ type: String,
22
+ default: "",
27
23
  },
28
- data: function () {
29
- return {
30
- html: "",
31
- };
24
+ client: {
25
+ type: String,
26
+ default: "std",
32
27
  },
33
- methods: {
34
- /**
35
- * 渲染某一个单独的Text标签成Span或链接
36
- * @param {*} school_id
37
- * @returns
38
- */
39
- renderItemHtml: function (item) {
40
- let content = item.text;
41
- let style = ``;
42
- let link = null;
43
- content = content.replace(/\n/g, "<br />").replace(/\\/g, "");
44
- if ([item.r, item.g, item.b].every((v) => v != undefined && v > 0)) {
45
- style = `color: rgb(${item.r}, ${item.g}, ${item.b});`;
46
- } else if (item.font != undefined) {
47
- const fonts = require("../assets/data/game_font.json");
48
- for (let color in fonts) {
49
- if (fonts[color].includes(item.font)) {
50
- style = `color: ${color};`;
51
- break;
52
- }
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}秒`;
53
124
  }
54
- }
55
- if (item.name == "iteminfolink" && item.script) {
56
- let item_type = item.script?.match(/this\.dwTabType=(\d+)/i)?.[1];
57
- let item_index = item.script?.match(/this\.dwIndex=(\d+)/i)?.[1];
58
- if (item_type && item_index) {
59
- let item_id = `${item_type}_${item_index}`;
60
- link = getLink("item", item_id);
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
+ }
61
137
  }
138
+ }
139
+ this.html = this.html.replace(item.token, value);
62
140
  }
63
- if (link) {
64
- return `<a style="${style} text-decoration: none;" target="_blank" href="${link}">${content}</a>`;
65
- } else {
66
- return `<span style="${style}">${content}</span>`;
67
- }
68
- },
69
- /**
70
- * 将一段游戏内文本转换为Html
71
- * @param {Object[]} texts 标签对象
72
- */
73
- renderTextHtml: function (Text) {
74
- let result = Text;
75
- const matches = Text.match(/<Text>(.*?)<\/text>/gimsy);
76
- if (!matches) return Text;
77
- for (let match of matches) {
78
- let text = extractTextContent(match);
79
- let html = this.renderItemHtml(text[0]);
80
- result = result.replace(match, html);
81
- }
82
- return result;
83
- },
84
- /**
85
- * 获取形如<BUFF 110 1 desc>的资源字段并转换
86
- */
87
- renderResource: function () {
88
- const matches = this.html.match(/<BUFF (\d+) (\d+) (.*?)>/gim);
89
- if (!matches) return;
90
- for (let match of matches) {
91
- let [, id, level, type] = match.match(/<BUFF (\d+) (\d+) (.*?)>/i);
92
- type = type.toLowerCase();
93
- let type_map = {
94
- desc: "Desc",
95
- time: "Interval",
96
- };
97
- getResource(`buff.${id}_${level}`, this.client)
98
- .then((res) => {
99
- let data = res.data;
100
- let attr = type_map[type] || type;
101
- let value = data[attr];
102
- if (typeof value == "number" && type == "time") {
103
- let time = value / 16;
104
- if (time > 60) {
105
- time = `${Math.floor(time / 60)}分钟`;
106
- } else {
107
- time = `${time}秒`;
108
- }
109
- this.html = this.html.replace(match, time);
110
- return;
111
- }
112
- if (!value) return;
113
- let _matches = value.match(/<BUFF ([0-9a-zA-Z]+)>/gi);
114
- if (!_matches) this.html = this.html.replace(match, value);
115
- for (let _match of _matches) {
116
- let [, _attr] = _match.match(/<BUFF ([0-9a-zA-Z]+)>/i);
117
- for (let i = 1; i < 15; i++) {
118
- if (data[`BeginAttrib${i}`] == _attr) {
119
- value = value.replace(_match, data[`BeginValue${i}A`]);
120
- }
121
- }
122
- }
123
- this.html = this.html.replace(match, value);
124
- })
125
- .catch((err) => {
126
- console.log(err);
127
- });
128
- }
129
- },
141
+ })
142
+ .catch((err) => {
143
+ console.log(err);
144
+ });
145
+ }
146
+ },
147
+ renderEnchantResource: function () {
148
+ const matches = this.html.match(/<ENCHANT (\d+)>/gim);
149
+ for (let match of matches) {
150
+ let enchant_id = match.match(/<ENCHANT (\d+)>/i)[1];
151
+ getResource(`enchant.${enchant_id}`, this.client)
152
+ .then((res) => {
153
+ let data = res.data;
154
+ let time = data.Time;
155
+ if (time) time = `,持续${parseInt(time) / 60}分钟。`;
156
+ let result = `${data.AttriName}${time ? time : ""}`;
157
+ this.html = this.html.replace(match, result);
158
+ })
159
+ .catch((err) => {
160
+ this.html = this.html.replace(match, escape(match));
161
+ console.log(err);
162
+ });
163
+ }
164
+ },
165
+ renderResource: function () {
166
+ this.renderBuffResource();
167
+ this.renderEnchantResource();
130
168
  },
131
- watch: {
132
- text: {
133
- immediate: true,
134
- handler: function (val) {
135
- this.html = this.renderTextHtml(val);
136
- this.renderResource();
137
- },
138
- },
169
+ },
170
+ watch: {
171
+ text: {
172
+ immediate: true,
173
+ handler: function (val) {
174
+ this.html = this.renderTextHtml(val);
175
+ this.renderResource();
176
+ },
139
177
  },
178
+ },
140
179
  };
141
180
  </script>
142
181