Skip to content

Commit d116cff

Browse files
committed
1.Demo添加了一个测试按钮,便于直接跳转到指定章节和剧情位置
2.框架源码添加判断是否存在剧情文件对应的代码文件,如果不存在自定义js文件,不执行eval函数 3.预计下次将module源码文件夹合并到fullExample便于测试。 4.之后,框架源码将会与测试Demo绑定,单独复制出来用,可能需要改一下 执行到<end时的路径
1 parent 8e1c58a commit d116cff

File tree

8 files changed

+126
-7
lines changed

8 files changed

+126
-7
lines changed

bin/音乐餐厅/Scene/Game.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!-- 禁用缓存 -->
77
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
88
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
9-
<META HTTP-EQUIV="Expires" CONTENT="0">
9+
<META HTTP-EQUIV="Expires" CONTENT="0">
1010
<!--框架运行强制依赖js插件-->
1111
<!--<script src="jQuery_main.js"></script>-->
1212
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
@@ -35,8 +35,10 @@ <h1> EasyAvgFramework </h1>
3535
<button id="history">历史记录</button>
3636
<button id="hideDialog">隐藏对话框</button>
3737
<button id="clearAll">清空所有localStorage</button>
38-
<button id="loadFromChapterBtn">从头加载指定的章节 方便测试用</button>
39-
<sapn>开发游戏时,请删除这个防止玩家乱点</span>
38+
<br>
39+
<input id="loadFromInput" style="width:300px;" placeholder="请输入要加载的章节 格式1_1 章节_第几句话的索引">
40+
<button id="loadFromChapterBtn">加载</button>
41+
<span>从输入的位置加载指定的章节方便测试用</span> <sapn>开发游戏时,请删除这个防止玩家乱点</span>
4042
<ol id="HistoryPanel" style="display:none"></ol>
4143
<h6> Copyright © 2020 小沙盒工作室&128hh. </h6>
4244
</body>

bin/音乐餐厅/Scene/InitGame.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ $(function()
5555
{
5656
file.clearAll()
5757
})
58+
5859
}
5960
initUI()
6061
//显示bgm
@@ -129,4 +130,24 @@ $("#saveGame").click(function()
129130
changeScene("../Load_and_Save.html")
130131
}
131132
})
133+
//读取指定的章节文件
134+
$("#loadFromChapterBtn").click(function()
135+
{
136+
var input_str=$("#loadFromInput").val()
137+
var chapterIndex=input_str.split("_")[0]
138+
var lineIndex=input_str.split("_")[1]
139+
var dataObj=PlotLoader.load_from(chapterIndex,lineIndex)
140+
if(dataObj!=null)
141+
{
142+
console.log("存在数据")
143+
dialog.setLoadContent(dataObj)
144+
console.log("#游戏进度_>_"+t_data)
145+
console.warn("#返回的加载后的数据");
146+
console.log(dataObj);
147+
}
148+
else
149+
{
150+
console.log("#错误,无法获得返回的加载数据")
151+
}
152+
})
132153
})

bin/音乐餐厅/module/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ this.create_Dialog=function(color)
113113
if(data_obj.has_func==false)
114114
{
115115
// console.clear()
116-
console.warn("#此章节不存在用于脚本,不执行脚本,测试信息,请忽略")
116+
console.warn("#此章节对应自定义js文件不存在,不执行脚本,测试信息,请忽略")
117117
alert("不存在js文件,跳过运算js代码")
118118
}
119119
if(data_obj.has_func==true)

fullExample/Scene/Game.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ <h1> EasyAvgFramework </h1>
3030
<button id="history">历史记录</button>
3131
<button id="hideDialog">隐藏对话框</button>
3232
<button id="clearAll">清空所有localStorage</button>
33+
<br>
34+
<input id="loadFromInput" style="width:300px;" placeholder="请输入要加载的章节 格式1_1 章节_第几句话的索引">
35+
<button id="loadFromChapterBtn">加载</button>
36+
<span>从输入的位置加载指定的章节方便测试用</span> <sapn>开发游戏时,请删除这个防止玩家乱点</span>
3337
<sapn>开发游戏时,请删除这个防止玩家乱点</span>
3438
<ol id="HistoryPanel" style="display:none"></ol>
3539
<h6> Copyright © 2020 小沙盒工作室&128hh. </h6>

fullExample/Scene/InitGame.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,24 @@ $("#saveGame").click(function()
124124
changeScene("../Load_and_Save.html")
125125
}
126126
})
127+
//读取指定的章节文件
128+
$("#loadFromChapterBtn").click(function()
129+
{
130+
var input_str=$("#loadFromInput").val()
131+
var chapterIndex=input_str.split("_")[0]
132+
var lineIndex=input_str.split("_")[1]
133+
var dataObj=PlotLoader.load_from(chapterIndex,lineIndex)
134+
if(dataObj!=null)
135+
{
136+
console.log("存在数据")
137+
dialog.setLoadContent(dataObj)
138+
console.log("#游戏进度_>_"+t_data)
139+
console.warn("#返回的加载后的数据");
140+
console.log(dataObj);
141+
}
142+
else
143+
{
144+
console.log("#错误,无法获得返回的加载数据")
145+
}
146+
})
127147
})

module/PlotLoader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//整合一下 这个将会是新的剧情加载器
2+
// NOTE: 这里细节需要修改一下 如果当前章节不需要对应的脚本,则不去获取脚本
23
function IPlotLoader()
34
{ // NOTE: 剧情加载器和脚本加载器应该由Dialog的clicks 驱动,只要返回数据到Dialog
45
//默认章节位置 默认句子位置 增加I防止混淆变量名称
@@ -9,8 +10,8 @@ function IPlotLoader()
910
// NOTE: 初始化的加载方法,用于开启新的游戏,从头开始读文件
1011
this.load=function(str_url,func_url)
1112
{
12-
//把剧情分词和函数分词存储一个数组 此时为二维数组,一次性return
13-
var final_obj={"plot_array":[],"func_array":[]}//剧情数组元素在前,函数数组元素在后
13+
//把剧情分词和函数分词存储为Json对象
14+
var final_obj={"plot_array":[],"func_array":[],"has_func":true}//剧情数组元素在前,函数数组元素在后
1415
//改用ajax同步方法 //async:false为同步 获取文本
1516
$.ajax({url:str_url,async:false,success:function(result)
1617
{
@@ -20,6 +21,11 @@ function IPlotLoader()
2021
$.ajax({url:func_url,async:false,success:function(result)
2122
{
2223
final_obj.func_array=result.split("\n")
24+
final_obj.has_func=true
25+
},error:function(xhr,status,error)
26+
{
27+
alert("此章节没有自定义js,不执行,执行has_func=false")
28+
final_obj.has_func=false
2329
}})
2430
//最后返回数据数组
2531
return final_obj

module/PlotLoader.js.备份

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//整合一下 这个将会是新的剧情加载器
2+
function IPlotLoader()
3+
{ // NOTE: 剧情加载器和脚本加载器应该由Dialog的clicks 驱动,只要返回数据到Dialog
4+
//默认章节位置 默认句子位置 增加I防止混淆变量名称
5+
this.IchapterIndex=0
6+
this.IlineIndex=0
7+
var chapterPath="../chapter/"
8+
var scriptPath="../chapterScript/"
9+
// NOTE: 初始化的加载方法,用于开启新的游戏,从头开始读文件
10+
this.load=function(str_url,func_url)
11+
{
12+
//把剧情分词和函数分词存储一个数组 此时为二维数组,一次性return
13+
var final_obj={"plot_array":[],"func_array":[]}//剧情数组元素在前,函数数组元素在后
14+
//改用ajax同步方法 //async:false为同步 获取文本
15+
$.ajax({url:str_url,async:false,success:function(result)
16+
{
17+
// alert(result)
18+
final_obj.plot_array=result.split("\n")
19+
}})
20+
$.ajax({url:func_url,async:false,success:function(result)
21+
{
22+
final_obj.func_array=result.split("\n")
23+
}})
24+
//最后返回数据数组
25+
return final_obj
26+
}
27+
// NOTE: 读取已经存在的存档 需要一个章节变量 一个index变量
28+
this.load_from=function(chapterIndex,lineIndex)
29+
{//暂存
30+
// NOTE: 逻辑是,在游戏的Init.js中(在玩家js之前,初始化的js)
31+
//1.如果获取到游戏数据,然后调用此方法,返回数据对象给Init.js,
32+
//2.Init.js再根据此对象,调用Dialog的setLoadContent方法,设置文本,同时同步更新Dialog内部计数器索引
33+
//3.Dialog每次点击,就自动是新的数据
34+
this.IchapterIndex=chapterIndex
35+
this.IlineIndex=lineIndex
36+
// NOTE: 新增两个参数,用于给Dialog设置指定位置的文本
37+
var final_obj={
38+
"plot_array":[],
39+
"func_array":[],
40+
"chapterIndex":chapterIndex,
41+
"lineIndex":lineIndex,
42+
}
43+
$.ajax({url:chapterPath+chapterIndex+".txt",async:false,success:function(result)
44+
{
45+
final_obj.plot_array=result.split("\n")
46+
final_obj.chapterIndex=Number(chapterIndex)
47+
final_obj.lineIndex=Number(lineIndex)
48+
}})
49+
$.ajax({url:scriptPath+"func"+chapterIndex+".js.txt",async:false,success:function(result)
50+
{
51+
final_obj.func_array=result.split("\n")
52+
}})
53+
return final_obj
54+
}
55+
56+
}

module/core.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ this.create_Dialog=function(color)
111111
console.log(dataObj.plot_array);
112112
var tmp_li=$("<li class='historyView'>"+dataObj.plot_array[0]+"</li>")
113113
$("#HistoryPanel").append(tmp_li)
114-
eval(dataObj.func_array[0])
114+
if(data_obj.has_func==false)
115+
{
116+
// console.clear()
117+
console.warn("#此章节对应自定义js文件不存在,不执行脚本,测试信息,请忽略")
118+
alert("不存在js文件,跳过运算js代码")
119+
}
120+
if(data_obj.has_func==true)
121+
{
122+
console.warn("#存在js脚本,运算它");
123+
eval(dataObj.func_array[0])
124+
}
115125
}
116126
//加载已经存在的游戏进度时使用的方法
117127
dialog.setLoadContent=function(data_obj)

0 commit comments

Comments
 (0)