editGame.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * @Author: CGT (caogtaa@gmail.com)
  3. * @Date: 2020-01-16 22:09:21
  4. * @Last Modified by: CGT (caogtaa@gmail.com)
  5. * @Last Modified time: 2020-01-16 23:45:39
  6. */
  7. 'use strict';
  8. let _config = {};
  9. Editor.Panel.extend({
  10. // css style for panel
  11. style: `
  12. :host { margin: 5px; }
  13. :host ui-input { width: 100%; }
  14. h2 { color: #f90; }
  15. ul {
  16. list-style-type: none;
  17. padding-inline-start: 20px;
  18. }
  19. ul.root {
  20. padding-inline-start: 15px;
  21. }
  22. ul li {
  23. padding: 2px 10px 1px 0;
  24. text-align: -webkit-match-parent;
  25. color: #ccc;
  26. border-bottom: 1px solid #454545;
  27. box-sizing: border-box;
  28. }
  29. span.selected {
  30. background: #555;
  31. }
  32. .caret {
  33. cursor: pointer;
  34. user-select: none;
  35. width: 12px;
  36. display: inline-block;
  37. }
  38. .caret-holder {
  39. width: 12px;
  40. display: inline-block;
  41. }
  42. .caret::before {
  43. content: "\\25B6";
  44. color: #ccc;
  45. display: inline-block;
  46. margin-right: 6px;
  47. }
  48. .caret-down::before {
  49. transform: rotate(90deg);
  50. }
  51. .nested {
  52. display: none;
  53. }
  54. .collapsed {
  55. }
  56. .active:not(.collapsed) {
  57. display: block;
  58. }
  59. `,
  60. // html template for panel
  61. template: `
  62. <p>先选择游戏类型,再选择学期-课程-关卡</p>
  63. <div v-if="d.loaded">
  64. <ui-box-container>
  65. <div class="layout horizontal start-justified">
  66. <ui-prop name="游戏类型">
  67. <ui-select v-value="d.config.gameType" @change="onTypeChange($event)">
  68. <option value="0">测试</option>
  69. <option value="1">课堂版</option>
  70. <option value="2">家长版</option>
  71. <option value="3">数学版</option>
  72. <option value="4">闯关版</option>
  73. <option value="5">无尽版</option>
  74. <option value="6">识字宝</option>
  75. <option value="7">数感宝</option>
  76. <option value="9">拼音宝</option>
  77. </ui-select>
  78. </ui-prop>
  79. </div>
  80. <div class="layout horizontal start-justified">
  81. <ui-prop name="学期:">
  82. <ui-select v-value="d.config.semeID" @change="onSemeIDChange($event)">
  83. <option value="231">2-3岁上学期</option>
  84. <option value="232">2-3岁下学期</option>
  85. <option value="341">3-4岁上学期</option>
  86. <option value="342">3-4岁下学期</option>
  87. <option value="451">4-5岁上学期</option>
  88. <option value="452">4-5岁下学期</option>
  89. <option value="561">5-6岁上学期</option>
  90. <option value="562">5-6岁下学期</option>
  91. <option value="300">拼读训练</option>
  92. <option value="200">无尽关卡</option>
  93. <option value="100">测试关卡</option>
  94. </ui-select>
  95. </ui-prop>
  96. <ui-prop name="模板:">
  97. <ui-select v-value="d.config.modeID" @change="onModeIDChange($event)">
  98. <option value="0">不使用模板</option>
  99. <option value="1">拖拽模板</option>
  100. <option value="2">选择模板</option>
  101. <option value="3">连线模板</option>
  102. <option value="4">迷宫模板</option>
  103. <option value="5">翻页拖拽模板</option>
  104. <option value="6">翻页选择模板</option>
  105. <option value="7">运笔模板</option>
  106. <option value="8">演示模板</option>
  107. <option value="9">翻页演示模板</option>
  108. <option value="10">翻页连线模板</option>
  109. <option value="11">无尽记忆模板</option>
  110. <option value="12">无尽选择模板</option>
  111. <option value="13">无尽赛车模板</option>
  112. <option value="14">无尽对对碰模板</option>
  113. <option value="15">无尽打地鼠模板</option>
  114. <option value="16">无尽汉字翻牌模板</option>
  115. <option value="17">接汉字模板</option>
  116. </ui-select>
  117. </ui-prop>
  118. </div>
  119. <div class="layout horizontal start-justified">
  120. <ui-prop name="课程">
  121. <ui-input v-value="d.config.gameID" placeholder="请输入课程"></ui-input>
  122. </ui-prop>
  123. <ui-prop name="关卡">
  124. <ui-input v-value="d.config.partID" placeholder="请输入关卡"></ui-input>
  125. </ui-prop>
  126. <ui-prop name="汉字">
  127. <ui-input v-value="d.config.word" placeholder="请输入汉字" @change="onWordChange"></ui-input>
  128. <ui-prop id="wordCode" name=""></ui-prop>
  129. </ui-prop>
  130. </div>
  131. </ui-box-container>
  132. <ui-box-container>
  133. <div class="layout horizontal around-justified">
  134. <ui-button id="in" @confirm="onImportConfirm" class="green">导入关卡</ui-button>
  135. <ui-button id="out" @confirm="onOutConfirm" class="red">导出关卡</ui-button>
  136. <ui-button id="save" @confirm="onSaveGameConfirm" class="blue">保存关卡</ui-button>
  137. <ui-button id="inBg" @confirm="onInBgAni" class="red">导入背景动画</ui-button>
  138. <ui-button id="saveBg" @confirm="onOutBgAni" class="green">保存背景动画</ui-button>
  139. </div>
  140. <hr />
  141. <div class="layout horizontal around-justified">
  142. <ui-prop name="页数">
  143. <ui-select v-value="d.config.guidePage" @change="onGuidePageChange($event)">
  144. <option value="1">第1页</option>
  145. <option value="2">第2页</option>
  146. <option value="3">第3页</option>
  147. <option value="4">第4页</option>
  148. <option value="5">第5页</option>
  149. <option value="6">第6页</option>
  150. <option value="7">第7页</option>
  151. <option value="8">第8页</option>
  152. <option value="9">第9页</option>
  153. <option value="10">第10页</option>
  154. </ui-select>
  155. </ui-prop>
  156. <ui-button id="in" @confirm="onGuideImport" class="green">导入引导</ui-button>
  157. <ui-button id="out" @confirm="onGuideOut" class="red">导出引导</ui-button>
  158. <ui-button id="save" @confirm="onSaveGuide" class="blue">保存引导</ui-button>
  159. <ui-button id="play" @confirm="onPlayGuide" class="red">播放引导</ui-button>
  160. <ui-button id="pause" @confirm="onPauseGuide" class="blue">暂停引导</ui-button>
  161. <ui-button id="reset" @confirm="onResetGuide" class="green">重置引导</ui-button>
  162. <ui-button id="nodePlay" @confirm="onPlayNodeGuide" class="red">单独播放</ui-button>
  163. </div>
  164. </ui-box-container>
  165. <ui-box-container>
  166. <div class="layout horizontal around-justified">
  167. <ui-button id="in" @confirm="onTeacherImport" class="green">导入讲解</ui-button>
  168. <ui-button id="out" @confirm="onTeacherOut" class="red">导出讲解</ui-button>
  169. <ui-button id="out" @confirm="onTeacherSave" class="red">保存讲解</ui-button>
  170. </div>
  171. </ui-box-container>
  172. </div>
  173. `,
  174. // element and variable binding
  175. $: {},
  176. // method executed when template and styles are successfully loaded and initialized
  177. ready() {
  178. const fs = require('fs');
  179. let temp = Editor.Project.path + '/temp/temp_game_edit_config.json';
  180. let configPath = temp;
  181. if (!fs.existsSync(temp)) {
  182. // read default config
  183. configPath = Editor.url('packages://cc-ext-scene-menu/temp_game_edit_config.json');
  184. }
  185. let saveConfig = () => {
  186. let data = JSON.stringify(_config, null, 4);
  187. fs.writeFile(temp, data, function (err) {
  188. if (err) {
  189. Editor.log('保存当前导出记录失败:' + err);
  190. return;
  191. }
  192. });
  193. };
  194. let initWindow = (config) => {
  195. _config = config;
  196. _config.guidePage = 1
  197. new window.Vue({
  198. el: this.shadowRoot,
  199. data: {
  200. d: {
  201. config: _config,
  202. loaded: true,
  203. }
  204. },
  205. methods: {
  206. onImportConfirm(e) {
  207. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'importGame', _config, (err) => {
  208. if (err) Editor.error(err);
  209. });
  210. },
  211. onOutConfirm(e) {
  212. saveConfig();
  213. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'outGameJson', _config, (err) => {
  214. if (err) Editor.error(err);
  215. }, 20000);
  216. },
  217. onSaveGameConfirm(e) {
  218. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'saveGameJson', _config, (err) => {
  219. if (err) Editor.error(err);
  220. }, 20000);
  221. },
  222. onWordChange(e) {
  223. e.target.parentElement.getElementsByTagName("ui-prop")[0].name = _config.word ? _config.word.charCodeAt() : ''
  224. },
  225. onInBgAni(e) {
  226. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'inBgAni', _config, (err) => {
  227. if (err) Editor.error(err);
  228. }, 20000);
  229. },
  230. onOutBgAni(e) {
  231. saveConfig();
  232. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'outBgAni', _config, (err) => {
  233. if (err) Editor.error(err);
  234. }, 20000);
  235. },
  236. onTypeChange(e) {
  237. Editor.log(`导入关卡选择的版本: ${_config.gameType}`)
  238. },
  239. onSemeIDChange(e) {
  240. Editor.log(`导入关卡选择的学期: ${_config.semeID}`)
  241. },
  242. onModeIDChange(e) {
  243. Editor.log(`导入关卡选择的模板: ${_config.modeID}`)
  244. },
  245. onGuideImport(e) {
  246. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'guideImport', _config, (err) => {
  247. if (err) Editor.error(err);
  248. }, 20000);
  249. },
  250. onGuideOut(e) {
  251. saveConfig();
  252. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'guideOut', _config, (err) => {
  253. if (err) Editor.error(err);
  254. }, 20000);
  255. },
  256. onSaveGuide(e) {
  257. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'savaGuide', _config, (err) => {
  258. if (err) Editor.error(err);
  259. }, 20000);
  260. },
  261. onPlayGuide(e) {
  262. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'playGuide', _config, (err) => {
  263. if (err) Editor.error(err);
  264. }, 20000);
  265. },
  266. onPauseGuide(e) {
  267. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'pauseGuide', _config, (err) => {
  268. if (err) Editor.error(err);
  269. }, 20000);
  270. },
  271. onResetGuide(e) {
  272. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'resetGuide', _config, (err) => {
  273. if (err) Editor.error(err);
  274. }, 20000);
  275. },
  276. onGuidePageChange(e) {
  277. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'guidePageChange', _config, (err) => {
  278. if (err) Editor.error(err);
  279. }, 20000);
  280. },
  281. onPlayNodeGuide(e) {
  282. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'playNodeGuide', _config, (err) => {
  283. if (err) Editor.error(err);
  284. }, 20000);
  285. },
  286. onTeacherImport(e) {
  287. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'teacherImport', _config, (err) => {
  288. if (err) Editor.error(err);
  289. }, 20000);
  290. },
  291. onTeacherOut(e) {
  292. saveConfig();
  293. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'teacherOut', _config, (err) => {
  294. if (err) Editor.error(err);
  295. }, 20000);
  296. },
  297. onTeacherSave(e) {
  298. Editor.Scene.callSceneScript('cc-ext-scene-menu', 'savaTeacher', _config, (err) => {
  299. if (err) Editor.error(err);
  300. }, 20000);
  301. },
  302. }
  303. });
  304. };
  305. fs.readFile(configPath, function (err, data) {
  306. if (err) {
  307. // file not exists
  308. initWindow([]);
  309. return;
  310. }
  311. let config = [];
  312. try {
  313. config = JSON.parse(data);
  314. // Editor.log(`index.js read data: ${data}`);
  315. } catch (err) {
  316. } finally {
  317. initWindow(config);
  318. }
  319. });
  320. },
  321. // register your ipc messages here
  322. messages: {}
  323. });