Squashed commit of the following:
commitb421082374Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Dec 31 20:26:20 2021 +0800 update specialthanks commit765a69294bAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 19:10:03 2021 +0800 fix ios goto commit8eb8c3ca72Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 19:03:37 2021 +0800 add event grade commitab705dd46cAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:48:42 2021 +0800 build version commita1e4232369Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:47:05 2021 +0800 change talent replace before property allocate commitf4d7b3ae3cAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Dec 14 18:06:18 2021 +0800 add event grade commit0567e40ddcAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 21:28:10 2021 +0800 add particle commitf17003925eAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 20:14:26 2021 +0800 change ui commitf8beda1d8fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 19:08:30 2021 +0800 change popup message ui commit915a2aa17dAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 18:34:29 2021 +0800 new build commitb5edabc104Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 18:18:46 2021 +0800 add hint message commita143feadafAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 17:57:31 2021 +0800 fix copy bug commiteab1975791Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 17:56:28 2021 +0800 add save/load commitacf9b92134Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Dec 2 14:35:33 2021 +0800 add theme switch commit488a6054abAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Dec 1 18:30:36 2021 +0800 fix uiManager bug commitf0317eaf14Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Dec 1 16:07:03 2021 +0800 add message popup commiteb02d1ee6fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 21:22:54 2021 +0800 change relocation commit60503eae47Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:27:16 2021 +0800 change ScaleButton -> Laya.runtime.ScaleButton commit52ef5909c1Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:26:31 2021 +0800 change ScaleButton -> Laya.runtime.ScaleButton commit0284f6aa71Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 19:05:24 2021 +0800 config webpack commit0e272ffd99Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 13:17:41 2021 +0800 add thanks commite1e2ab4701Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 28 11:40:21 2021 +0800 add light theme commit4f55c00f86Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 27 22:27:39 2021 +0800 fix bug commit1d07bdfc46Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 27 21:48:47 2021 +0800 daily update commit52d6a0ca8fAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Nov 24 23:10:04 2021 +0800 daily update commitf8dd720d4dAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Wed Nov 24 19:08:13 2021 +0800 daily update commitd088c1a862Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 21 21:41:46 2021 +0800 remove useless commita711fcf3edAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Nov 16 00:53:05 2021 +0800 add achievement popup add page adaptive add talent extends commit05e02de3dbAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 13 01:24:04 2021 +0800 add github and discord commitbff0109cc5Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sat Nov 13 00:30:01 2021 +0800 add trajectory auto mode commit54c04f65c2Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Nov 12 19:54:31 2021 +0800 fix property judge negative number bug commit660739530bAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Fri Nov 12 19:48:58 2021 +0800 update achievement commitc94e9e7433Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Thu Nov 11 21:37:45 2021 +0800 update daily commitc06cd9ea62Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Tue Nov 9 00:08:05 2021 +0800 update daily commit2666983f89Author: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 7 23:00:22 2021 +0800 add uiManager auto scan and load skin resource commit22fa5d755aAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Nov 7 22:17:04 2021 +0800 update framework commitf40698d63eAuthor: Vick Scarlet <scarlet_vick@outlook.com> Date: Sun Oct 31 00:13:22 2021 +0800 add laya
1
public/chunk/184.7e968.js
Normal file
1
public/chunk/187.29ba1.js
Normal file
1
public/chunk/202.812b3.js
Normal file
1
public/chunk/285.8fcb6.js
Normal file
1
public/chunk/297.4d69d.js
Normal file
1
public/chunk/33.6a18b.js
Normal file
1
public/chunk/376.c285c.js
Normal file
1
public/chunk/501.338d9.js
Normal file
1
public/chunk/51.b32bb.js
Normal file
1
public/chunk/544.27c17.js
Normal file
1
public/chunk/556.75429.js
Normal file
1
public/chunk/614.cac87.js
Normal file
1
public/chunk/631.5f9d9.js
Normal file
1
public/chunk/764.ade88.js
Normal file
1
public/chunk/803.68263.js
Normal file
1
public/chunk/844.d1970.js
Normal file
1
public/chunk/85.ffdbc.js
Normal file
1
public/chunk/891.20105.js
Normal file
1
public/chunk/897.ce4cf.js
Normal file
1
public/chunk/908.c797b.js
Normal file
1
public/chunk/912.1f149.js
Normal file
1
public/chunk/971.5c09f.js
Normal file
1
public/chunk/main.a3242.js
Normal file
180
public/condition_test.html
Normal file
@@ -0,0 +1,180 @@
|
||||
颜值: <input class="prop" name="CHR" style="width:300px;" value="5" >(CHR)<br/>
|
||||
智力: <input class="prop" name="INT" style="width:300px;" value="5" >(INT)<br/>
|
||||
体质: <input class="prop" name="STR" style="width:300px;" value="5" >(STR)<br/>
|
||||
家境: <input class="prop" name="MNY" style="width:300px;" value="5" >(MNY)<br/>
|
||||
快乐: <input class="prop" name="SPR" style="width:300px;" value="5" >(SPR)<br/>
|
||||
生命: <input class="prop" name="LIF" style="width:300px;" value="5" >(LIF)<br/>
|
||||
天赋: <input class="prop" name="TLT" style="width:300px;" value="[5]" >(TLT)<br/>
|
||||
事件: <input class="prop" name="EVT" style="width:300px;" value="[5]" >(EVT)<br/>
|
||||
<br/><br/>
|
||||
表达式:<input id="conditions" style="width:500px;"><br/><br/>
|
||||
结果:<span id="result" style="color:red;"></span><br/><br/>
|
||||
<button id="submit"> 测 试 </button><br/>
|
||||
|
||||
<script>
|
||||
const DEFAULT_PROP = {
|
||||
CHR: 5, // 颜值 charm CHR
|
||||
INT: 5, // 智力 intelligence INT
|
||||
STR: 5, // 体质 strength STR
|
||||
MNY: 5, // 家境 money MNY
|
||||
SPR: 5, // 快乐 spirit SPR
|
||||
LIF: 5, // 生命 life LIF
|
||||
TLT: [5], // 天赋 talent TLT
|
||||
EVT: [5], // 事件 event EVT
|
||||
};
|
||||
document.querySelector("#submit").onclick = function() {
|
||||
document.querySelectorAll('.prop').forEach(({name, value})=>DEFAULT_PROP[name] = JSON.parse(value));
|
||||
conditions = document.querySelector("#conditions").value;
|
||||
const result = check(conditions);
|
||||
document.querySelector("#result").textContent = result;
|
||||
}
|
||||
|
||||
function getProp(prop) {
|
||||
switch(prop) {
|
||||
case 'CHR':
|
||||
case 'INT':
|
||||
case 'STR':
|
||||
case 'MNY':
|
||||
case 'SPR':
|
||||
case 'LIF':
|
||||
case 'TLT':
|
||||
case 'EVT': return DEFAULT_PROP[prop];
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
function check(condition) {
|
||||
const conditions = parseCondition(condition);
|
||||
return checkParsedCondition(conditions);
|
||||
}
|
||||
|
||||
function checkParsedCondition(conditions) {
|
||||
if(!Array.isArray(conditions)) return checkLogic(conditions);
|
||||
if(conditions.length == 0) return true;
|
||||
if(conditions.length == 1) return checkParsedCondition(conditions[0]);
|
||||
|
||||
let ret = checkParsedCondition(conditions[0]);
|
||||
for(let i=1; i<conditions.length; i+=2) {
|
||||
switch(conditions[i]) {
|
||||
case '&':
|
||||
if(ret) ret = checkParsedCondition(conditions[i+1]);
|
||||
break;
|
||||
case '|':
|
||||
if(ret) return true;
|
||||
ret = checkParsedCondition(conditions[i+1]);
|
||||
break;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
function checkLogic(condition) {
|
||||
const length = condition.length;
|
||||
let i = condition.search(/[><\!\?=]/);
|
||||
|
||||
const prop = condition.substring(0,i);
|
||||
const symbol = condition.substring(i, i+=(condition[i+1]=='='?2:1));
|
||||
const d = condition.substring(i, length);
|
||||
|
||||
const propData = getProp(prop);
|
||||
const conditionData = d[0]=='['? JSON.parse(d): Number(d);
|
||||
|
||||
switch(symbol) {
|
||||
case '>': return propData > conditionData;
|
||||
case '<': return propData < conditionData;
|
||||
case '>=': return propData >= conditionData;
|
||||
case '<=': return propData <= conditionData;
|
||||
case '=':
|
||||
if(Array.isArray(propData))
|
||||
return propData.includes(conditionData);
|
||||
return propData == conditionData;
|
||||
case '!=':
|
||||
if(Array.isArray(propData))
|
||||
return !propData.includes(conditionData);
|
||||
return propData == conditionData;
|
||||
case '?':
|
||||
if(Array.isArray(propData)) {
|
||||
for(const p of propData)
|
||||
if(conditionData.includes(p)) return true;
|
||||
return false;
|
||||
}
|
||||
return conditionData.includes(propData);
|
||||
case '!':
|
||||
if(Array.isArray(propData)) {
|
||||
for(const p of propData)
|
||||
if(conditionData.includes(p)) return false;
|
||||
return true;
|
||||
}
|
||||
return !conditionData.includes(propData);
|
||||
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
function parseCondition(condition) {
|
||||
const conditions = [];
|
||||
const length = condition.length;
|
||||
const stack = [];
|
||||
stack.unshift(conditions);
|
||||
let cursor = 0;
|
||||
const catchString = i => {
|
||||
const str = condition.substring(cursor, i).trim();
|
||||
cursor = i;
|
||||
if(str) stack[0].push(str);
|
||||
};
|
||||
|
||||
for(let i=0; i<length; i++) {
|
||||
switch(condition[i]) {
|
||||
case ' ': continue;
|
||||
|
||||
case '(':
|
||||
catchString(i);
|
||||
cursor ++;
|
||||
const sub = [];
|
||||
stack[0].push(sub);
|
||||
stack.unshift(sub);
|
||||
break;
|
||||
|
||||
case ')':
|
||||
catchString(i);
|
||||
cursor ++;
|
||||
stack.shift();
|
||||
break;
|
||||
|
||||
case '|':
|
||||
case '&':
|
||||
catchString(i);
|
||||
catchString(i+1);
|
||||
break;
|
||||
default: continue;
|
||||
}
|
||||
}
|
||||
|
||||
catchString(length);
|
||||
|
||||
return conditions;
|
||||
}
|
||||
|
||||
// function debug(...conditions) {
|
||||
// for(const condition of conditions)
|
||||
// console.debug(check(condition), '\t', condition);
|
||||
// }
|
||||
//
|
||||
// debug(
|
||||
// '(STR<2&MNY>3)|(MNY<2&CHR<2)',
|
||||
// '(STR<2&MNY>3)',
|
||||
// '(STR>2&MNY>3)',
|
||||
// '((((STR>2&MNY>2))))',
|
||||
// '((((STR>2&MNY>2)|(MNY<2&CHR<2))))',
|
||||
// '((((STR>2&MNY>2)|(MNY<2&CHR<2)&(STR>2&MNY>3))))',
|
||||
// '((((STR>2&MNY>2)|(MNY<2&CHR<2))&(STR>2&MNY>3)))',
|
||||
// 'EVT![1,2,3]',
|
||||
// 'EVT![1,2]',
|
||||
// 'EVT?[1,2,3]',
|
||||
// 'EVT?[1,2]',
|
||||
// );
|
||||
</script>
|
||||
|
||||
|
||||
1460
public/data/en-us/achievement.json
Normal file
71816
public/data/en-us/age.json
Normal file
13145
public/data/en-us/events.json
Normal file
1335
public/data/en-us/talents.json
Normal file
4347
public/data/specialthanks.json
Normal file
1460
public/data/zh-cn/achievement.json
Normal file
71808
public/data/zh-cn/age.json
Normal file
13145
public/data/zh-cn/events.json
Normal file
1335
public/data/zh-cn/talents.json
Normal file
74
public/dev.html
Normal file
@@ -0,0 +1,74 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
|
||||
<meta name="description" content="やり直すんだ。そして、次はうまくやる。"/>
|
||||
<meta name="keywords" content="人生重开模拟器 liferestart life restart remake 人生重来"/>
|
||||
<meta name="renderer" content="webkit"/>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
||||
<meta name="full-screen" content="true"/>
|
||||
<meta name="x5-fullscreen" content="true"/>
|
||||
<meta name="360-fullscreen" content="true"/>
|
||||
<meta name="theme-color" content="#157878"/>
|
||||
<meta name="laya" screenorientation ="landscape"/>
|
||||
<meta http-equiv="expires" content="0"/>
|
||||
<meta http-equiv="Cache-Control" content="no-siteapp"/>
|
||||
<font-face font-family="方正像素12" src="fonts/方正像素12.ttf"/>
|
||||
<title>Life Restart</title>
|
||||
</head>
|
||||
<body style="background:black">
|
||||
<!--以下引用了常用类库,如果不使用,可以删除-->
|
||||
|
||||
<!--核心包,封装了显示对象渲染,事件,时间管理,时间轴动画,缓动,消息交互,socket,本地存储,鼠标触摸,声音,加载,颜色滤镜,位图字体等-->
|
||||
<script type="text/javascript" src="libs/laya/laya.core.js"></script>
|
||||
<!--提供了微信小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.wxmini.js"></script> -->
|
||||
<!--提供了百度小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.bdmini.js"></script> -->
|
||||
<!--提供了小米小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.xmmini.js"></script> -->
|
||||
<!--提供了OPPO小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.quickgamemini.js"></script> -->
|
||||
<!--提供了bilibili小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.bilimini.js"></script> -->
|
||||
<!--提供了Alipay小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.Alipaymini.js"></script> -->
|
||||
<!--提供了qq小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.qqmini.js"></script> -->
|
||||
<!--提供了字节跳动小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.ttmini.js"></script> -->
|
||||
<!--提供了华为快游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.hwmini.js"></script> -->
|
||||
<!--提供了淘宝商家应用的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.tbmini.js"></script> -->
|
||||
<!--提供了淘宝小部件的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.tbplugin.js"></script> -->
|
||||
<!--封装了webgl渲染管线,如果使用webgl渲染,可以在初始化时调用Laya.init(1000,800,laya.webgl.WebGL);-->
|
||||
<script type="text/javascript" src="libs/laya/laya.webgl.js"></script>
|
||||
<!--提供了VIVO小游戏的适配-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.vvmini.js"></script> -->
|
||||
<!--是动画模块,包含了swf动画,骨骼动画等-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.ani.js"></script> -->
|
||||
<!--包含更多webgl滤镜,比如外发光,阴影,模糊以及更多-->
|
||||
<script type="text/javascript" src="libs/laya/laya.filter.js"></script>
|
||||
<!--封装了html动态排版功能-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.html.js"></script> -->
|
||||
<!--粒子类库-->
|
||||
<script type="text/javascript" src="libs/laya/laya.particle.js"></script>
|
||||
<!--提供tileMap解析支持-->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.tiledmap.js"></script> -->
|
||||
<!--提供了制作UI的各种组件实现-->
|
||||
<script type="text/javascript" src="libs/laya/laya.ui.js"></script>
|
||||
<!-- 提供LayaAir3d接口 -->
|
||||
<!-- <script type="text/javascript" src="libs/laya/laya.d3.js"></script> -->
|
||||
|
||||
<!-- 物理引擎matter.js -->
|
||||
<!--自定义的js(src文件夹下)文件自动添加到下面jsfile模块标签里面里,js的顺序可以手动修改,修改后保留修改的顺序,新增加的js会默认依次追加到标签里-->
|
||||
<!--删除标签,ide不会自动添加js文件,请谨慎操作-->
|
||||
<!--jsfile--startTag-->
|
||||
<script type="module" src="../src/index.js"></script>
|
||||
<!--jsfile--endTag-->
|
||||
</body>
|
||||
</html>
|
||||
BIN
public/fonts/方正像素12.ttf
Normal file
BIN
public/images/accessories/insert_coin@3x.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
public/images/accessories/title@3x.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
public/images/accessories/title_neon@3x.png
Normal file
|
After Width: | Height: | Size: 99 KiB |
BIN
public/images/accessories/titlebar@3x.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
69
public/images/atlas/.rec
Normal file
@@ -0,0 +1,69 @@
|
||||
D .
|
||||
D fonts
|
||||
R 39B4F491 方正像素12.ttf
|
||||
D images
|
||||
D images/accessories
|
||||
P ADDDCB66 cardicon@3x.png
|
||||
R 0E2F6E7F insert_coin@3x.png
|
||||
R B45325FC title@3x.png
|
||||
P 074FEF52 title_left@3x.png
|
||||
R 97E72B92 title_neon@3x.png
|
||||
P 2BA0101A title_right@3x.png
|
||||
R E1602E15 titlebar@3x.png
|
||||
D images/background
|
||||
R 9343F3BB background_1@3x.png
|
||||
R 0B49B27D background_2@3x.png
|
||||
D images/border
|
||||
P A2B33396 achievement@3x.png
|
||||
R 45A1A604 achievement_complete@3x.png
|
||||
R 6CF3EE8E border_1@3x.png
|
||||
R AAEA6308 border_2@3x.png
|
||||
R A57A026E card@3x.png
|
||||
P C1EDDBED property@3x.png
|
||||
R A8C7A5A5 talent_item@3x.png
|
||||
R DCE4E73A talent_item_selected@3x.png
|
||||
R 373CDF45 up@3x.png
|
||||
D images/button
|
||||
P 69FF5572 button_back@3x.png
|
||||
R 441BFE78 button_main@3x.png
|
||||
P F2B85B54 button_small@3x.png
|
||||
D images/icons
|
||||
P C677F3AE icon_achievement@3x.png
|
||||
P 3D072134 icon_chr@3x.png
|
||||
P C663FAF5 icon_discord.png
|
||||
P 3FA91C13 icon_github.png
|
||||
P AB934AEA icon_int@3x.png
|
||||
P F1A0724B icon_mny@3x.png
|
||||
P D5AADAC9 icon_rank@3x.png
|
||||
P 0806E5F3 icon_save.png
|
||||
P 2DB0325D icon_spr@3x.png
|
||||
P 2EFA541B icon_str@3x.png
|
||||
P 804842C9 icon_thanks@3x.png
|
||||
P 96DD5D94 icon_themes.png
|
||||
P 6ECB5FEC icon_up@3x.png
|
||||
D images/progress
|
||||
P E2BF0C93 progress_1@3x$bar.png
|
||||
P B86E1D0F progress_1@3x.png
|
||||
P E7F15BA7 progress_2$bar.png
|
||||
P 641A22BF progress_2.png
|
||||
P AF80A9AF progress_s$bar.png
|
||||
P 41417E8D progress_s.png
|
||||
D images/radio
|
||||
P CCF63014 radio_cyber.png
|
||||
P 040DE73C radio_dark.png
|
||||
P BA975F5A radio_light.png
|
||||
D images/resource
|
||||
P F3659301 bottombreath.png
|
||||
P 496D6FB9 circle.png
|
||||
P B5087365 circleflash.png
|
||||
D images/slider
|
||||
P 9682C590 hslider_s$bar.png
|
||||
P F6238BD4 hslider_s$down.png
|
||||
P F4198287 hslider_s$up.png
|
||||
P 2A785866 hslider_s.png
|
||||
R 8B95E6D3 vslider_1@3x$bar.png
|
||||
P 6581FBA8 vslider_1@3x$down.png
|
||||
P 6581FBA8 vslider_1@3x$up.png
|
||||
R C9587878 vslider_1@3x.png
|
||||
D images/texture
|
||||
P FD231754 texture_1.png
|
||||
1
public/images/atlas/images/accessories.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"cardicon@3x.png":{"frame":{"h":466,"idx":0,"w":455,"x":0,"y":0},"sourceSize":{"h":466,"w":455},"spriteSourceSize":{"x":0,"y":0}},"title_left@3x.png":{"frame":{"h":27,"idx":0,"w":48,"x":456,"y":0},"sourceSize":{"h":27,"w":48},"spriteSourceSize":{"x":0,"y":0}},"title_right@3x.png":{"frame":{"h":27,"idx":0,"w":48,"x":456,"y":28},"sourceSize":{"h":27,"w":48},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"accessories.png","prefix":"images/accessories/"}}
|
||||
BIN
public/images/atlas/images/accessories.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
1
public/images/atlas/images/border.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"achievement@3x.png":{"frame":{"h":412,"idx":0,"w":486,"x":0,"y":0},"sourceSize":{"h":412,"w":486},"spriteSourceSize":{"x":0,"y":0}},"property@3x.png":{"frame":{"h":84,"idx":0,"w":257,"x":0,"y":413},"sourceSize":{"h":84,"w":257},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"border.png","prefix":"images/border/"}}
|
||||
BIN
public/images/atlas/images/border.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
1
public/images/atlas/images/button.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"button_back@3x.png":{"frame":{"h":114,"idx":0,"w":147,"x":0,"y":91},"sourceSize":{"h":114,"w":147},"spriteSourceSize":{"x":0,"y":0}},"button_small@3x.png":{"frame":{"h":90,"idx":0,"w":225,"x":0,"y":0},"sourceSize":{"h":90,"w":225},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"button.png","prefix":"images/button/"}}
|
||||
BIN
public/images/atlas/images/button.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
1
public/images/atlas/images/icons.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"icon_achievement@3x.png":{"frame":{"h":69,"idx":0,"w":65,"x":188,"y":385},"sourceSize":{"h":69,"w":65},"spriteSourceSize":{"x":0,"y":0}},"icon_chr@3x.png":{"frame":{"h":61,"idx":0,"w":57,"x":320,"y":448},"sourceSize":{"h":61,"w":57},"spriteSourceSize":{"x":0,"y":0}},"icon_discord.png":{"frame":{"h":384,"idx":0,"w":384,"x":0,"y":0},"sourceSize":{"h":384,"w":384},"spriteSourceSize":{"x":0,"y":0}},"icon_github.png":{"frame":{"h":384,"idx":0,"w":384,"x":385,"y":0},"sourceSize":{"h":384,"w":384},"spriteSourceSize":{"x":0,"y":0}},"icon_int@3x.png":{"frame":{"h":57,"idx":0,"w":54,"x":188,"y":455},"sourceSize":{"h":57,"w":54},"spriteSourceSize":{"x":0,"y":0}},"icon_mny@3x.png":{"frame":{"h":57,"idx":0,"w":54,"x":243,"y":455},"sourceSize":{"h":57,"w":54},"spriteSourceSize":{"x":0,"y":0}},"icon_rank@3x.png":{"frame":{"h":62,"idx":0,"w":72,"x":320,"y":385},"sourceSize":{"h":62,"w":72},"spriteSourceSize":{"x":0,"y":0}},"icon_save.png":{"frame":{"h":90,"idx":0,"w":90,"x":97,"y":385},"sourceSize":{"h":90,"w":90},"spriteSourceSize":{"x":0,"y":0}},"icon_spr@3x.png":{"frame":{"h":60,"idx":0,"w":57,"x":378,"y":448},"sourceSize":{"h":60,"w":57},"spriteSourceSize":{"x":0,"y":0}},"icon_str@3x.png":{"frame":{"h":57,"idx":0,"w":54,"x":393,"y":385},"sourceSize":{"h":57,"w":54},"spriteSourceSize":{"x":0,"y":0}},"icon_thanks@3x.png":{"frame":{"h":69,"idx":0,"w":65,"x":254,"y":385},"sourceSize":{"h":69,"w":65},"spriteSourceSize":{"x":0,"y":0}},"icon_themes.png":{"frame":{"h":96,"idx":0,"w":96,"x":0,"y":385},"sourceSize":{"h":96,"w":96},"spriteSourceSize":{"x":0,"y":0}},"icon_up@3x.png":{"frame":{"h":18,"idx":0,"w":33,"x":97,"y":476},"sourceSize":{"h":18,"w":33},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"icons.png","prefix":"images/icons/"}}
|
||||
BIN
public/images/atlas/images/icons.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
1
public/images/atlas/images/progress.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"progress_1@3x$bar.png":{"frame":{"h":36,"idx":0,"w":203,"x":0,"y":262},"sourceSize":{"h":36,"w":203},"spriteSourceSize":{"x":0,"y":0}},"progress_1@3x.png":{"frame":{"h":36,"idx":0,"w":203,"x":204,"y":262},"sourceSize":{"h":36,"w":203},"spriteSourceSize":{"x":0,"y":0}},"progress_2$bar.png":{"frame":{"h":200,"idx":0,"w":200,"x":0,"y":0},"sourceSize":{"h":200,"w":200},"spriteSourceSize":{"x":0,"y":0}},"progress_2.png":{"frame":{"h":200,"idx":0,"w":200,"x":201,"y":0},"sourceSize":{"h":200,"w":200},"spriteSourceSize":{"x":0,"y":0}},"progress_s$bar.png":{"frame":{"h":60,"idx":0,"w":226,"x":0,"y":201},"sourceSize":{"h":60,"w":226},"spriteSourceSize":{"x":0,"y":0}},"progress_s.png":{"frame":{"h":60,"idx":0,"w":226,"x":227,"y":201},"sourceSize":{"h":60,"w":226},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"progress.png","prefix":"images/progress/"}}
|
||||
BIN
public/images/atlas/images/progress.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
1
public/images/atlas/images/radio.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"radio_cyber.png":{"frame":{"h":300,"idx":0,"w":300,"x":0,"y":0},"sourceSize":{"h":300,"w":300},"spriteSourceSize":{"x":0,"y":0}},"radio_dark.png":{"frame":{"h":300,"idx":0,"w":300,"x":0,"y":301},"sourceSize":{"h":300,"w":300},"spriteSourceSize":{"x":0,"y":0}},"radio_light.png":{"frame":{"h":300,"idx":0,"w":300,"x":301,"y":0},"sourceSize":{"h":300,"w":300},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"radio.png","prefix":"images/radio/"}}
|
||||
BIN
public/images/atlas/images/radio.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
1
public/images/atlas/images/resource.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"bottombreath.png":{"frame":{"h":200,"idx":0,"w":200,"x":0,"y":0},"sourceSize":{"h":200,"w":200},"spriteSourceSize":{"x":0,"y":0}},"circle.png":{"frame":{"h":200,"idx":0,"w":200,"x":0,"y":201},"sourceSize":{"h":200,"w":200},"spriteSourceSize":{"x":0,"y":0}},"circleflash.png":{"frame":{"h":200,"idx":0,"w":200,"x":201,"y":0},"sourceSize":{"h":200,"w":200},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"resource.png","prefix":"images/resource/"}}
|
||||
BIN
public/images/atlas/images/resource.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
1
public/images/atlas/images/slider.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"hslider_s$bar.png":{"frame":{"h":180,"idx":0,"w":47,"x":0,"y":61},"sourceSize":{"h":180,"w":47},"spriteSourceSize":{"x":0,"y":0}},"hslider_s$down.png":{"frame":{"h":1,"idx":0,"w":1,"x":0,"y":242},"sourceSize":{"h":1,"w":1},"spriteSourceSize":{"x":0,"y":0}},"hslider_s$up.png":{"frame":{"h":1,"idx":0,"w":1,"x":0,"y":244},"sourceSize":{"h":1,"w":1},"spriteSourceSize":{"x":0,"y":0}},"hslider_s.png":{"frame":{"h":60,"idx":0,"w":226,"x":0,"y":0},"sourceSize":{"h":60,"w":226},"spriteSourceSize":{"x":0,"y":0}},"vslider_1@3x$down.png":{"frame":{"h":1,"idx":0,"w":1,"x":0,"y":246},"sourceSize":{"h":1,"w":1},"spriteSourceSize":{"x":0,"y":0}},"vslider_1@3x$up.png":{"frame":{"h":1,"idx":0,"w":1,"x":0,"y":248},"sourceSize":{"h":1,"w":1},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"slider.png","prefix":"images/slider/"}}
|
||||
BIN
public/images/atlas/images/slider.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
1
public/images/atlas/images/texture.atlas
Normal file
@@ -0,0 +1 @@
|
||||
{"frames":{"texture_1.png":{"frame":{"h":400,"idx":0,"w":400,"x":0,"y":0},"sourceSize":{"h":400,"w":400},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"texture.png","prefix":"images/texture/"}}
|
||||
BIN
public/images/atlas/images/texture.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
public/images/background/background_1@3x.png
Normal file
|
After Width: | Height: | Size: 426 KiB |
BIN
public/images/background/background_2@3x.png
Normal file
|
After Width: | Height: | Size: 502 KiB |
BIN
public/images/border/achievement_complete@3x.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
public/images/border/border_1@3x.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
public/images/border/border_2@3x.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
public/images/border/card@3x.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
public/images/border/talent_item@3x.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
public/images/border/talent_item_selected@3x.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
public/images/border/up@3x.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
public/images/button/button_main@3x.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
public/images/icons/icon-128x128.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
public/images/icons/icon-144x144.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
public/images/icons/icon-152x152.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
public/images/icons/icon-192x192.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
public/images/icons/icon-384x384.png
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
public/images/icons/icon-512x512.png
Normal file
|
After Width: | Height: | Size: 114 KiB |
BIN
public/images/icons/icon-72x72.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
public/images/icons/icon-96x96.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
public/images/slider/vslider_1@3x$bar.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
public/images/slider/vslider_1@3x.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
public/images/texture/texture_1.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
1
public/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"><meta name="description" content="やり直すんだ。そして、次はうまくやる。"/><meta name="keywords" content="人生重开模拟器 liferestart life restart remake 人生重来"/><meta name="renderer" content="webkit"/><meta name="apple-mobile-web-app-capable" content="yes"/><meta name="full-screen" content="true"/><meta name="x5-fullscreen" content="true"/><meta name="360-fullscreen" content="true"/><meta name="theme-color" content="#157878"/><meta name="laya" screenorientation="landscape"/><meta http-equiv="expires" content="0"/><meta http-equiv="Cache-Control" content="no-siteapp"/><title>Life Restart</title><script src="libs/laya/min/laya.core.min.js"></script><script src="libs/laya/min/laya.webgl.min.js"></script><script src="libs/laya/min/laya.filter.min.js"></script><script src="libs/laya/min/laya.particle.min.js"></script><script src="libs/laya/min/laya.ui.min.js"></script><script defer="defer" src="chunk/main.a3242.js"></script></head><body style="background:black"></body></html>
|
||||
425
public/libs/laya/LayaRender.js
Normal file
@@ -0,0 +1,425 @@
|
||||
/**
|
||||
* Matter.js 渲染器在 LayaAir 的实现。
|
||||
*/
|
||||
(function()
|
||||
{
|
||||
var LayaRender = {};
|
||||
|
||||
var Common = Matter.Common;
|
||||
var Composite = Matter.Composite;
|
||||
var Bounds = Matter.Bounds;
|
||||
var Events = Matter.Events;
|
||||
var Grid = Matter.Grid;
|
||||
var Vector = Matter.Vector;
|
||||
|
||||
/**
|
||||
* 创建新的渲染器。
|
||||
* @param {object} options 所有属性都有默认值,options中的属性会覆盖默认属性。
|
||||
* @return {render} 返回创建的旋绕器
|
||||
*/
|
||||
LayaRender.create = function(options)
|
||||
{
|
||||
var defaults = {
|
||||
controller: LayaRender,
|
||||
engine: null,
|
||||
element: null,
|
||||
canvas: null,
|
||||
mouse: null,
|
||||
frameRequestId: null,
|
||||
options:
|
||||
{
|
||||
width: 800,
|
||||
height: 600,
|
||||
pixelRatio: 1,
|
||||
background: '#fafafa',
|
||||
wireframeBackground: '#222222',
|
||||
hasBounds: !!options.bounds,
|
||||
enabled: true,
|
||||
wireframes: true,
|
||||
showSleeping: true,
|
||||
showDebug: false,
|
||||
showBroadphase: false,
|
||||
showBounds: false,
|
||||
showVelocity: false,
|
||||
showCollisions: false,
|
||||
showSeparations: false,
|
||||
showAxes: false,
|
||||
showPositions: false,
|
||||
showAngleIndicator: false,
|
||||
showIds: false,
|
||||
showShadows: false,
|
||||
showVertexNumbers: false,
|
||||
showConvexHulls: false,
|
||||
showInternalEdges: false,
|
||||
showMousePosition: false
|
||||
}
|
||||
};
|
||||
var render = Common.extend(defaults, options);
|
||||
render.mouse = options.mouse;
|
||||
render.engine = options.engine;
|
||||
// 如果用户没有指定contaienr,默认使用stage
|
||||
render.container = render.container || Laya.stage;
|
||||
render.bounds = render.bounds ||
|
||||
{
|
||||
min:
|
||||
{
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
max:
|
||||
{
|
||||
x: render.width,
|
||||
y: render.height
|
||||
}
|
||||
};
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行渲染器。
|
||||
* @param {render} render 渲染的目标是LayaRender.create()返回的对象
|
||||
* @return {void}
|
||||
*/
|
||||
LayaRender.run = function(render)
|
||||
{
|
||||
Laya.timer.frameLoop(1, this, LayaRender.world, [render]);
|
||||
Events.on(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite);
|
||||
};
|
||||
|
||||
/**
|
||||
* 停止渲染器。
|
||||
* @param {render} LayaRender.create()返回的对象
|
||||
* @return {void}
|
||||
*/
|
||||
LayaRender.stop = function(render)
|
||||
{
|
||||
Laya.timer.clear(this, LayaRender.world);
|
||||
Events.off(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite);
|
||||
}
|
||||
|
||||
LayaRender.onRemoveSprite = function(args)
|
||||
{
|
||||
var sprite = args.object.layaSprite;
|
||||
if (sprite && sprite.parent)
|
||||
sprite.parent.removeChild(sprite);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染给定的 engine 的 Matter.World 对象。
|
||||
* 这是渲染的入口,每次场景改变时都应该被调用。
|
||||
* @param {render} render
|
||||
* @return {void}
|
||||
*/
|
||||
LayaRender.world = function(render)
|
||||
{
|
||||
var engine = render.engine,
|
||||
world = engine.world,
|
||||
renderer = render.renderer,
|
||||
container = render.container,
|
||||
options = render.options,
|
||||
bodies = Composite.allBodies(world),
|
||||
allConstraints = Composite.allConstraints(world),
|
||||
constraints = [],
|
||||
i;
|
||||
|
||||
if (options.wireframes)
|
||||
{
|
||||
LayaRender.setBackground(render, options.wireframeBackground);
|
||||
}
|
||||
else
|
||||
{
|
||||
LayaRender.setBackground(render, options.background);
|
||||
}
|
||||
|
||||
// 处理 bounds
|
||||
var boundsWidth = render.bounds.max.x - render.bounds.min.x,
|
||||
boundsHeight = render.bounds.max.y - render.bounds.min.y,
|
||||
boundsScaleX = boundsWidth / render.options.width,
|
||||
boundsScaleY = boundsHeight / render.options.height;
|
||||
|
||||
if (options.hasBounds)
|
||||
{
|
||||
// 隐藏不在视口内的bodies
|
||||
for (i = 0; i < bodies.length; i++)
|
||||
{
|
||||
var body = bodies[i];
|
||||
body.render.sprite.visible = Bounds.overlaps(body.bounds, render.bounds);
|
||||
}
|
||||
|
||||
// 过滤掉不在视口内的 constraints
|
||||
for (i = 0; i < allConstraints.length; i++)
|
||||
{
|
||||
var constraint = allConstraints[i],
|
||||
bodyA = constraint.bodyA,
|
||||
bodyB = constraint.bodyB,
|
||||
pointAWorld = constraint.pointA,
|
||||
pointBWorld = constraint.pointB;
|
||||
|
||||
if (bodyA) pointAWorld = Vector.add(bodyA.position, constraint.pointA);
|
||||
if (bodyB) pointBWorld = Vector.add(bodyB.position, constraint.pointB);
|
||||
|
||||
if (!pointAWorld || !pointBWorld)
|
||||
continue;
|
||||
|
||||
if (Bounds.contains(render.bounds, pointAWorld) || Bounds.contains(render.bounds, pointBWorld))
|
||||
constraints.push(constraint);
|
||||
}
|
||||
|
||||
// 改变视口
|
||||
container.scale(1 / boundsScaleX, 1 / boundsScaleY);
|
||||
container.pos(-render.bounds.min.x * (1 / boundsScaleX), -render.bounds.min.y * (1 / boundsScaleY));
|
||||
}
|
||||
else
|
||||
{
|
||||
constraints = allConstraints;
|
||||
}
|
||||
|
||||
for (i = 0; i < bodies.length; i++)
|
||||
LayaRender.body(render, bodies[i]);
|
||||
|
||||
for (i = 0; i < constraints.length; i++)
|
||||
LayaRender.constraint(render, constraints[i]);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置背景色或者背景图片。
|
||||
* @param {render} render
|
||||
* @param {string} background 16进制颜色字符串或者图片路径
|
||||
*/
|
||||
LayaRender.setBackground = function(render, background)
|
||||
{
|
||||
if (render.currentBackground !== background)
|
||||
{
|
||||
var isColor = background.indexOf && background.indexOf('#') !== -1;
|
||||
|
||||
render.container.graphics.clear();
|
||||
|
||||
if (isColor)
|
||||
{
|
||||
// 使用纯色背景
|
||||
render.container.bgColor = background;
|
||||
}
|
||||
else
|
||||
{
|
||||
render.container.loadImage(background);
|
||||
// 使用背景图片时把背景色设置为白色
|
||||
render.container.bgColor = "#FFFFFF";
|
||||
}
|
||||
|
||||
render.currentBackground = background;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染 body
|
||||
* @param {render} render
|
||||
* @param {body} body
|
||||
* @return {void}
|
||||
*/
|
||||
LayaRender.body = function(render, body)
|
||||
{
|
||||
var engine = render.engine,
|
||||
bodyRender = body.render;
|
||||
|
||||
if (!bodyRender.visible)
|
||||
return;
|
||||
|
||||
// 有纹理的body
|
||||
if (bodyRender.sprite && bodyRender.sprite.texture)
|
||||
{
|
||||
var spriteId = 'b-' + body.id,
|
||||
sprite = body.layaSprite,
|
||||
container = render.container;
|
||||
|
||||
// 如果sprite不存在,则初始化一个
|
||||
if (!sprite)
|
||||
sprite = body.layaSprite = _createBodySprite(render, body);
|
||||
|
||||
// 如果sprite未在显示列表,则添加至显示列表
|
||||
if (!container.contains(sprite))
|
||||
container.addChild(sprite);
|
||||
|
||||
// 更新sprite位置
|
||||
sprite.x = body.position.x;
|
||||
sprite.y = body.position.y;
|
||||
sprite.rotation = body.angle * 180 / Math.PI;
|
||||
sprite.scaleX = bodyRender.sprite.xScale || 1;
|
||||
sprite.scaleY = bodyRender.sprite.yScale || 1;
|
||||
}
|
||||
else // 没有纹理的body
|
||||
{
|
||||
var primitiveId = 'b-' + body.id,
|
||||
sprite = body.layaSprite,
|
||||
container = render.container;
|
||||
|
||||
// 如果sprite不存在,则初始化一个
|
||||
if (!sprite)
|
||||
{
|
||||
sprite = body.layaSprite = _createBodyPrimitive(render, body);
|
||||
sprite.initialAngle = body.angle;
|
||||
}
|
||||
|
||||
// 如果sprite未在显示列表,则添加至显示列表
|
||||
if (!container.contains(sprite))
|
||||
container.addChild(sprite);
|
||||
// 更新sprite位置
|
||||
sprite.x = body.position.x;
|
||||
sprite.y = body.position.y;
|
||||
sprite.rotation = (body.angle - sprite.initialAngle) * 180 / Math.PI;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建使用纹理的Sprite对象。
|
||||
* @param {render} render
|
||||
* @param {body} body
|
||||
* @return {void}
|
||||
*/
|
||||
var _createBodySprite = function(render, body)
|
||||
{
|
||||
var bodyRender = body.render,
|
||||
texturePath = bodyRender.sprite.texture,
|
||||
sprite = new Laya.Sprite();
|
||||
|
||||
sprite.loadImage(texturePath);
|
||||
sprite.pivotX = body.render.sprite.xOffset;
|
||||
sprite.pivotY = body.render.sprite.yOffset;
|
||||
|
||||
return sprite;
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建使用矢量绘图的Sprite对象。
|
||||
* @param {render} render
|
||||
* @param {body} body
|
||||
* @return {void}
|
||||
*/
|
||||
var _createBodyPrimitive = function(render, body)
|
||||
{
|
||||
var bodyRender = body.render,
|
||||
options = render.options,
|
||||
sprite = new Laya.Sprite(),
|
||||
fillStyle, strokeStyle, lineWidth,
|
||||
part, points = [];
|
||||
|
||||
var primitive = sprite.graphics;
|
||||
primitive.clear();
|
||||
|
||||
// 处理 compound parts
|
||||
for (var k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++)
|
||||
{
|
||||
part = body.parts[k];
|
||||
|
||||
if (!options.wireframes)
|
||||
{
|
||||
fillStyle = bodyRender.fillStyle;
|
||||
strokeStyle = bodyRender.strokeStyle;
|
||||
lineWidth = bodyRender.lineWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
fillStyle = null;
|
||||
strokeStyle = '#bbbbbb';
|
||||
lineWidth = 1;
|
||||
}
|
||||
|
||||
points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y);
|
||||
|
||||
for (var j = 1; j < part.vertices.length; j++)
|
||||
{
|
||||
points.push(part.vertices[j].x - body.position.x, part.vertices[j].y - body.position.y);
|
||||
}
|
||||
|
||||
points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y);
|
||||
|
||||
primitive.drawPoly(0, 0, points, fillStyle, strokeStyle, lineWidth);
|
||||
|
||||
// 角度指示器
|
||||
if (options.showAngleIndicator || options.showAxes)
|
||||
{
|
||||
lineWidth = 1;
|
||||
if (options.wireframes)
|
||||
{
|
||||
strokeStyle = '#CD5C5C';
|
||||
}
|
||||
else
|
||||
{
|
||||
strokeStyle = bodyRender.strokeStyle;
|
||||
}
|
||||
|
||||
primitive.drawLine(part.position.x - body.position.x, part.position.y - body.position.y,
|
||||
((part.vertices[0].x + part.vertices[part.vertices.length - 1].x) / 2 - body.position.x),
|
||||
((part.vertices[0].y + part.vertices[part.vertices.length - 1].y) / 2 - body.position.y));
|
||||
}
|
||||
}
|
||||
|
||||
return sprite;
|
||||
};
|
||||
|
||||
/**
|
||||
* 绘制 constraint。
|
||||
* @param {render} render
|
||||
* @param {constraint} constraint
|
||||
* @return {void}
|
||||
*/
|
||||
LayaRender.constraint = function(render, constraint)
|
||||
{
|
||||
var engine = render.engine,
|
||||
bodyA = constraint.bodyA,
|
||||
bodyB = constraint.bodyB,
|
||||
pointA = constraint.pointA,
|
||||
pointB = constraint.pointB,
|
||||
container = render.container,
|
||||
constraintRender = constraint.render,
|
||||
primitiveId = 'c-' + constraint.id,
|
||||
sprite = constraint.layaSprite;
|
||||
|
||||
// 如果sprite不存在,则初始化一个
|
||||
if (!sprite)
|
||||
sprite = constraint.layaSprite = new Laya.Sprite();
|
||||
|
||||
var primitive = sprite.graphics;
|
||||
|
||||
// constraint 没有两个终点时不渲染
|
||||
if (!constraintRender.visible || !constraint.pointA || !constraint.pointB)
|
||||
{
|
||||
primitive.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果sprite未在显示列表,则添加至显示列表
|
||||
if (!container.contains(sprite))
|
||||
container.addChild(sprite);
|
||||
|
||||
// 渲染 constraint
|
||||
primitive.clear();
|
||||
|
||||
var fromX, fromY, toX, toY;
|
||||
if (bodyA)
|
||||
{
|
||||
fromX = bodyA.position.x + pointA.x;
|
||||
fromY = bodyA.position.y + pointA.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
fromX = pointA.x;
|
||||
fromY = pointA.y;
|
||||
}
|
||||
|
||||
if (bodyB)
|
||||
{
|
||||
toX = bodyB.position.x + pointB.x;
|
||||
toY = bodyB.position.y + pointB.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
toX = pointB.x;
|
||||
toY = pointB.y;
|
||||
}
|
||||
|
||||
primitive.drawLine(fromX, fromY, toX, toY, constraintRender.strokeStyle, constraintRender.lineWidth);
|
||||
};
|
||||
|
||||
window.LayaRender = LayaRender;
|
||||
})();
|
||||
3746
public/libs/laya/bytebuffer.js
Normal file
2357
public/libs/laya/domparserinone.js
Normal file
1904
public/libs/laya/laya.Alipaymini.js
Normal file
6137
public/libs/laya/laya.ani.js
Normal file
1538
public/libs/laya/laya.bdmini.js
Normal file
1909
public/libs/laya/laya.bilimini.js
Normal file
21377
public/libs/laya/laya.core.js
Normal file
45496
public/libs/laya/laya.d3.js
Normal file
117
public/libs/laya/laya.d3Plugin.js
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
(function(window,document,Laya){
|
||||
var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
|
||||
|
||||
var Component3D=laya.d3.component.Component3D,ComponentNode=laya.d3.core.ComponentNode,MeshTerrainSprite3D=laya.d3.core.MeshTerrainSprite3D;
|
||||
var Sprite3D=laya.d3.core.Sprite3D;
|
||||
/**
|
||||
*<code>PathFinding</code> 类用于创建寻路。
|
||||
*/
|
||||
//class laya.d3.component.PathFind extends laya.d3.component.Component3D
|
||||
var PathFind=(function(_super){
|
||||
function PathFind(){
|
||||
/**@private */
|
||||
this._meshTerrainSprite3D=null;
|
||||
/**@private */
|
||||
this._finder=null;
|
||||
/**@private */
|
||||
this._setting=null;
|
||||
/**寻路网格。*/
|
||||
this.grid=null;
|
||||
PathFind.__super.call(this);
|
||||
}
|
||||
|
||||
__class(PathFind,'laya.d3.component.PathFind',_super);
|
||||
var __proto=PathFind.prototype;
|
||||
/**
|
||||
*@private
|
||||
*初始化载入蒙皮动画组件。
|
||||
*@param owner 所属精灵对象。
|
||||
*/
|
||||
__proto._load=function(owner){
|
||||
if (! (owner instanceof laya.d3.core.MeshTerrainSprite3D ))
|
||||
throw new Error("PathFinding: The owner must MeshTerrainSprite3D!");
|
||||
_super.prototype._load.call(this,owner);
|
||||
this._meshTerrainSprite3D=owner;
|
||||
}
|
||||
|
||||
/**
|
||||
*寻找路径。
|
||||
*@param startX 开始X。
|
||||
*@param startZ 开始Z。
|
||||
*@param endX 结束X。
|
||||
*@param endZ 结束Z。
|
||||
*@return 路径。
|
||||
*/
|
||||
__proto.findPath=function(startX,startZ,endX,endZ){
|
||||
var minX=this._meshTerrainSprite3D.minX;
|
||||
var minZ=this._meshTerrainSprite3D.minZ;
|
||||
var cellX=this._meshTerrainSprite3D.width / this.grid.width;
|
||||
var cellZ=this._meshTerrainSprite3D.depth / this.grid.height;
|
||||
var halfCellX=cellX / 2;
|
||||
var halfCellZ=cellZ / 2;
|
||||
var gridStartX=Math.floor((startX-minX)/ cellX);
|
||||
var gridStartZ=Math.floor((startZ-minZ)/ cellZ);
|
||||
var gridEndX=Math.floor((endX-minX)/ cellX);
|
||||
var gridEndZ=Math.floor((endZ-minZ)/ cellZ);
|
||||
var boundWidth=this.grid.width-1;
|
||||
var boundHeight=this.grid.height-1;
|
||||
(gridStartX > boundWidth)&& (gridStartX=boundWidth);
|
||||
(gridStartZ > boundHeight)&& (gridStartZ=boundHeight);
|
||||
(gridStartX < 0)&& (gridStartX=0);
|
||||
(gridStartZ < 0)&& (gridStartZ=0);
|
||||
(gridEndX > boundWidth)&& (gridEndX=boundWidth);
|
||||
(gridEndZ > boundHeight)&& (gridEndZ=boundHeight);
|
||||
(gridEndX < 0)&& (gridEndX=0);
|
||||
(gridEndZ < 0)&& (gridEndZ=0);
|
||||
var path=this._finder.findPath(gridStartX,gridStartZ,gridEndX,gridEndZ,this.grid);
|
||||
this.grid.reset();
|
||||
for (var i=1;i < path.length-1;i++){
|
||||
var gridPos=path[i];
|
||||
gridPos[0]=gridPos[0] *cellX+halfCellX+minX;
|
||||
gridPos[1]=gridPos[1] *cellZ+halfCellZ+minZ;
|
||||
}
|
||||
if (path.length==1){
|
||||
path[0][0]=endX;
|
||||
path[0][1]=endX;
|
||||
}else if (path.length > 1){
|
||||
path[0][0]=startX;
|
||||
path[0][1]=startZ;
|
||||
path[path.length-1][0]=endX;
|
||||
path[path.length-1][1]=endZ;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
*设置寻路设置。
|
||||
*@param value 寻路设置。
|
||||
*/
|
||||
/**
|
||||
*获取寻路设置。
|
||||
*@return 寻路设置。
|
||||
*/
|
||||
__getset(0,__proto,'setting',function(){
|
||||
return this._setting;
|
||||
},function(value){
|
||||
(value)&& (this._finder=new PathFinding.finders.AStarFinder(value));
|
||||
this._setting=value;
|
||||
});
|
||||
|
||||
return PathFind;
|
||||
})(Component3D)
|
||||
|
||||
|
||||
|
||||
})(window,document,Laya);
|
||||
|
||||
if (typeof define === 'function' && define.amd){
|
||||
define('laya.core', ['require', "exports"], function(require, exports) {
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
for (var i in Laya) {
|
||||
var o = Laya[i];
|
||||
o && o.__isclass && (exports[i] = o);
|
||||
}
|
||||
});
|
||||
}
|
||||
12590
public/libs/laya/laya.debugtool.js
Normal file
974
public/libs/laya/laya.device.js
Normal file
@@ -0,0 +1,974 @@
|
||||
|
||||
(function(window,document,Laya){
|
||||
var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
|
||||
|
||||
var Bitmap=laya.resource.Bitmap,Browser=laya.utils.Browser,Event=laya.events.Event,EventDispatcher=laya.events.EventDispatcher;
|
||||
var Handler=laya.utils.Handler,Rectangle=laya.maths.Rectangle,Render=laya.renders.Render,Sprite=laya.display.Sprite;
|
||||
var Stage=laya.display.Stage,Texture=laya.resource.Texture,Utils=laya.utils.Utils,WebGL=laya.webgl.WebGL;
|
||||
var WebGLContext=laya.webgl.WebGLContext;
|
||||
/**
|
||||
*使用前可用<code>supported</code>查看浏览器支持。
|
||||
*/
|
||||
//class laya.device.geolocation.Geolocation
|
||||
var Geolocation=(function(){
|
||||
function Geolocation(){}
|
||||
__class(Geolocation,'laya.device.geolocation.Geolocation');
|
||||
Geolocation.getCurrentPosition=function(onSuccess,onError){
|
||||
Geolocation.navigator.geolocation.getCurrentPosition(function(pos){
|
||||
Geolocation.position.setPosition(pos);
|
||||
onSuccess.runWith(Geolocation.position);
|
||||
},
|
||||
function(error){
|
||||
onError.runWith(error);
|
||||
},{
|
||||
enableHighAccuracy :laya.device.geolocation.Geolocation.enableHighAccuracy,
|
||||
timeout :laya.device.geolocation.Geolocation.timeout,
|
||||
maximumAge :laya.device.geolocation.Geolocation.maximumAge
|
||||
});
|
||||
}
|
||||
|
||||
Geolocation.watchPosition=function(onSuccess,onError){
|
||||
return Geolocation.navigator.geolocation.watchPosition(function(pos){
|
||||
Geolocation.position.setPosition(pos);
|
||||
onSuccess.runWith(Geolocation.position);
|
||||
},
|
||||
function(error){
|
||||
onError.runWith(error);
|
||||
},{
|
||||
enableHighAccuracy :Geolocation.enableHighAccuracy,
|
||||
timeout :Geolocation.timeout,
|
||||
maximumAge :Geolocation.maximumAge
|
||||
});
|
||||
}
|
||||
|
||||
Geolocation.clearWatch=function(id){
|
||||
Geolocation.navigator.geolocation.clearWatch(id);
|
||||
}
|
||||
|
||||
Geolocation.PERMISSION_DENIED=1;
|
||||
Geolocation.POSITION_UNAVAILABLE=2;
|
||||
Geolocation.TIMEOUT=3;
|
||||
Geolocation.enableHighAccuracy=false;
|
||||
Geolocation.maximumAge=0;
|
||||
__static(Geolocation,
|
||||
['navigator',function(){return this.navigator=Browser.window.navigator;},'position',function(){return this.position=new GeolocationInfo();},'supported',function(){return this.supported=!!Geolocation.navigator.geolocation;},'timeout',function(){return this.timeout=1E10;}
|
||||
]);
|
||||
return Geolocation;
|
||||
})()
|
||||
|
||||
|
||||
//class laya.device.geolocation.GeolocationInfo
|
||||
var GeolocationInfo=(function(){
|
||||
function GeolocationInfo(){
|
||||
this.pos=null;
|
||||
this.coords=null;
|
||||
}
|
||||
|
||||
__class(GeolocationInfo,'laya.device.geolocation.GeolocationInfo');
|
||||
var __proto=GeolocationInfo.prototype;
|
||||
__proto.setPosition=function(pos){
|
||||
this.pos=pos;
|
||||
this.coords=pos.coords;
|
||||
}
|
||||
|
||||
__getset(0,__proto,'heading',function(){
|
||||
return this.coords.heading;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'latitude',function(){
|
||||
return this.coords.latitude;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'altitudeAccuracy',function(){
|
||||
return this.coords.altitudeAccuracy;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'longitude',function(){
|
||||
return this.coords.longitude;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'altitude',function(){
|
||||
return this.coords.altitude;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'accuracy',function(){
|
||||
return this.coords.accuracy;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'speed',function(){
|
||||
return this.coords.speed;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'timestamp',function(){
|
||||
return this.pos.timestamp;
|
||||
});
|
||||
|
||||
return GeolocationInfo;
|
||||
})()
|
||||
|
||||
|
||||
/**
|
||||
*Media用于捕捉摄像头和麦克风。可以捕捉任意之一,或者同时捕捉两者。<code>getCamera</code>前可以使用<code>supported()</code>检查当前浏览器是否支持。
|
||||
*<b>NOTE:</b>
|
||||
*<p>目前Media在移动平台只支持Android,不支持IOS。只可在FireFox完整地使用,Chrome测试时无法捕捉视频。</p>
|
||||
*/
|
||||
//class laya.device.media.Media
|
||||
var Media=(function(){
|
||||
function Media(){}
|
||||
__class(Media,'laya.device.media.Media');
|
||||
Media.supported=function(){
|
||||
return !!Browser.window.navigator.getUserMedia;
|
||||
}
|
||||
|
||||
Media.getMedia=function(options,onSuccess,onError){
|
||||
if (Browser.window.navigator.getUserMedia){
|
||||
Browser.window.navigator.getUserMedia(options,function(stream){
|
||||
onSuccess.runWith(Browser.window.URL.createObjectURL(stream));
|
||||
},function(err){
|
||||
onError.runWith(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Media.__init$=function(){
|
||||
/*__JS__ */navigator.getUserMedia=navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;;
|
||||
}
|
||||
|
||||
return Media;
|
||||
})()
|
||||
|
||||
|
||||
/**
|
||||
*加速度x/y/z的单位均为m/s²。
|
||||
*在硬件(陀螺仪)不支持的情况下,alpha、beta和gamma值为null。
|
||||
*
|
||||
*@author Survivor
|
||||
*/
|
||||
//class laya.device.motion.AccelerationInfo
|
||||
var AccelerationInfo=(function(){
|
||||
function AccelerationInfo(){
|
||||
/**
|
||||
*x轴上的加速度值。
|
||||
*/
|
||||
this.x=NaN;
|
||||
/**
|
||||
*y轴上的加速度值。
|
||||
*/
|
||||
this.y=NaN;
|
||||
/**
|
||||
*z轴上的加速度值。
|
||||
*/
|
||||
this.z=NaN;
|
||||
}
|
||||
|
||||
__class(AccelerationInfo,'laya.device.motion.AccelerationInfo');
|
||||
return AccelerationInfo;
|
||||
})()
|
||||
|
||||
|
||||
/**
|
||||
*保存旋转信息的类。请勿修改本类的属性。
|
||||
*@author Survivor
|
||||
*/
|
||||
//class laya.device.motion.RotationInfo
|
||||
var RotationInfo=(function(){
|
||||
function RotationInfo(){
|
||||
/**
|
||||
*<p>
|
||||
*指示设备是否可以提供绝对方位数据(指向地球坐标系),或者设备决定的任意坐标系。
|
||||
*关于坐标系参见<i>https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Orientation_and_motion_data_explained</i>。
|
||||
*</p>
|
||||
*需要注意的是,IOS环境下,该值始终为false。即使如此,你依旧可以从<code>alpha</code>中取得正确的值。
|
||||
*/
|
||||
this.absolute=false;
|
||||
/**
|
||||
*Z轴旋转角度,其值范围从0至360。
|
||||
*若<code>absolute</code>为true或者在IOS中,alpha值是从北方到当前设备方向的角度值。
|
||||
*/
|
||||
this.alpha=NaN;
|
||||
/**
|
||||
*X轴旋转角度,其值范围从-180至180。代表设备从前至后的运动。
|
||||
*/
|
||||
this.beta=NaN;
|
||||
/**
|
||||
*Y轴旋转角度,其值范围从-90至90。代表设备从左至右的运动。
|
||||
*/
|
||||
this.gamma=NaN;
|
||||
/**
|
||||
*罗盘数据的精确度(角度)。仅IOS可用。
|
||||
*/
|
||||
this.compassAccuracy=NaN;
|
||||
}
|
||||
|
||||
__class(RotationInfo,'laya.device.motion.RotationInfo');
|
||||
return RotationInfo;
|
||||
})()
|
||||
|
||||
|
||||
/**
|
||||
*Accelerator.instance获取唯一的Accelerator引用,请勿调用构造函数。
|
||||
*
|
||||
*<p>
|
||||
*listen()的回调处理器接受四个参数:
|
||||
*<ol>
|
||||
*<li><b>acceleration</b>:表示用户给予设备的加速度。</li>
|
||||
*<li><b>accelerationIncludingGravity</b>:设备受到的总加速度(包含重力)。</li>
|
||||
*<li><b>rotationRate</b>:设备的自转速率。</li>
|
||||
*<li><b>interval</b>:加速度获取的时间间隔(毫秒)。</li>
|
||||
*</ol>
|
||||
*</p>
|
||||
*<p>
|
||||
*<b>NOTE</b><br/>
|
||||
*如,rotationRate的alpha在apple和moz文档中都是z轴旋转角度,但是实测是x轴旋转角度。为了使各属性表示的值与文档所述相同,实际值与其他属性进行了对调。
|
||||
*其中:
|
||||
*<ul>
|
||||
*<li>alpha使用gamma值。</li>
|
||||
*<li>beta使用alpha值。</li>
|
||||
*<li>gamma使用beta。</li>
|
||||
*</ul>
|
||||
*目前孰是孰非尚未可知,以此为注。
|
||||
*</p>
|
||||
*/
|
||||
//class laya.device.motion.Accelerator extends laya.events.EventDispatcher
|
||||
var Accelerator=(function(_super){
|
||||
function Accelerator(singleton){
|
||||
Accelerator.__super.call(this);
|
||||
/*__JS__ */this.onDeviceOrientationChange=this.onDeviceOrientationChange.bind(this);
|
||||
}
|
||||
|
||||
__class(Accelerator,'laya.device.motion.Accelerator',_super);
|
||||
var __proto=Accelerator.prototype;
|
||||
/**
|
||||
*侦听加速器运动。
|
||||
*@param observer 回调函数接受4个参数,见类说明。
|
||||
*/
|
||||
__proto.on=function(type,caller,listener,args){
|
||||
_super.prototype.on.call(this,type,caller,listener,args);
|
||||
Browser.window.addEventListener('devicemotion',this.onDeviceOrientationChange);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*取消侦听加速器。
|
||||
*@param handle 侦听加速器所用处理器。
|
||||
*/
|
||||
__proto.off=function(type,caller,listener,onceOnly){
|
||||
(onceOnly===void 0)&& (onceOnly=false);
|
||||
if (!this.hasListener(type))
|
||||
Browser.window.removeEventListener('devicemotion',this.onDeviceOrientationChange)
|
||||
return _super.prototype.off.call(this,type,caller,listener,onceOnly);
|
||||
}
|
||||
|
||||
__proto.onDeviceOrientationChange=function(e){
|
||||
var interval=e.interval;
|
||||
Accelerator.acceleration.x=e.acceleration.x;
|
||||
Accelerator.acceleration.y=e.acceleration.y;
|
||||
Accelerator.acceleration.z=e.acceleration.z;
|
||||
Accelerator.accelerationIncludingGravity.x=e.accelerationIncludingGravity.x;
|
||||
Accelerator.accelerationIncludingGravity.y=e.accelerationIncludingGravity.y;
|
||||
Accelerator.accelerationIncludingGravity.z=e.accelerationIncludingGravity.z;
|
||||
Accelerator.rotationRate.alpha=e.rotationRate.gamma *-1;
|
||||
Accelerator.rotationRate.beta=e.rotationRate.alpha *-1;
|
||||
Accelerator.rotationRate.gamma=e.rotationRate.beta;
|
||||
if (Browser.onAndroid){
|
||||
if (Accelerator.onChrome){
|
||||
Accelerator.rotationRate.alpha *=180 / Math.PI;
|
||||
Accelerator.rotationRate.beta *=180 / Math.PI;
|
||||
Accelerator.rotationRate.gamma *=180 / Math.PI;
|
||||
}
|
||||
Accelerator.acceleration.x *=-1;
|
||||
Accelerator.accelerationIncludingGravity.x *=-1;
|
||||
}
|
||||
else if (Browser.onIOS){
|
||||
Accelerator.acceleration.y *=-1;
|
||||
Accelerator.acceleration.z *=-1;
|
||||
Accelerator.accelerationIncludingGravity.y *=-1;
|
||||
Accelerator.accelerationIncludingGravity.z *=-1;
|
||||
interval *=1000;
|
||||
}
|
||||
this.event(/*laya.events.Event.CHANGE*/"change",[Accelerator.acceleration,Accelerator.accelerationIncludingGravity,Accelerator.rotationRate,interval]);
|
||||
}
|
||||
|
||||
__getset(1,Accelerator,'instance',function(){Accelerator._instance=Accelerator._instance|| new Accelerator(0)
|
||||
return Accelerator._instance;
|
||||
},laya.events.EventDispatcher._$SET_instance);
|
||||
|
||||
Accelerator.getTransformedAcceleration=function(acceleration){Accelerator.transformedAcceleration=Accelerator.transformedAcceleration|| new AccelerationInfo();
|
||||
Accelerator.transformedAcceleration.z=acceleration.z;
|
||||
if (Browser.window.orientation==90){
|
||||
Accelerator.transformedAcceleration.x=acceleration.y;
|
||||
Accelerator.transformedAcceleration.y=-acceleration.x;
|
||||
}
|
||||
else if (Browser.window.orientation==-90){
|
||||
Accelerator.transformedAcceleration.x=-acceleration.y;
|
||||
Accelerator.transformedAcceleration.y=acceleration.x;
|
||||
}
|
||||
else if (!Browser.window.orientation){
|
||||
Accelerator.transformedAcceleration.x=acceleration.x;
|
||||
Accelerator.transformedAcceleration.y=acceleration.y;
|
||||
}
|
||||
else if (Browser.window.orientation==180){
|
||||
Accelerator.transformedAcceleration.x=-acceleration.x;
|
||||
Accelerator.transformedAcceleration.y=-acceleration.y;
|
||||
};
|
||||
var tx=NaN;
|
||||
if (Laya.stage.canvasDegree==-90){
|
||||
tx=Accelerator.transformedAcceleration.x;
|
||||
Accelerator.transformedAcceleration.x=-Accelerator.transformedAcceleration.y;
|
||||
Accelerator.transformedAcceleration.y=tx;
|
||||
}
|
||||
else if (Laya.stage.canvasDegree==90){
|
||||
tx=Accelerator.transformedAcceleration.x;
|
||||
Accelerator.transformedAcceleration.x=Accelerator.transformedAcceleration.y;
|
||||
Accelerator.transformedAcceleration.y=-tx;
|
||||
}
|
||||
return Accelerator.transformedAcceleration;
|
||||
}
|
||||
|
||||
Accelerator._instance=null;
|
||||
Accelerator.transformedAcceleration=null;
|
||||
__static(Accelerator,
|
||||
['acceleration',function(){return this.acceleration=new AccelerationInfo();},'accelerationIncludingGravity',function(){return this.accelerationIncludingGravity=new AccelerationInfo();},'rotationRate',function(){return this.rotationRate=new RotationInfo();},'onChrome',function(){return this.onChrome=(Browser.userAgent.indexOf("Chrome")>-1);}
|
||||
]);
|
||||
return Accelerator;
|
||||
})(EventDispatcher)
|
||||
|
||||
|
||||
/**
|
||||
*使用Gyroscope.instance获取唯一的Gyroscope引用,请勿调用构造函数。
|
||||
*
|
||||
*<p>
|
||||
*listen()的回调处理器接受两个参数:
|
||||
*<code>function onOrientationChange(absolute:Boolean,info:RotationInfo):void</code>
|
||||
*<ol>
|
||||
*<li><b>absolute</b>:指示设备是否可以提供绝对方位数据(指向地球坐标系),或者设备决定的任意坐标系。关于坐标系参见<i>https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Orientation_and_motion_data_explained</i>。</li>
|
||||
*<li><b>info</b>:<code>RotationInfo</code>类型参数,保存设备的旋转值。</li>
|
||||
*</ol>
|
||||
*</p>
|
||||
*
|
||||
*<p>
|
||||
*浏览器兼容性参见:<i>http://caniuse.com/#search=deviceorientation</i>
|
||||
*</p>
|
||||
*/
|
||||
//class laya.device.motion.Gyroscope extends laya.events.EventDispatcher
|
||||
var Gyroscope=(function(_super){
|
||||
function Gyroscope(singleton){
|
||||
Gyroscope.__super.call(this);
|
||||
/*__JS__ */this.onDeviceOrientationChange=this.onDeviceOrientationChange.bind(this);
|
||||
}
|
||||
|
||||
__class(Gyroscope,'laya.device.motion.Gyroscope',_super);
|
||||
var __proto=Gyroscope.prototype;
|
||||
/**
|
||||
*监视陀螺仪运动。
|
||||
*@param observer 回调函数接受一个Boolean类型的<code>absolute</code>和<code>GyroscopeInfo</code>类型参数。
|
||||
*/
|
||||
__proto.on=function(type,caller,listener,args){
|
||||
_super.prototype.on.call(this,type,caller,listener,args);
|
||||
Browser.window.addEventListener('deviceorientation',this.onDeviceOrientationChange);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*取消指定处理器对陀螺仪的监视。
|
||||
*@param observer
|
||||
*/
|
||||
__proto.off=function(type,caller,listener,onceOnly){
|
||||
(onceOnly===void 0)&& (onceOnly=false);
|
||||
if (!this.hasListener(type))
|
||||
Browser.window.removeEventListener('deviceorientation',this.onDeviceOrientationChange);
|
||||
return _super.prototype.off.call(this,type,caller,listener,onceOnly);
|
||||
}
|
||||
|
||||
__proto.onDeviceOrientationChange=function(e){
|
||||
Gyroscope.info.alpha=e.alpha;
|
||||
Gyroscope.info.beta=e.beta;
|
||||
Gyroscope.info.gamma=e.gamma;
|
||||
if (e.webkitCompassHeading){
|
||||
Gyroscope.info.alpha=e.webkitCompassHeading *-1;
|
||||
Gyroscope.info.compassAccuracy=e.webkitCompassAccuracy;
|
||||
}
|
||||
this.event(/*laya.events.Event.CHANGE*/"change",[e.absolute,Gyroscope.info]);
|
||||
}
|
||||
|
||||
__getset(1,Gyroscope,'instance',function(){Gyroscope._instance=Gyroscope._instance|| new Gyroscope(0);
|
||||
return Gyroscope._instance;
|
||||
},laya.events.EventDispatcher._$SET_instance);
|
||||
|
||||
Gyroscope._instance=null;
|
||||
__static(Gyroscope,
|
||||
['info',function(){return this.info=new RotationInfo();}
|
||||
]);
|
||||
return Gyroscope;
|
||||
})(EventDispatcher)
|
||||
|
||||
|
||||
/**
|
||||
*Shake只能在支持此操作的设备上有效。
|
||||
*
|
||||
*@author Survivor
|
||||
*/
|
||||
//class laya.device.Shake extends laya.events.EventDispatcher
|
||||
var Shake=(function(_super){
|
||||
function Shake(){
|
||||
this.throushold=0;
|
||||
this.shakeInterval=0;
|
||||
this.callback=null;
|
||||
this.lastX=NaN;
|
||||
this.lastY=NaN;
|
||||
this.lastZ=NaN;
|
||||
this.lastMillSecond=NaN;
|
||||
Shake.__super.call(this);
|
||||
}
|
||||
|
||||
__class(Shake,'laya.device.Shake',_super);
|
||||
var __proto=Shake.prototype;
|
||||
/**
|
||||
*开始响应设备摇晃。
|
||||
*@param throushold 响应的瞬时速度阈值,轻度摇晃的值约在5~10间。
|
||||
*@param timeout 设备摇晃的响应间隔时间。
|
||||
*@param callback 在设备摇晃触发时调用的处理器。
|
||||
*/
|
||||
__proto.start=function(throushold,interval){
|
||||
this.throushold=throushold;
|
||||
this.shakeInterval=interval;
|
||||
this.lastX=this.lastY=this.lastZ=NaN;
|
||||
Accelerator.instance.on(/*laya.events.Event.CHANGE*/"change",this,this.onShake);
|
||||
}
|
||||
|
||||
/**
|
||||
*停止响应设备摇晃。
|
||||
*/
|
||||
__proto.stop=function(){
|
||||
Accelerator.instance.off(/*laya.events.Event.CHANGE*/"change",this,this.onShake);
|
||||
}
|
||||
|
||||
__proto.onShake=function(acceleration,accelerationIncludingGravity,rotationRate,interval){
|
||||
if(isNaN(this.lastX)){
|
||||
this.lastX=accelerationIncludingGravity.x;
|
||||
this.lastY=accelerationIncludingGravity.y;
|
||||
this.lastZ=accelerationIncludingGravity.z;
|
||||
this.lastMillSecond=Browser.now();
|
||||
return;
|
||||
};
|
||||
var deltaX=Math.abs(this.lastX-accelerationIncludingGravity.x);
|
||||
var deltaY=Math.abs(this.lastY-accelerationIncludingGravity.y);
|
||||
var deltaZ=Math.abs(this.lastZ-accelerationIncludingGravity.z);
|
||||
if(this.isShaked(deltaX,deltaY,deltaZ)){
|
||||
var deltaMillSecond=Browser.now()-this.lastMillSecond;
|
||||
if (deltaMillSecond > this.shakeInterval){
|
||||
this.event(/*laya.events.Event.CHANGE*/"change");
|
||||
this.lastMillSecond=Browser.now();
|
||||
}
|
||||
}
|
||||
this.lastX=accelerationIncludingGravity.x;
|
||||
this.lastY=accelerationIncludingGravity.y;
|
||||
this.lastZ=accelerationIncludingGravity.z;
|
||||
}
|
||||
|
||||
// 通过任意两个分量判断是否满足摇晃设定。
|
||||
__proto.isShaked=function(deltaX,deltaY,deltaZ){
|
||||
return (deltaX > this.throushold && deltaY > this.throushold)||
|
||||
(deltaX > this.throushold && deltaZ > this.throushold)||
|
||||
(deltaY > this.throushold && deltaZ > this.throushold)
|
||||
}
|
||||
|
||||
__getset(1,Shake,'instance',function(){Shake._instance=Shake._instance|| new Shake();
|
||||
return Shake._instance;
|
||||
},laya.events.EventDispatcher._$SET_instance);
|
||||
|
||||
Shake._instance=null;
|
||||
return Shake;
|
||||
})(EventDispatcher)
|
||||
|
||||
|
||||
/**
|
||||
*<code>Video</code>将视频显示到Canvas上。<code>Video</code>可能不会在所有浏览器有效。
|
||||
*<p>关于Video支持的所有事件参见:<i>http://www.w3school.com.cn/tags/html_ref_audio_video_dom.asp</i>。</p>
|
||||
*<p>
|
||||
*<b>注意:</b><br/>
|
||||
*在PC端可以在任何时机调用<code>play()</code>因此,可以在程序开始运行时就使Video开始播放。但是在移动端,只有在用户第一次触碰屏幕后才可以调用play(),所以移动端不可能在程序开始运行时就自动开始播放Video。
|
||||
*</p>
|
||||
*
|
||||
*<p>MDN Video链接: <i>https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video</i></p>
|
||||
*/
|
||||
//class laya.device.media.Video extends laya.display.Sprite
|
||||
var Video=(function(_super){
|
||||
function Video(width,height){
|
||||
this.htmlVideo=null;
|
||||
this.videoElement=null;
|
||||
this.internalTexture=null;
|
||||
(width===void 0)&& (width=320);
|
||||
(height===void 0)&& (height=240);
|
||||
Video.__super.call(this);
|
||||
if (Render.isWebGL)
|
||||
this.htmlVideo=new WebGLVideo();
|
||||
else
|
||||
this.htmlVideo=new HtmlVideo();
|
||||
this.videoElement=this.htmlVideo.getVideo();
|
||||
this.videoElement.layaTarget=this;
|
||||
this.internalTexture=new Texture(this.htmlVideo);
|
||||
this.videoElement.addEventListener("abort",Video.onAbort);
|
||||
this.videoElement.addEventListener("canplay",Video.onCanplay);
|
||||
this.videoElement.addEventListener("canplaythrough",Video.onCanplaythrough);
|
||||
this.videoElement.addEventListener("durationchange",Video.onDurationchange);
|
||||
this.videoElement.addEventListener("emptied",Video.onEmptied);
|
||||
this.videoElement.addEventListener("error",Video.onError);
|
||||
this.videoElement.addEventListener("loadeddata",Video.onLoadeddata);
|
||||
this.videoElement.addEventListener("loadedmetadata",Video.onLoadedmetadata);
|
||||
this.videoElement.addEventListener("loadstart",Video.onLoadstart);
|
||||
this.videoElement.addEventListener("pause",Video.onPause);
|
||||
this.videoElement.addEventListener("play",Video.onPlay);
|
||||
this.videoElement.addEventListener("playing",Video.onPlaying);
|
||||
this.videoElement.addEventListener("progress",Video.onProgress);
|
||||
this.videoElement.addEventListener("ratechange",Video.onRatechange);
|
||||
this.videoElement.addEventListener("seeked",Video.onSeeked);
|
||||
this.videoElement.addEventListener("seeking",Video.onSeeking);
|
||||
this.videoElement.addEventListener("stalled",Video.onStalled);
|
||||
this.videoElement.addEventListener("suspend",Video.onSuspend);
|
||||
this.videoElement.addEventListener("timeupdate",Video.onTimeupdate);
|
||||
this.videoElement.addEventListener("volumechange",Video.onVolumechange);
|
||||
this.videoElement.addEventListener("waiting",Video.onWaiting);
|
||||
this.videoElement.addEventListener("ended",this.onPlayComplete['bind'](this));
|
||||
this.size(width,height);
|
||||
if (Browser.onMobile){
|
||||
/*__JS__ */this.onDocumentClick=this.onDocumentClick.bind(this);
|
||||
Browser.document.addEventListener("touchend",this.onDocumentClick);
|
||||
}
|
||||
}
|
||||
|
||||
__class(Video,'laya.device.media.Video',_super);
|
||||
var __proto=Video.prototype;
|
||||
__proto.onPlayComplete=function(e){
|
||||
Laya.timer.clear(this,this.renderCanvas);
|
||||
this.event("ended");
|
||||
}
|
||||
|
||||
/**
|
||||
*设置播放源。
|
||||
*@param url 播放源路径。
|
||||
*/
|
||||
__proto.load=function(url){
|
||||
if (url.indexOf("blob:")==0)
|
||||
this.videoElement.src=url;
|
||||
else
|
||||
this.htmlVideo.setSource(url,laya.device.media.Video.MP4);
|
||||
}
|
||||
|
||||
/**
|
||||
*开始播放视频。
|
||||
*/
|
||||
__proto.play=function(){
|
||||
this.videoElement.play();
|
||||
Laya.timer.frameLoop(1,this,this.renderCanvas);
|
||||
}
|
||||
|
||||
/**
|
||||
*暂停视频播放。
|
||||
*/
|
||||
__proto.pause=function(){
|
||||
this.videoElement.pause();
|
||||
Laya.timer.clear(this,this.renderCanvas);
|
||||
}
|
||||
|
||||
/**
|
||||
*重新加载视频。
|
||||
*/
|
||||
__proto.reload=function(){
|
||||
this.videoElement.load();
|
||||
}
|
||||
|
||||
/**
|
||||
*检测是否支持播放指定格式视频。
|
||||
*@param type 参数为Video.MP4 / Video.OGG / Video.WEBM之一。
|
||||
*@return 表示支持的级别。可能的值:
|
||||
*<ul>
|
||||
*<li>"probably",Video.SUPPORT_PROBABLY-浏览器最可能支持该音频/视频类型</li>
|
||||
*<li>"maybe",Video.SUPPORT_MAYBY-浏览器也许支持该音频/视频类型</li>
|
||||
*<li>"",Video.SUPPORT_NO-(空字符串)浏览器不支持该音频/视频类型</li>
|
||||
*</ul>
|
||||
*/
|
||||
__proto.canPlayType=function(type){
|
||||
var typeString;
|
||||
switch (type){
|
||||
case laya.device.media.Video.MP4:
|
||||
typeString="video/mp4";
|
||||
break ;
|
||||
case laya.device.media.Video.OGG:
|
||||
typeString="video/ogg";
|
||||
break ;
|
||||
case laya.device.media.Video.WEBM:
|
||||
typeString="video/webm";
|
||||
break ;
|
||||
}
|
||||
return this.videoElement.canPlayType(typeString);
|
||||
}
|
||||
|
||||
__proto.renderCanvas=function(){
|
||||
if (this.readyState===0)
|
||||
return;
|
||||
if (Render.isWebGL)
|
||||
this.htmlVideo['updateTexture']();
|
||||
this.graphics.clear();
|
||||
this.graphics.drawTexture(this.internalTexture,0,0,this.width,this.height);
|
||||
}
|
||||
|
||||
__proto.onDocumentClick=function(){
|
||||
this.videoElement.play();
|
||||
this.videoElement.pause();
|
||||
Browser.document.removeEventListener("touchend",this.onDocumentClick);
|
||||
}
|
||||
|
||||
__proto.size=function(width,height){
|
||||
_super.prototype.size.call(this,width,height)
|
||||
this.videoElement.width=width / Browser.pixelRatio;
|
||||
if (this.paused)this.renderCanvas();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*销毁内部事件绑定。
|
||||
*/
|
||||
__proto.destroy=function(detroyChildren){
|
||||
(detroyChildren===void 0)&& (detroyChildren=true);
|
||||
_super.prototype.destroy.call(this,detroyChildren);
|
||||
this.videoElement.removeEventListener("abort",Video.onAbort);
|
||||
this.videoElement.removeEventListener("canplay",Video.onCanplay);
|
||||
this.videoElement.removeEventListener("canplaythrough",Video.onCanplaythrough);
|
||||
this.videoElement.removeEventListener("durationchange",Video.onDurationchange);
|
||||
this.videoElement.removeEventListener("emptied",Video.onEmptied);
|
||||
this.videoElement.removeEventListener("error",Video.onError);
|
||||
this.videoElement.removeEventListener("loadeddata",Video.onLoadeddata);
|
||||
this.videoElement.removeEventListener("loadedmetadata",Video.onLoadedmetadata);
|
||||
this.videoElement.removeEventListener("loadstart",Video.onLoadstart);
|
||||
this.videoElement.removeEventListener("pause",Video.onPause);
|
||||
this.videoElement.removeEventListener("play",Video.onPlay);
|
||||
this.videoElement.removeEventListener("playing",Video.onPlaying);
|
||||
this.videoElement.removeEventListener("progress",Video.onProgress);
|
||||
this.videoElement.removeEventListener("ratechange",Video.onRatechange);
|
||||
this.videoElement.removeEventListener("seeked",Video.onSeeked);
|
||||
this.videoElement.removeEventListener("seeking",Video.onSeeking);
|
||||
this.videoElement.removeEventListener("stalled",Video.onStalled);
|
||||
this.videoElement.removeEventListener("suspend",Video.onSuspend);
|
||||
this.videoElement.removeEventListener("timeupdate",Video.onTimeupdate);
|
||||
this.videoElement.removeEventListener("volumechange",Video.onVolumechange);
|
||||
this.videoElement.removeEventListener("waiting",Video.onWaiting);
|
||||
this.videoElement.removeEventListener("ended",this.onPlayComplete);
|
||||
this.pause();
|
||||
this.videoElement=null;
|
||||
}
|
||||
|
||||
__proto.syncVideoPosition=function(){
|
||||
var stage=Laya.stage;
|
||||
var rec;
|
||||
rec=Utils.getGlobalPosAndScale(this);
|
||||
var a=stage._canvasTransform.a,d=stage._canvasTransform.d;
|
||||
var x=rec.x *stage.clientScaleX *a+stage.offset.x;
|
||||
var y=rec.y *stage.clientScaleY *d+stage.offset.y;
|
||||
this.videoElement.style.left=x+'px';;
|
||||
this.videoElement.style.top=y+'px';
|
||||
this.videoElement.width=this.width / Browser.pixelRatio;
|
||||
this.videoElement.height=this.height / Browser.pixelRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
*buffered 属性返回 TimeRanges(JS)对象。TimeRanges 对象表示用户的音视频缓冲范围。缓冲范围指的是已缓冲音视频的时间范围。如果用户在音视频中跳跃播放,会得到多个缓冲范围。
|
||||
*<p>buffered.length返回缓冲范围个数。如获取第一个缓冲范围则是buffered.start(0)和buffered.end(0)。以秒计。</p>
|
||||
*@return TimeRanges(JS)对象
|
||||
*/
|
||||
__getset(0,__proto,'buffered',function(){
|
||||
return this.videoElement.buffered;
|
||||
});
|
||||
|
||||
/**
|
||||
*获取视频源尺寸。ready事件触发后可用。
|
||||
*/
|
||||
__getset(0,__proto,'videoWidth',function(){
|
||||
return this.videoElement.videoWidth;
|
||||
});
|
||||
|
||||
/**
|
||||
*获取当前播放源路径。
|
||||
*/
|
||||
__getset(0,__proto,'currentSrc',function(){
|
||||
return this.videoElement.currentSrc;
|
||||
});
|
||||
|
||||
/**
|
||||
*设置和获取当前播放头位置。
|
||||
*/
|
||||
__getset(0,__proto,'currentTime',function(){
|
||||
return this.videoElement.currentTime;
|
||||
},function(value){
|
||||
this.videoElement.currentTime=value;
|
||||
this.renderCanvas();
|
||||
});
|
||||
|
||||
/**
|
||||
*返回音频/视频的播放是否已结束
|
||||
*/
|
||||
__getset(0,__proto,'ended',function(){
|
||||
return this.videoElement.ended;
|
||||
});
|
||||
|
||||
/**
|
||||
*设置和获取当前音量。
|
||||
*/
|
||||
__getset(0,__proto,'volume',function(){
|
||||
return this.videoElement.volume;
|
||||
},function(value){
|
||||
this.videoElement.volume=value;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'videoHeight',function(){
|
||||
return this.videoElement.videoHeight;
|
||||
});
|
||||
|
||||
/**
|
||||
*表示视频元素的就绪状态:
|
||||
*<ul>
|
||||
*<li>0=HAVE_NOTHING-没有关于音频/视频是否就绪的信息</li>
|
||||
*<li>1=HAVE_METADATA-关于音频/视频就绪的元数据</li>
|
||||
*<li>2=HAVE_CURRENT_DATA-关于当前播放位置的数据是可用的,但没有足够的数据来播放下一帧/毫秒</li>
|
||||
*<li>3=HAVE_FUTURE_DATA-当前及至少下一帧的数据是可用的</li>
|
||||
*<li>4=HAVE_ENOUGH_DATA-可用数据足以开始播放</li>
|
||||
*</ul>
|
||||
*/
|
||||
__getset(0,__proto,'readyState',function(){
|
||||
return this.videoElement.readyState;
|
||||
});
|
||||
|
||||
/**
|
||||
*获取视频长度(秒)。ready事件触发后可用。
|
||||
*/
|
||||
__getset(0,__proto,'duration',function(){
|
||||
return this.videoElement.duration;
|
||||
});
|
||||
|
||||
/**
|
||||
*返回表示音频/视频错误状态的 MediaError(JS)对象。
|
||||
*/
|
||||
__getset(0,__proto,'error',function(){
|
||||
return this.videoElement.error;
|
||||
});
|
||||
|
||||
/**
|
||||
*设置或返回音频/视频是否应在结束时重新播放。
|
||||
*/
|
||||
__getset(0,__proto,'loop',function(){
|
||||
return this.videoElement.loop;
|
||||
},function(value){
|
||||
this.videoElement.loop=value;
|
||||
});
|
||||
|
||||
/**
|
||||
*playbackRate 属性设置或返回音频/视频的当前播放速度。如:
|
||||
*<ul>
|
||||
*<li>1.0 正常速度</li>
|
||||
*<li>0.5 半速(更慢)</li>
|
||||
*<li>2.0 倍速(更快)</li>
|
||||
*<li>-1.0 向后,正常速度</li>
|
||||
*<li>-0.5 向后,半速</li>
|
||||
*</ul>
|
||||
*<p>只有 Google Chrome 和 Safari 支持 playbackRate 属性。</p>
|
||||
*/
|
||||
__getset(0,__proto,'playbackRate',function(){
|
||||
return this.videoElement.playbackRate;
|
||||
},function(value){
|
||||
this.videoElement.playbackRate=value;
|
||||
});
|
||||
|
||||
/**
|
||||
*获取和设置静音状态。
|
||||
*/
|
||||
__getset(0,__proto,'muted',function(){
|
||||
return this.videoElement.muted;
|
||||
},function(value){
|
||||
this.videoElement.muted=value;
|
||||
});
|
||||
|
||||
/**
|
||||
*返回视频是否暂停
|
||||
*/
|
||||
__getset(0,__proto,'paused',function(){
|
||||
return this.videoElement.paused;
|
||||
});
|
||||
|
||||
/**
|
||||
*preload 属性设置或返回是否在页面加载后立即加载视频。可赋值如下:
|
||||
*<ul>
|
||||
*<li>auto 指示一旦页面加载,则开始加载视频。</li>
|
||||
*<li>metadata 指示当页面加载后仅加载音频/视频的元数据。</li>
|
||||
*<li>none 指示页面加载后不应加载音频/视频。</li>
|
||||
*</ul>
|
||||
*/
|
||||
__getset(0,__proto,'preload',function(){
|
||||
return this.videoElement.preload;
|
||||
},function(value){
|
||||
this.videoElement.preload=value;
|
||||
});
|
||||
|
||||
/**
|
||||
*参见 <i>http://www.w3school.com.cn/tags/av_prop_seekable.asp</i>。
|
||||
*/
|
||||
__getset(0,__proto,'seekable',function(){
|
||||
return this.videoElement.seekable;
|
||||
});
|
||||
|
||||
/**
|
||||
*seeking 属性返回用户目前是否在音频/视频中寻址。
|
||||
*寻址中(Seeking)指的是用户在音频/视频中移动/跳跃到新的位置。
|
||||
*/
|
||||
__getset(0,__proto,'seeking',function(){
|
||||
return this.videoElement.seeking;
|
||||
});
|
||||
|
||||
__getset(0,__proto,'height',_super.prototype._$get_height,function(value){
|
||||
Laya.superSet(Sprite,this,'height',value);
|
||||
if (this.paused)this.renderCanvas();
|
||||
});
|
||||
|
||||
__getset(0,__proto,'width',_super.prototype._$get_width,function(value){
|
||||
this.videoElement.width=this.width / Browser.pixelRatio;
|
||||
Laya.superSet(Sprite,this,'width',value);
|
||||
if (this.paused)this.renderCanvas();
|
||||
});
|
||||
|
||||
Video.onAbort=function(e){e.target.layaTarget.event("abort")}
|
||||
Video.onCanplay=function(e){e.target.layaTarget.event("canplay")}
|
||||
Video.onCanplaythrough=function(e){e.target.layaTarget.event("canplaythrough")}
|
||||
Video.onDurationchange=function(e){e.target.layaTarget.event("durationchange")}
|
||||
Video.onEmptied=function(e){e.target.layaTarget.event("emptied")}
|
||||
Video.onError=function(e){e.target.layaTarget.event("error")}
|
||||
Video.onLoadeddata=function(e){e.target.layaTarget.event("loadeddata")}
|
||||
Video.onLoadedmetadata=function(e){e.target.layaTarget.event("loadedmetadata")}
|
||||
Video.onLoadstart=function(e){e.target.layaTarget.event("loadstart")}
|
||||
Video.onPause=function(e){e.target.layaTarget.event("pause")}
|
||||
Video.onPlay=function(e){e.target.layaTarget.event("play")}
|
||||
Video.onPlaying=function(e){e.target.layaTarget.event("playing")}
|
||||
Video.onProgress=function(e){e.target.layaTarget.event("progress")}
|
||||
Video.onRatechange=function(e){e.target.layaTarget.event("ratechange")}
|
||||
Video.onSeeked=function(e){e.target.layaTarget.event("seeked")}
|
||||
Video.onSeeking=function(e){e.target.layaTarget.event("seeking")}
|
||||
Video.onStalled=function(e){e.target.layaTarget.event("stalled")}
|
||||
Video.onSuspend=function(e){e.target.layaTarget.event("suspend")}
|
||||
Video.onTimeupdate=function(e){e.target.layaTarget.event("timeupdate")}
|
||||
Video.onVolumechange=function(e){e.target.layaTarget.event("volumechange")}
|
||||
Video.onWaiting=function(e){e.target.layaTarget.event("waiting")}
|
||||
Video.MP4=1;
|
||||
Video.OGG=2;
|
||||
Video.CAMERA=4;
|
||||
Video.WEBM=8;
|
||||
Video.SUPPORT_PROBABLY="probably";
|
||||
Video.SUPPORT_MAYBY="maybe";
|
||||
Video.SUPPORT_NO="";
|
||||
return Video;
|
||||
})(Sprite)
|
||||
|
||||
|
||||
/**
|
||||
*@private
|
||||
*/
|
||||
//class laya.device.media.HtmlVideo extends laya.resource.Bitmap
|
||||
var HtmlVideo=(function(_super){
|
||||
function HtmlVideo(){
|
||||
this.video=null;
|
||||
HtmlVideo.__super.call(this);
|
||||
this._w=1;
|
||||
this._h=1;
|
||||
this.createDomElement();
|
||||
}
|
||||
|
||||
__class(HtmlVideo,'laya.device.media.HtmlVideo',_super);
|
||||
var __proto=HtmlVideo.prototype;
|
||||
__proto.createDomElement=function(){
|
||||
var _$this=this;
|
||||
this._source=this.video=Browser.createElement("video");
|
||||
var style=this.video.style;
|
||||
style.position='absolute';
|
||||
style.top='0px';
|
||||
style.left='0px';
|
||||
this.video.addEventListener("loadedmetadata",(function(){
|
||||
this._w=_$this.video.videoWidth;
|
||||
this._h=_$this.video.videoHeight;
|
||||
})['bind'](this));
|
||||
}
|
||||
|
||||
__proto.setSource=function(url,extension){
|
||||
while(this.video.childElementCount)
|
||||
this.video.firstChild.remove();
|
||||
if (extension & Video.MP4)
|
||||
this.appendSource(url,"video/mp4");
|
||||
if (extension & Video.OGG)
|
||||
this.appendSource(url+".ogg","video/ogg");
|
||||
}
|
||||
|
||||
__proto.appendSource=function(source,type){
|
||||
var sourceElement=Browser.createElement("source");
|
||||
sourceElement.src=source;
|
||||
sourceElement.type=type;
|
||||
this.video.appendChild(sourceElement);
|
||||
}
|
||||
|
||||
__proto.getVideo=function(){
|
||||
return this.video;
|
||||
}
|
||||
|
||||
HtmlVideo.create=function(){
|
||||
return new HtmlVideo();
|
||||
}
|
||||
|
||||
return HtmlVideo;
|
||||
})(Bitmap)
|
||||
|
||||
|
||||
/**
|
||||
*@private
|
||||
*/
|
||||
//class laya.device.media.WebGLVideo extends laya.device.media.HtmlVideo
|
||||
var WebGLVideo=(function(_super){
|
||||
function WebGLVideo(){
|
||||
this.gl=null;
|
||||
this.preTarget=null;
|
||||
this.preTexture=null;
|
||||
WebGLVideo.__super.call(this);
|
||||
if(Browser.onIPhone)
|
||||
return;
|
||||
this.gl=WebGL.mainContext;
|
||||
this._source=this.gl.createTexture();
|
||||
this.preTarget=WebGLContext.curBindTexTarget;
|
||||
this.preTexture=WebGLContext.curBindTexValue;
|
||||
WebGLContext.bindTexture(this.gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._source);
|
||||
this.gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
|
||||
this.gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
|
||||
this.gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
|
||||
this.gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
|
||||
(this.preTarget && this.preTexture)&& (WebGLContext.bindTexture(this.gl,this.preTarget,this.preTexture));
|
||||
}
|
||||
|
||||
__class(WebGLVideo,'laya.device.media.WebGLVideo',_super);
|
||||
var __proto=WebGLVideo.prototype;
|
||||
__proto.updateTexture=function(){
|
||||
if(Browser.onIPhone)
|
||||
return;
|
||||
WebGLContext.bindTexture(this.gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._source);
|
||||
this.gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,0,/*laya.webgl.WebGLContext.RGB*/0x1907,/*laya.webgl.WebGLContext.RGB*/0x1907,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,this.video);
|
||||
}
|
||||
|
||||
return WebGLVideo;
|
||||
})(HtmlVideo)
|
||||
|
||||
|
||||
Laya.__init([Media]);
|
||||
})(window,document,Laya);
|
||||
|
||||
if (typeof define === 'function' && define.amd){
|
||||
define('laya.core', ['require', "exports"], function(require, exports) {
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
for (var i in Laya) {
|
||||
var o = Laya[i];
|
||||
o && o.__isclass && (exports[i] = o);
|
||||
}
|
||||
});
|
||||
}
|
||||
353
public/libs/laya/laya.filter.js
Normal file
@@ -0,0 +1,353 @@
|
||||
|
||||
(function(window,document,Laya){
|
||||
var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
|
||||
|
||||
var Browser=laya.utils.Browser,Color=laya.utils.Color,ColorFilterAction=laya.filters.ColorFilterAction;
|
||||
var ColorFilterActionGL=laya.filters.webgl.ColorFilterActionGL,Filter=laya.filters.Filter,FilterActionGL=laya.filters.webgl.FilterActionGL;
|
||||
var Matrix=laya.maths.Matrix,Rectangle=laya.maths.Rectangle,Render=laya.renders.Render,RenderContext=laya.renders.RenderContext;
|
||||
var RenderTarget2D=laya.webgl.resource.RenderTarget2D,RunDriver=laya.utils.RunDriver,ShaderDefines2D=laya.webgl.shader.d2.ShaderDefines2D;
|
||||
var Sprite=laya.display.Sprite,Texture=laya.resource.Texture,Value2D=laya.webgl.shader.d2.value.Value2D;
|
||||
/**
|
||||
*默认的FILTER,什么都不做
|
||||
*@private
|
||||
*/
|
||||
//class laya.filters.FilterAction
|
||||
var FilterAction=(function(){
|
||||
function FilterAction(){
|
||||
this.data=null;
|
||||
}
|
||||
|
||||
__class(FilterAction,'laya.filters.FilterAction');
|
||||
var __proto=FilterAction.prototype;
|
||||
Laya.imps(__proto,{"laya.filters.IFilterAction":true})
|
||||
__proto.apply=function(data){
|
||||
return null;
|
||||
}
|
||||
|
||||
return FilterAction;
|
||||
})()
|
||||
|
||||
|
||||
/**
|
||||
*@private
|
||||
*/
|
||||
//class laya.filters.WebGLFilter
|
||||
var WebGLFilter=(function(){
|
||||
function WebGLFilter(){}
|
||||
__class(WebGLFilter,'laya.filters.WebGLFilter');
|
||||
WebGLFilter.enable=function(){
|
||||
if (WebGLFilter.isInit)return;
|
||||
WebGLFilter.isInit=true;
|
||||
if (!Render.isWebGL)return;
|
||||
RunDriver.createFilterAction=function (type){
|
||||
var action;
|
||||
switch (type){
|
||||
case /*laya.filters.Filter.COLOR*/0x20:
|
||||
action=new ColorFilterActionGL();
|
||||
break ;
|
||||
case /*laya.filters.Filter.BLUR*/0x10:
|
||||
action=new BlurFilterActionGL();
|
||||
break ;
|
||||
case /*laya.filters.Filter.GLOW*/0x08:
|
||||
action=new GlowFilterActionGL();
|
||||
break ;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
WebGLFilter.isInit=false;
|
||||
WebGLFilter.__init$=function(){
|
||||
BlurFilterActionGL;
|
||||
ColorFilterActionGL;
|
||||
GlowFilterActionGL;
|
||||
Render;
|
||||
RunDriver;{
|
||||
RunDriver.createFilterAction=function (type){
|
||||
var action;
|
||||
switch (type){
|
||||
case /*laya.filters.Filter.BLUR*/0x10:
|
||||
action=new FilterAction();
|
||||
break ;
|
||||
case /*laya.filters.Filter.GLOW*/0x08:
|
||||
action=new FilterAction();
|
||||
break ;
|
||||
case /*laya.filters.Filter.COLOR*/0x20:
|
||||
action=new ColorFilterAction();
|
||||
break ;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return WebGLFilter;
|
||||
})()
|
||||
|
||||
|
||||
/**
|
||||
*模糊滤镜
|
||||
*/
|
||||
//class laya.filters.BlurFilter extends laya.filters.Filter
|
||||
var BlurFilter=(function(_super){
|
||||
function BlurFilter(strength){
|
||||
/**模糊滤镜的强度(值越大,越不清晰 */
|
||||
this.strength=NaN;
|
||||
this.strength_sig2_2sig2_gauss1=[];
|
||||
BlurFilter.__super.call(this);
|
||||
(strength===void 0)&& (strength=4);
|
||||
if (Render.isWebGL)WebGLFilter.enable();
|
||||
this.strength=strength;
|
||||
this._action=RunDriver.createFilterAction(0x10);
|
||||
this._action.data=this;
|
||||
}
|
||||
|
||||
__class(BlurFilter,'laya.filters.BlurFilter',_super);
|
||||
var __proto=BlurFilter.prototype;
|
||||
/**
|
||||
*@private 通知微端
|
||||
*/
|
||||
__proto.callNative=function(sp){
|
||||
sp.conchModel &&sp.conchModel.blurFilter&&sp.conchModel.blurFilter(this.strength);
|
||||
}
|
||||
|
||||
/**
|
||||
*@private
|
||||
*当前滤镜对应的操作器
|
||||
*/
|
||||
__getset(0,__proto,'action',function(){
|
||||
return this._action;
|
||||
});
|
||||
|
||||
/**
|
||||
*@private
|
||||
*当前滤镜的类型
|
||||
*/
|
||||
__getset(0,__proto,'type',function(){
|
||||
return 0x10;
|
||||
});
|
||||
|
||||
return BlurFilter;
|
||||
})(Filter)
|
||||
|
||||
|
||||
/**
|
||||
*发光滤镜(也可以当成阴影滤使用)
|
||||
*/
|
||||
//class laya.filters.GlowFilter extends laya.filters.Filter
|
||||
var GlowFilter=(function(_super){
|
||||
function GlowFilter(color,blur,offX,offY){
|
||||
/**滤镜的颜色*/
|
||||
this._color=null;
|
||||
GlowFilter.__super.call(this);
|
||||
this._elements=new Float32Array(9);
|
||||
(blur===void 0)&& (blur=4);
|
||||
(offX===void 0)&& (offX=6);
|
||||
(offY===void 0)&& (offY=6);
|
||||
if (Render.isWebGL){
|
||||
WebGLFilter.enable();
|
||||
}
|
||||
this._color=new Color(color);
|
||||
this.blur=Math.min(blur,20);
|
||||
this.offX=offX;
|
||||
this.offY=offY;
|
||||
this._action=RunDriver.createFilterAction(0x08);
|
||||
this._action.data=this;
|
||||
}
|
||||
|
||||
__class(GlowFilter,'laya.filters.GlowFilter',_super);
|
||||
var __proto=GlowFilter.prototype;
|
||||
/**@private */
|
||||
__proto.getColor=function(){
|
||||
return this._color._color;
|
||||
}
|
||||
|
||||
/**
|
||||
*@private 通知微端
|
||||
*/
|
||||
__proto.callNative=function(sp){
|
||||
sp.conchModel &&sp.conchModel.glowFilter&&sp.conchModel.glowFilter(this._color.strColor,this._elements[4],this._elements[5],this._elements[6]);
|
||||
}
|
||||
|
||||
/**
|
||||
*@private
|
||||
*滤镜类型
|
||||
*/
|
||||
__getset(0,__proto,'type',function(){
|
||||
return 0x08;
|
||||
});
|
||||
|
||||
/**@private */
|
||||
__getset(0,__proto,'action',function(){
|
||||
return this._action;
|
||||
});
|
||||
|
||||
/**@private */
|
||||
/**@private */
|
||||
__getset(0,__proto,'offY',function(){
|
||||
return this._elements[6];
|
||||
},function(value){
|
||||
this._elements[6]=value;
|
||||
});
|
||||
|
||||
/**@private */
|
||||
/**@private */
|
||||
__getset(0,__proto,'offX',function(){
|
||||
return this._elements[5];
|
||||
},function(value){
|
||||
this._elements[5]=value;
|
||||
});
|
||||
|
||||
/**@private */
|
||||
/**@private */
|
||||
__getset(0,__proto,'blur',function(){
|
||||
return this._elements[4];
|
||||
},function(value){
|
||||
this._elements[4]=value;
|
||||
});
|
||||
|
||||
return GlowFilter;
|
||||
})(Filter)
|
||||
|
||||
|
||||
/**
|
||||
*@private
|
||||
*/
|
||||
//class laya.filters.webgl.BlurFilterActionGL extends laya.filters.webgl.FilterActionGL
|
||||
var BlurFilterActionGL=(function(_super){
|
||||
function BlurFilterActionGL(){
|
||||
this.data=null;
|
||||
BlurFilterActionGL.__super.call(this);
|
||||
}
|
||||
|
||||
__class(BlurFilterActionGL,'laya.filters.webgl.BlurFilterActionGL',_super);
|
||||
var __proto=BlurFilterActionGL.prototype;
|
||||
__proto.setValueMix=function(shader){
|
||||
shader.defines.add(this.data.type);
|
||||
var o=shader;
|
||||
}
|
||||
|
||||
__proto.apply3d=function(scope,sprite,context,x,y){
|
||||
var b=scope.getValue("bounds");
|
||||
var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
|
||||
shaderValue.setFilters([this.data]);
|
||||
var tMatrix=Matrix.EMPTY;
|
||||
tMatrix.identity();
|
||||
context.ctx.drawTarget(scope,0,0,b.width,b.height,Matrix.EMPTY,"src",shaderValue);
|
||||
shaderValue.setFilters(null);
|
||||
}
|
||||
|
||||
__proto.setValue=function(shader){
|
||||
shader.strength=this.data.strength;
|
||||
var sigma=this.data.strength/3.0;
|
||||
var sigma2=sigma*sigma;
|
||||
this.data.strength_sig2_2sig2_gauss1[0]=this.data.strength;
|
||||
this.data.strength_sig2_2sig2_gauss1[1]=sigma2;
|
||||
this.data.strength_sig2_2sig2_gauss1[2]=2.0*sigma2;
|
||||
this.data.strength_sig2_2sig2_gauss1[3]=1.0/(2.0*Math.PI*sigma2);
|
||||
shader.strength_sig2_2sig2_gauss1=this.data.strength_sig2_2sig2_gauss1;
|
||||
}
|
||||
|
||||
__getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.BLUR*/0x10;});
|
||||
return BlurFilterActionGL;
|
||||
})(FilterActionGL)
|
||||
|
||||
|
||||
/**
|
||||
*@private
|
||||
*/
|
||||
//class laya.filters.webgl.GlowFilterActionGL extends laya.filters.webgl.FilterActionGL
|
||||
var GlowFilterActionGL=(function(_super){
|
||||
function GlowFilterActionGL(){
|
||||
this.data=null;
|
||||
this._initKey=false;
|
||||
this._textureWidth=0;
|
||||
this._textureHeight=0;
|
||||
GlowFilterActionGL.__super.call(this);
|
||||
}
|
||||
|
||||
__class(GlowFilterActionGL,'laya.filters.webgl.GlowFilterActionGL',_super);
|
||||
var __proto=GlowFilterActionGL.prototype;
|
||||
Laya.imps(__proto,{"laya.filters.IFilterActionGL":true})
|
||||
__proto.setValueMix=function(shader){}
|
||||
__proto.apply3d=function(scope,sprite,context,x,y){
|
||||
var b=scope.getValue("bounds");
|
||||
scope.addValue("color",this.data.getColor());
|
||||
var w=b.width,h=b.height;
|
||||
this._textureWidth=w;
|
||||
this._textureHeight=h;
|
||||
var shaderValue;
|
||||
var mat=Matrix.TEMP;
|
||||
mat.identity();
|
||||
shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
|
||||
shaderValue.setFilters([this.data]);
|
||||
context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue,null);
|
||||
shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
|
||||
context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue);
|
||||
return null;
|
||||
}
|
||||
|
||||
__proto.setSpriteWH=function(sprite){
|
||||
this._textureWidth=sprite.width;
|
||||
this._textureHeight=sprite.height;
|
||||
}
|
||||
|
||||
__proto.setValue=function(shader){
|
||||
shader.u_offsetX=this.data.offX;
|
||||
shader.u_offsetY=-this.data.offY;
|
||||
shader.u_strength=1.0;
|
||||
shader.u_blurX=this.data.blur;
|
||||
shader.u_blurY=this.data.blur;
|
||||
shader.u_textW=this._textureWidth;
|
||||
shader.u_textH=this._textureHeight;
|
||||
shader.u_color=this.data.getColor();
|
||||
}
|
||||
|
||||
__getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.GLOW*/0x08;});
|
||||
GlowFilterActionGL.tmpTarget=function(scope,sprite,context,x,y){
|
||||
var b=scope.getValue("bounds");
|
||||
var out=scope.getValue("out");
|
||||
out.end();
|
||||
var tmpTarget=RenderTarget2D.create(b.width,b.height);
|
||||
tmpTarget.start();
|
||||
var color=scope.getValue("color");
|
||||
if (color){
|
||||
tmpTarget.clear(color[0],color[1],color[2],0);
|
||||
}
|
||||
scope.addValue("tmpTarget",tmpTarget);
|
||||
}
|
||||
|
||||
GlowFilterActionGL.startOut=function(scope,sprite,context,x,y){
|
||||
var tmpTarget=scope.getValue("tmpTarget");
|
||||
tmpTarget.end();
|
||||
var out=scope.getValue("out");
|
||||
out.start();
|
||||
var color=scope.getValue("color");
|
||||
if (color){
|
||||
out.clear(color[0],color[1],color[2],0);
|
||||
}
|
||||
}
|
||||
|
||||
GlowFilterActionGL.recycleTarget=function(scope,sprite,context,x,y){
|
||||
var src=scope.getValue("src");
|
||||
var tmpTarget=scope.getValue("tmpTarget");
|
||||
tmpTarget.recycle();
|
||||
}
|
||||
|
||||
return GlowFilterActionGL;
|
||||
})(FilterActionGL)
|
||||
|
||||
|
||||
Laya.__init([WebGLFilter]);
|
||||
})(window,document,Laya);
|
||||
|
||||
if (typeof define === 'function' && define.amd){
|
||||
define('laya.core', ['require', "exports"], function(require, exports) {
|
||||
'use strict';
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
for (var i in Laya) {
|
||||
var o = Laya[i];
|
||||
o && o.__isclass && (exports[i] = o);
|
||||
}
|
||||
});
|
||||
}
|
||||