Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
renderingEngine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王剑峰
renderingEngine
Commits
03035a71
Commit
03035a71
authored
Dec 26, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交一下
parent
f70709ec
Changes
20
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1088 additions
and
503 deletions
+1088
-503
engine.js
debug/engine.js
+696
-347
engine.js.map
debug/engine.js.map
+1
-1
renderingengine.iml
renderingengine.iml
+3
-1
Container.ts
src/2d/display/Container.ts
+61
-1
Sprite.ts
src/2d/display/Sprite.ts
+26
-25
TextField.ts
src/2d/text/TextField.ts
+100
-25
index.ts
src/2d/utils/index.ts
+1
-1
index.ts
src/index.ts
+2
-0
Process.ts
src/zeroing/behavior-runtime/Process.ts
+1
-2
scripts.ts
src/zeroing/decorators/scripts.ts
+1
-1
GameStage.ts
src/zeroing/game-warpper/GameStage.ts
+8
-9
LoadingView.ts
src/zeroing/game-warpper/LoadingView.ts
+38
-0
assets-manager.ts
src/zeroing/game-warpper/assets-manager.ts
+23
-8
data-center.ts
src/zeroing/game-warpper/data-center.ts
+12
-3
TextInput.ts
src/zeroing/game-warpper/nodes/TextInput.ts
+47
-39
sound.ts
src/zeroing/game-warpper/sound.ts
+34
-10
index.ts
src/zeroing/index.ts
+3
-2
launcher.ts
src/zeroing/launcher.ts
+24
-7
node-utils.ts
src/zeroing/node-utils.ts
+0
-18
utils.ts
src/zeroing/utils/utils.ts
+7
-3
No files found.
debug/engine.js
View file @
03035a71
This diff is collapsed.
Click to expand it.
debug/engine.js.map
View file @
03035a71
This diff is collapsed.
Click to expand it.
renderingengine.iml
View file @
03035a71
...
...
@@ -2,7 +2,9 @@
<module
type=
"WEB_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
/>
<content
url=
"file://$MODULE_DIR$"
>
<excludeFolder
url=
"file://$MODULE_DIR$/dist"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
...
...
src/2d/display/Container.ts
View file @
03035a71
...
...
@@ -184,7 +184,7 @@ export default class Container extends DisplayObject {
* 是否含有child
* @param child
*/
contains
(
child
:
DisplayObject
):
boolean
{
contains
(
child
:
DisplayObject
):
boolean
{
return
!!
this
.
getChildIndex
(
child
);
}
...
...
@@ -209,6 +209,66 @@ export default class Container extends DisplayObject {
return
this
.
children
[
index
];
}
/**
* 根据路径获取子节点
* @param path
* @param method
*/
getChildByPath
(
path
:
any
,
method
:
string
):
DisplayObject
{
if
(
!
path
)
{
return
null
;
}
let
p
=
this
;
while
(
path
.
length
>
0
)
{
let
segment
=
path
.
shift
();
p
=
p
[
method
](
segment
);
if
(
!
p
)
{
break
;
}
}
return
p
;
}
/**
* 根据名称路径获取子节点
* @param path
*/
getChildByNamePath
(
path
:
string
):
DisplayObject
{
const
pathArr
=
path
.
split
(
'/'
);
return
this
.
getChildByPath
(
pathArr
,
'getChildByName'
);
}
/**
* 根据索引路径获取子节点
* @param path
*/
getChildByIndexPath
(
path
:
string
):
DisplayObject
{
const
pathArr
=
path
.
split
(
'/'
).
map
(
seg
=>
parseInt
(
seg
));
return
this
.
getChildByPath
(
pathArr
,
'getChildAt'
);
}
/**
* 根据uuid搜索子节点
* @param uuid
*/
findChildByUUID
(
uuid
:
string
)
{
if
(
this
[
'uuid'
]
===
uuid
)
{
return
this
;
}
if
(
this
.
children
&&
this
.
children
.
length
>
0
)
{
for
(
let
child
of
this
.
children
)
{
if
(
child
.
findChildByUUID
){
let
target
=
child
.
findChildByUUID
(
uuid
);
if
(
target
)
{
return
target
;
}
}
}
}
}
/**
* 通过名字获取子级
* @param name
...
...
src/2d/display/Sprite.ts
View file @
03035a71
import
{
ObservablePoint
,
Point
,
Rectangle
}
from
'../math'
;
import
{
sign
,
TextureCache
}
from
'../utils'
;
import
{
ObservablePoint
,
Point
,
Rectangle
}
from
'../math'
;
import
{
sign
,
TextureCache
}
from
'../utils'
;
// import { BLEND_MODES } from '../const';
import
Texture
from
'../texture/Texture'
;
import
{
Event
}
from
'../events/Event'
;
import
{
Event
}
from
'../events/Event'
;
import
Container
from
'./Container'
;
import
{
DisplayObject
}
from
"./DisplayObject"
;
import
{
DisplayObject
}
from
"./DisplayObject"
;
import
CanvasRenderer
from
'../renderers/CanvasRenderer'
;
import
{
SCALE_MODES
}
from
'../const'
;
import
{
WebglRenderer
}
from
'../renderers/WebglRenderer'
;
import
{
SCALE_MODES
}
from
'../const'
;
import
{
WebglRenderer
}
from
'../renderers/WebglRenderer'
;
const
indices
=
new
Uint16Array
([
0
,
1
,
2
,
0
,
2
,
3
]);
/**
...
...
@@ -456,6 +456,7 @@ export default class Sprite extends Container {
get
tint
()
{
return
this
.
_tint
;
}
set
tint
(
value
)
{
if
(
value
===
this
.
_tint
)
return
;
this
.
_tint
=
value
;
...
...
src/2d/text/TextField.ts
View file @
03035a71
...
...
@@ -18,7 +18,6 @@ const padding = 10;
* @public
*/
export
class
TextField
extends
Sprite
{
canvas
:
HTMLCanvasElement
;
context
:
CanvasRenderingContext2D
;
/**
...
...
@@ -231,6 +230,8 @@ export class TextField extends Sprite {
private
_lineType
:
TEXT_lINETYPE
=
TEXT_lINETYPE
.
SINGLE
;
protected
_text
:
string
=
""
;
/**
* 文本内容
* @property text
...
...
@@ -244,7 +245,7 @@ export class TextField extends Sprite {
}
public
get
text
():
string
{
return
this
.
_t
ext
;
return
this
.
pureT
ext
;
}
protected
_setText
(
value
)
{
...
...
@@ -256,7 +257,49 @@ export class TextField extends Sprite {
}
}
protected
_text
:
string
=
""
;
protected
_textFlow
:
any
;
protected
_pureText
=
''
;
get
textFlow
():
any
{
return
this
.
_textFlow
;
}
set
textFlow
(
value
:
any
)
{
this
.
_textFlow
=
value
;
this
.
dirty
=
true
;
let
text
=
''
;
for
(
let
item
of
this
.
_textFlow
)
{
text
+=
item
.
text
;
}
this
.
_pureText
=
text
;
}
get
isPureText
()
{
return
!
this
.
_textFlow
||
this
.
_textFlow
.
length
==
0
;
}
get
pureText
()
{
return
this
.
isPureText
?
this
.
_text
:
this
.
_pureText
;
}
protected
getStyle
(
index
)
{
if
(
!
this
.
textFlow
)
{
return
null
;
}
let
targetItem
;
let
count
=
0
;
for
(
let
item
of
this
.
_textFlow
)
{
count
+=
item
.
text
.
length
;
if
(
index
<
count
)
{
targetItem
=
item
;
break
;
}
}
return
targetItem
.
style
;
}
/**
* 文本的css字体样式
...
...
@@ -292,7 +335,6 @@ export class TextField extends Sprite {
this
.
_size
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
size
():
number
{
...
...
@@ -314,7 +356,6 @@ export class TextField extends Sprite {
this
.
_fillColor
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
fillColor
():
any
{
...
...
@@ -336,7 +377,6 @@ export class TextField extends Sprite {
this
.
_strokeColor
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
strokeColor
():
string
{
...
...
@@ -358,7 +398,6 @@ export class TextField extends Sprite {
this
.
_stroke
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
stroke
():
number
{
...
...
@@ -380,7 +419,6 @@ export class TextField extends Sprite {
this
.
_italic
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
italic
():
boolean
{
...
...
@@ -402,7 +440,6 @@ export class TextField extends Sprite {
this
.
_bold
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
bold
():
boolean
{
...
...
@@ -423,7 +460,6 @@ export class TextField extends Sprite {
this
.
_border
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
border
():
boolean
{
...
...
@@ -512,8 +548,9 @@ export class TextField extends Sprite {
*/
public
updateText
():
void
{
let
s
:
TextField
=
this
;
let
text
=
s
.
_pureText
;
//如果没有文本
if
(
!
s
.
_
text
)
{
if
(
!
text
)
{
s
.
canvas
.
width
=
0
;
s
.
canvas
.
height
=
0
;
s
.
_localBoundsSelf
.
clear
();
...
...
@@ -521,12 +558,13 @@ export class TextField extends Sprite {
this
.
updateTexture
();
return
}
let
measureCache
=
{};
if
(
!
s
.
dirty
)
return
;
s
.
dirty
=
false
;
s
.
_
text
+=
""
;
text
+=
""
;
let
can
=
s
.
canvas
;
let
ctx
=
s
.
context
;
let
hardLines
:
any
=
s
.
_
text
.
toString
().
split
(
/
(?:\r\n
|
\r
|
\n)
/
);
let
hardLines
:
any
=
text
.
toString
().
split
(
/
(?:\r\n
|
\r
|
\n)
/
);
let
realLines
:
any
=
[];
s
.
realLines
=
realLines
;
s
.
_prepContext
(
ctx
);
...
...
@@ -534,7 +572,7 @@ export class TextField extends Sprite {
let
textWidth
=
s
.
_width
;
// let lineH = s._lineSpacing + s.size;
//单行文本时
if
(
s
.
_
text
.
indexOf
(
"
\n
"
)
<
0
&&
s
.
lineType
==
TEXT_lINETYPE
.
SINGLE
)
{
if
(
text
.
indexOf
(
"
\n
"
)
<
0
&&
s
.
lineType
==
TEXT_lINETYPE
.
SINGLE
)
{
realLines
[
realLines
.
length
]
=
hardLines
[
0
];
let
str
=
hardLines
[
0
];
let
lineW
=
s
.
_getMeasuredWidth
(
str
);
...
...
@@ -559,17 +597,13 @@ export class TextField extends Sprite {
}
}
else
{
//textWidth取每行最大值,如果没设置过textWidth
let
measureCache
=
{};
const
shouldMeasureTextWidth
=
!
textWidth
;
for
(
let
i
=
0
,
l
=
hardLines
.
length
;
i
<
l
;
i
++
)
{
let
str
=
hardLines
[
i
];
if
(
!
str
)
continue
;
let
lineWidth
=
0
;
for
(
let
char
of
str
)
{
let
charWidth
=
measureCache
[
char
];
if
(
charWidth
===
undefined
)
{
charWidth
=
measureCache
[
char
]
=
s
.
_getMeasuredWidth
(
char
);
}
let
charWidth
=
measureChar
(
char
);
lineWidth
+=
charWidth
;
}
if
(
shouldMeasureTextWidth
)
{
...
...
@@ -630,13 +664,46 @@ export class TextField extends Sprite {
upY
=
s
.
_height
-
trueHeight
;
}
}
let
index
=
0
;
for
(
let
i
=
0
;
i
<
realLines
.
length
;
i
++
)
{
let
line
=
realLines
[
i
];
if
(
s
.
isPureText
)
{
let
y
=
upY
+
i
*
lineH
;
if
(
s
.
stroke
)
{
ctx
.
strokeStyle
=
s
.
strokeColor
;
ctx
.
lineWidth
=
s
.
stroke
*
2
;
ctx
.
strokeText
(
realLines
[
i
],
0
,
upY
+
i
*
lineH
,
maxW
);
ctx
.
strokeText
(
line
,
0
,
y
,
maxW
);
}
ctx
.
fillText
(
line
,
0
,
y
,
maxW
);
}
else
{
let
x
=
0
;
for
(
let
j
=
0
,
lj
=
line
.
length
;
j
<
lj
;
j
++
)
{
const
char
=
line
[
j
];
let
style
=
s
.
getStyle
(
index
);
if
(
style
)
{
if
(
style
.
hasOwnProperty
(
'color'
))
{
ctx
.
fillStyle
=
style
.
color
;
}
if
(
style
.
hasOwnProperty
(
'stroke'
))
{
ctx
.
lineWidth
=
style
.
stroke
*
2
;
}
if
(
style
.
hasOwnProperty
(
'strokeColor'
))
{
ctx
.
strokeStyle
=
style
.
strokeColor
;
}
}
else
{
ctx
.
fillStyle
=
s
.
fillColor
;
ctx
.
lineWidth
=
s
.
stroke
;
ctx
.
strokeStyle
=
s
.
strokeColor
;
}
let
y
=
upY
+
i
*
lineH
;
if
(
ctx
.
lineWidth
>
0
)
{
ctx
.
strokeText
(
char
,
x
,
y
);
}
ctx
.
fillText
(
char
,
x
,
y
);
x
+=
measureChar
(
char
);
index
++
;
}
}
ctx
.
fillText
(
realLines
[
i
],
0
,
upY
+
i
*
lineH
,
maxW
);
}
//offset用_anchorTexture代替
s
.
offsetX
=
-
padding
;
...
...
@@ -651,7 +718,15 @@ export class TextField extends Sprite {
s
.
_localBoundsSelf
.
width
=
maxW
;
s
.
_localBoundsSelf
.
height
=
maxH
;
//修改texture及baseTexture属性
s
.
updateTexture
()
s
.
updateTexture
();
function
measureChar
(
char
)
{
let
w
=
measureCache
[
char
];
if
(
w
===
undefined
)
{
w
=
measureCache
[
char
]
=
s
.
_getMeasuredWidth
(
char
);
}
return
w
;
}
}
/**
...
...
src/2d/utils/index.ts
View file @
03035a71
...
...
@@ -8,7 +8,7 @@ import { BLEND_MODES, DATA_URI, RENDERER_TYPE, URL_FILE_EXTENSION } from "../con
export
*
from
'./twiddle'
;
export
{
default
as
toDisplayDataURL
}
from
"./toDisplayDataURL"
;
export
{
default
as
determineCrossOrigin
}
from
'./determineCrossOrigin'
;
export
*
from
'./DrawAllToCanvas'
let
nextUid
=
0
;
...
...
src/index.ts
View file @
03035a71
...
...
@@ -24,6 +24,8 @@ export * from "./2d/ui";
export
*
from
'./2d/tween'
export
*
from
'./2d/net'
export
{
GlobalPro
,
DrawAllToCanvas
}
from
'./2d/utils'
export
{
default
as
toDisplayDataURL
}
from
"./2d/utils/toDisplayDataURL"
;
export
{
inputFeildIosEnable
}
from
"./2d/utils/index"
...
...
src/zeroing/behavior-runtime/Process.ts
View file @
03035a71
...
...
@@ -5,7 +5,6 @@
*/
import
{
VM
}
from
"./VM"
;
import
{
getDataByPath
,
linkedFlag
,
nodeScheme
,
objClone
}
from
"../utils"
;
import
{
findNodeByUUID
}
from
"../node-utils"
;
import
{
dataCenter
}
from
"../game-warpper/data-center"
;
import
{
env
}
from
"../game-warpper/enviroment"
;
import
{
getLogSwitch
,
Logs
}
from
"../log-switch"
;
...
...
@@ -231,7 +230,7 @@ export class Process {
}
else
if
(
value
&&
value
.
indexOf
&&
value
.
indexOf
(
nodeScheme
)
===
0
)
{
let
uuid
=
value
.
replace
(
nodeScheme
,
''
);
if
(
uuid
)
{
props
[
key
]
=
findNodeByUUID
(
this
.
_vm
.
globalContext
.
gameStage
,
uuid
);
props
[
key
]
=
this
.
_vm
.
globalContext
.
gameStage
.
findChildByUUID
(
uuid
);
}
}
else
if
(
originProps
[
key
]
!==
undefined
)
{
props
[
key
]
=
originProps
[
key
];
...
...
src/zeroing/decorators/scripts.ts
View file @
03035a71
...
...
@@ -15,7 +15,7 @@ const scriptDefs = {};
*/
export
function
applyScript
(
ctor
:
Function
)
{
ctor
.
prototype
.
applyScripts
=
function
()
{
let
scriptsProxy
=
this
.
scripts
Proxy
=
new
ScriptsProxy
(
this
);
let
scriptsProxy
=
this
.
scripts
=
new
ScriptsProxy
(
this
);
this
.
addEventListener
(
Event
.
ENTER_FRAME
,
scriptsProxy
.
onEnterFrame
,
scriptsProxy
);
this
.
addEventListener
(
Event
.
ADDED_TO_STAGE
,
scriptsProxy
.
onAddedToStage
,
scriptsProxy
);
...
...
src/zeroing/game-warpper/GameStage.ts
View file @
03035a71
...
...
@@ -8,14 +8,13 @@ import {loadAssets} from "./assets-manager";
import
{
instantiate
}
from
"./view-interpreter"
;
import
{
dataCenter
,
DataCenter
}
from
"./data-center"
;
import
{
setProcessMetaLibs
}
from
"../behavior-runtime"
;
import
{
registerScripts
}
from
".."
;
import
{
Tween
}
from
"../../2d/tween"
;
import
{
Rect
}
from
"./nodes"
;
import
{
injectEnv
}
from
"./enviroment"
;
import
{
registerCustomModuleFromConfig
}
from
"./custom-module"
;
import
{
hideLoadingView
,
showLoadingView
}
from
"./loading-view"
;
import
{
Toast
}
from
"./Toast"
;
import
{
arrayFind
}
from
"../utils"
;
import
{
registerScripts
}
from
".."
;
import
{
registerCustomModuleFromConfig
}
from
"./custom-module"
;
/**
* 游戏舞台
...
...
@@ -111,7 +110,6 @@ export class GameStage extends Container {
}
}
showLoadingView
();
await
loadAssets
(
assets
,
p
).
catch
(
e
=>
{
console
.
log
(
e
);
});
...
...
@@ -124,7 +122,6 @@ export class GameStage extends Container {
}
}
}
hideLoadingView
();
this
.
start
();
...
...
@@ -157,10 +154,12 @@ export class GameStage extends Container {
}
setProcessMetaLibs
(
processes
,
builtinProcesses
);
setTimeout
(()
=>
{
let
sceneEntry
=
this
.
instantiateView
(
entrySceneView
);
if
(
sceneEntry
)
{
this
.
_sceneContainer
.
push
(
sceneEntry
);
}
})
}
/**
...
...
src/zeroing/game-warpper/
loading-v
iew.ts
→
src/zeroing/game-warpper/
LoadingV
iew.ts
View file @
03035a71
...
...
@@ -2,16 +2,6 @@
* Created by rockyl on 2019-11-22.
*/
/*const template = `
<div id="loadingWrapper" style="position: absolute; left: 0;top: 0;right: 0;bottom: 0;">
<div id="loadingTrack" style="width: 100px;height: 20px;border: 1px solid deepskyblue;">
<div id="loadingThumb">
</div>
</div>
</div>
`;*/
const
template
=
`
<div style="
position: absolute;
...
...
@@ -34,18 +24,15 @@ let container = document.createElement('div');
container
.
innerHTML
=
template
;
let
wrapper
=
container
.
removeChild
(
container
.
children
[
0
]);
export
function
showLoadingView
()
{
export
default
{
onProgress
(
done
,
total
)
{
if
(
!
wrapper
.
parentElement
)
{
document
.
body
.
appendChild
(
wrapper
);
}
}
export
function
hideLoadingView
()
{
},
onComplete
()
{
if
(
wrapper
.
parentElement
)
{
document
.
body
.
removeChild
(
wrapper
);
}
}
export
function
setLoadingViewProgress
(
current
,
total
)
{
},
}
src/zeroing/game-warpper/assets-manager.ts
View file @
03035a71
...
...
@@ -32,18 +32,18 @@ export function loadAssets(config, onProgress?, onComplete?) {
config
.
map
(
assetConfig
=>
{
assetsConfig
.
push
(
assetConfig
);
const
loadFunc
=
loaderMapping
[
assetConfig
.
ext
];
if
(
loadFunc
)
{
if
(
loadFunc
)
{
let
method
=
globalLoader
[
'load'
+
loadFunc
];
return
method
.
call
(
globalLoader
,
assetConfig
.
url
,
assetConfig
.
uuid
).
then
(
(
data
)
=>
{
(
data
)
=>
{
loaded
++
;
onProgress
&&
onProgress
(
loaded
,
total
);
},
(
error
)
=>
{
(
error
)
=>
{
failedList
.
push
(
assetConfig
.
url
);
}
);
}
else
{
}
else
{
loaded
++
;
onProgress
&&
onProgress
(
loaded
,
total
);
return
Promise
.
resolve
();
...
...
@@ -64,14 +64,29 @@ export function loadAssets(config, onProgress?, onComplete?) {
* 根据uuid获取素材配置
* @param uuid
*/
export
function
getAssetByUUID
(
uuid
)
{
return
arrayFind
(
assetsConfig
,
item
=>
item
.
uuid
===
uuid
);
export
function
getAssetByUUID
(
uuid
)
:
any
{
return
arrayFind
(
assetsConfig
,
item
=>
item
.
uuid
===
uuid
);
}
/**
* 根据name获取素材配置
* @param name
*/
export
function
getAssetByName
(
name
)
{
return
arrayFind
(
assetsConfig
,
item
=>
item
.
name
===
name
);
export
function
getAssetByName
(
name
):
any
{
let
result
=
arrayFind
(
assetsConfig
,
item
=>
item
.
name
===
name
);
if
(
result
)
{
return
result
;
}
else
{
for
(
let
assetConfig
of
assetsConfig
)
{
let
res
=
engine
.
globalLoader
.
get
(
assetConfig
.
url
);
if
(
res
&&
res
.
frames
)
{
for
(
let
key
in
res
.
frames
)
{
const
frame
=
res
.
frames
[
key
];
if
(
frame
.
name
===
name
)
{
return
{
url
:
key
};
}
}
}
}
}
}
src/zeroing/game-warpper/data-center.ts
View file @
03035a71
...
...
@@ -24,7 +24,7 @@ export class DataCenter extends EventDispatcher {
* @param origin
*/
registerGroup
(
name
,
origin
?)
{
return
this
.
store
[
name
]
=
origin
||
{}
;
return
this
.
store
[
name
]
=
origin
===
undefined
?
{}
:
origin
;
}
/**
...
...
@@ -50,7 +50,13 @@ export class DataCenter extends EventDispatcher {
* @param throwException
*/
getDataByPath
(
path
,
groupName
?,
throwException
?)
{
let
scope
=
groupName
===
undefined
?
this
.
store
:
this
.
getGroup
(
groupName
)
||
this
.
store
;
let
scope
;
if
(
groupName
===
undefined
)
{
scope
=
this
.
store
;
}
else
{
let
group
=
this
.
getGroup
(
groupName
);
scope
=
group
===
undefined
?
this
.
store
:
group
;
}
return
getDataByPath
(
scope
,
path
,
throwException
);
}
...
...
@@ -101,7 +107,7 @@ export class DataCenter extends EventDispatcher {
* @param dispatch
*/
increase
(
groupName
,
step
?,
path
?,
dispatch
=
true
)
{
if
(
step
<
0
||
step
>
0
)
{
if
(
step
<
0
||
step
>
0
)
{
let
data
:
any
=
this
.
getDataByPath
(
path
,
groupName
);
if
(
data
===
undefined
)
{
data
=
0
;
...
...
@@ -122,6 +128,9 @@ export class DataCenter extends EventDispatcher {
* @param dispatch
*/
mutate
(
groupName
,
data
?,
path
?,
dispatch
=
true
)
{
if
(
!
groupName
)
{
return
;
}
let
group
=
this
.
getGroup
(
groupName
);
if
(
!
group
)
{
...
...
src/zeroing/game-warpper/nodes/TextInput.ts
View file @
03035a71
...
...
@@ -7,15 +7,23 @@ import {Event} from "../../../2d/events/Event";
import
{
FloatDisplay
}
from
"../../../2d/display/FloatDisplay"
;
import
{
TextField
}
from
"../../../2d/text"
;
import
{
Point
}
from
"../../../2d/math"
;
import
{
dirtyFieldTrigger
}
from
"../../decorators"
;
import
{
VERTICAL_ALIGN
}
from
"../../.."
;
export
class
TextInput
extends
Label
{
private
_floatDisplay
:
FloatDisplay
;
private
_placeholderLabel
:
TextField
;
private
_input
:
any
;
private
_placeholder
:
string
=
''
;
private
_placeholderColor
:
any
=
'#666666'
;
private
_maxLength
:
number
;
@
dirtyFieldTrigger
placeholder
:
string
;
@
dirtyFieldTrigger
placeholderColor
:
any
=
'#666666'
;
@
dirtyFieldTrigger
maxLength
:
number
;
@
dirtyFieldTrigger
type
:
string
=
'text'
;
@
dirtyFieldTrigger
pattern
:
string
;
private
_oldFillColor
;
private
_oldStrokeColor
;
...
...
@@ -30,32 +38,21 @@ export class TextInput extends Label {
this
.
text
=
''
;
}
get
placeholder
():
string
{
return
this
.
_placeholder
;
}
set
placeholder
(
value
:
string
)
{
this
.
_placeholder
=
value
;
onModify
(
value
,
key
)
{
switch
(
key
)
{
case
'placeholder'
:
if
(
this
.
_placeholderLabel
)
{
this
.
_placeholderLabel
.
text
=
value
;
}
get
placeholderColor
():
any
{
return
this
.
_placeholderColor
;
}
set
placeholderColor
(
value
:
any
)
{
this
.
_placeholderColor
=
value
;
break
;
case
'placeholderColor'
:
if
(
this
.
_placeholderLabel
)
{
this
.
_placeholderLabel
.
fillColor
=
value
;
}
get
maxLength
():
number
{
return
this
.
_maxLength
;
}
set
maxLength
(
value
:
number
)
{
if
(
this
.
_maxLength
!=
value
){
this
.
_maxLength
=
value
;
break
;
case
'maxLength'
:
this
.
setMaxLength
();
break
;
}
}
...
...
@@ -76,7 +73,7 @@ export class TextInput extends Label {
input
.
addEventListener
(
'blur'
,
this
.
onBlur
);
let
pl
=
this
.
_placeholderLabel
=
new
TextField
();
pl
.
fillColor
=
this
.
_
placeholderColor
;
pl
.
fillColor
=
this
.
placeholderColor
;
this
.
verticalAlign
=
pl
.
verticalAlign
=
VERTICAL_ALIGN
.
MIDDLE
;
...
...
@@ -95,7 +92,7 @@ export class TextInput extends Label {
private
setMaxLength
()
{
let
value
=
this
.
_text
;
let
maxLength
=
this
.
_
maxLength
;
let
maxLength
=
this
.
maxLength
;
if
(
maxLength
>
0
&&
value
&&
value
.
length
>
maxLength
)
{
this
.
text
=
value
.
substr
(
0
,
maxLength
);
}
...
...
@@ -103,14 +100,14 @@ export class TextInput extends Label {
private
showPlaceholderLabel
(
value
)
{
let
pl
=
this
.
_placeholderLabel
;
if
(
value
)
{
if
(
value
)
{
let
pl
=
this
.
_placeholderLabel
;
if
(
pl
.
parent
)
{
pl
.
parent
.
removeChild
(
pl
);
}
}
else
{
}
else
{
if
(
!
pl
.
parent
)
{
pl
.
text
=
this
.
_
placeholder
;
pl
.
text
=
this
.
placeholder
;
pl
.
size
=
this
.
size
;
pl
.
font
=
this
.
font
;
this
.
addChildAt
(
pl
,
0
);
...
...
@@ -147,12 +144,23 @@ export class TextInput extends Label {
this
.
_floatDisplay
.
alpha
=
1
;
input
.
style
.
pointerEvents
=
'auto'
;
if
(
this
.
_maxLength
>
0
){
input
.
maxLength
=
this
.
_maxLength
;
}
else
{
const
maxLength
=
this
.
maxLength
;
if
(
maxLength
>
0
)
{
input
.
maxLength
=
maxLength
;
}
else
{
input
.
removeAttribute
(
'maxLength'
)
}
if
(
this
.
pattern
)
{
input
.
pattern
=
this
.
pattern
;
}
else
{
input
.
removeAttribute
(
'pattern'
)
}
if
(
this
.
type
)
{
input
.
type
=
this
.
type
;
}
input
.
focus
();
this
.
dispatchEvent
(
Event
.
FOCUS
);
...
...
@@ -178,8 +186,8 @@ export class TextInput extends Label {
this
.
setBlur
();
};
private
onClickStage
(
e
){
if
(
e
.
currentTarget
!==
this
)
{
private
onClickStage
(
e
)
{
if
(
e
.
currentTarget
!==
this
)
{
this
.
setBlur
();
}
}
...
...
src/zeroing/game-warpper/sound.ts
View file @
03035a71
...
...
@@ -7,35 +7,59 @@ import {injectProperties} from "../utils";
const
instances
=
{};
export
function
playSound
(
uuid
,
options
=
{},
name
?)
{
export
function
playSound
(
uuid
,
options
:
any
=
{},
name
?)
{
let
assetConfig
=
getAssetByUUID
(
uuid
);
if
(
assetConfig
)
{
let
url
=
assetConfig
.
url
;
let
opts
:
any
=
{
src
:
[
url
],
autoplay
:
tru
e
,
autoplay
:
fals
e
,
};
injectProperties
(
opts
,
options
);
let
sound
=
new
Howl
(
opts
)
;
const
key
=
name
||
uuid
;
if
(
name
!==
undefined
)
{
instances
[
name
]
=
sound
;
const
{
keep
=
false
}
=
opts
;
let
sound
;
if
(
keep
)
{
const
data
=
instances
[
key
];
if
(
data
)
{
sound
=
data
.
sound
;
}
}
if
(
!
sound
)
{
sound
=
new
Howl
(
opts
);
}
instances
[
key
]
=
{
sound
,
keep
,
};
if
(
!
keep
)
{
sound
.
on
(
'end'
,
function
()
{
de
lete
instances
[
name
]
;
de
stroySound
(
key
)
;
});
}
sound
.
play
();
return
sound
;
}
}
export
function
stopSound
(
name
){
let
sound
=
instances
[
name
];
if
(
sound
)
{
export
function
stopSound
(
name
)
{
let
{
sound
,
keep
}
=
instances
[
name
];
if
(
sound
)
{
sound
.
stop
();
delete
instances
[
name
];
if
(
!
keep
)
{
destroySound
(
name
);
}
}
}
export
function
destroySound
(
name
)
{
delete
instances
[
name
];
}
src/zeroing/index.ts
View file @
03035a71
...
...
@@ -11,10 +11,11 @@ export * from './game-warpper'
export
*
from
'./behavior-runtime'
export
*
from
'./web'
export
*
from
'./log-switch'
import
{
instantiate
}
from
'./game-warpper/view-interpreter'
import
{
instantiate
,
registerNodeType
}
from
'./game-warpper/view-interpreter'
export
{
Howl
,
Howler
}
from
'howler'
;
export
{
instantiate
instantiate
,
registerNodeType
,
}
src/zeroing/launcher.ts
View file @
03035a71
...
...
@@ -8,17 +8,18 @@ import {GameStage} from "./game-warpper";
import
{
setGlobalContext
}
from
"./behavior-runtime"
;
import
{
globalLoader
}
from
"../2d/loader/Loader"
;
import
{
Event
}
from
"../2d/events/Event"
;
import
builtinLoadingView
from
"./game-warpper/LoadingView"
;
export
let
gameStage
:
GameStage
;
export
function
launch
(
url
,
onAssetsProgress
,
onAssetsComplete
,
onStart
)
{
export
function
launch
(
url
,
loadingDelegate
?,
onStart
?
)
{
return
globalLoader
.
loadJson
(
url
)
.
then
(
config
=>
{
return
launchWithConfig
(
config
,
onAssetsProgress
,
onAssetsComple
te
,
onStart
);
return
launchWithConfig
(
config
,
loadingDelega
te
,
onStart
);
});
}
export
function
launchWithLocalStorage
(
id
,
onAssetsProgress
,
onAssetsComplete
,
onStart
)
{
export
function
launchWithLocalStorage
(
id
,
loadingDelegate
?,
onStart
?
)
{
const
storeKey
=
'preview-project-'
+
id
;
let
storeData
=
localStorage
.
getItem
(
storeKey
);
let
{
data
,
processes
,
scripts
,
customs
,}
=
JSON
.
parse
(
storeData
);
...
...
@@ -27,10 +28,20 @@ export function launchWithLocalStorage(id, onAssetsProgress, onAssetsComplete, o
registerScripts
(
scripts
);
registerCustomModuleFromConfig
(
customs
);
return
launchWithConfig
(
data
,
onAssetsProgress
,
onAssetsComple
te
,
onStart
);
return
launchWithConfig
(
data
,
loadingDelega
te
,
onStart
);
}
export
function
launchWithConfig
(
config
,
onAssetsProgress
,
onAssetsComplete
,
onStart
)
{
export
function
launchWithWindowVariable
(
name
,
loadingDelegate
?,
onStart
?)
{
let
{
data
,
processes
,
scripts
,
customs
,}
=
window
[
name
];
setProcessMetaLibs
(
processes
);
registerScripts
(
scripts
);
registerCustomModuleFromConfig
(
customs
);
return
launchWithConfig
(
data
,
loadingDelegate
,
onStart
);
}
export
function
launchWithConfig
(
config
,
loadingDelegate
?,
onStart
?)
{
return
new
Promise
(
resolve
=>
{
const
{
containerId
,
designWidth
,
designHeight
,
frameRate
,
scaleMode
,
rendererType
,}
=
config
.
options
;
let
stage
=
window
[
'stage'
]
=
new
Stage
(
...
...
@@ -39,7 +50,7 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS
designHeight
||
1334
,
frameRate
||
60
,
scaleMode
||
StageScaleMode
.
FIXED_WIDTH
,
rendererType
||
RENDERER_TYPE
.
WEBGL
rendererType
||
RENDERER_TYPE
.
WEBGL
,
);
Stage
.
flushAll
();
...
...
@@ -50,7 +61,13 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete, onS
});
stage
.
addChild
(
gameStage
);
gameStage
.
launch
(
config
,
onAssetsProgress
,
onAssetsComplete
,
onStart
);
let
delegate
=
loadingDelegate
||
builtinLoadingView
;
gameStage
.
launch
(
config
,
function
(
done
,
total
){
delegate
.
onProgress
&&
delegate
.
onProgress
(
done
,
total
)
},
function
(){
delegate
.
onComplete
&&
delegate
.
onComplete
();
},
onStart
);
});
resolve
(
gameStage
);
...
...
src/zeroing/node-utils.ts
deleted
100644 → 0
View file @
f70709ec
/**
* Created by rockyl on 2019-11-13.
*/
export
function
findNodeByUUID
(
node
,
uuid
)
{
if
(
node
.
uuid
===
uuid
)
{
return
node
;
}
if
(
node
.
children
&&
node
.
children
.
length
>
0
){
for
(
let
child
of
node
.
children
)
{
let
target
=
findNodeByUUID
(
child
,
uuid
);
if
(
target
)
{
return
target
;
}
}
}
}
src/zeroing/utils/utils.ts
View file @
03035a71
...
...
@@ -134,6 +134,10 @@ export function obj2query(obj: any): string {
return
arr
.
join
(
'&'
);
}
function
requireForCJS
(
id
){
return
window
[
id
];
}
/**
* 导入cjs包装的代码
* @param code
...
...
@@ -141,11 +145,11 @@ export function obj2query(obj: any): string {
*/
export
function
importCJSCode
(
code
,
node
?)
{
if
(
node
)
{
let
create
=
new
Function
(
'module'
,
code
);
let
create
=
new
Function
(
'module'
,
'require'
,
code
);
let
module
=
{
exports
:
{},
};
create
(
module
);
create
(
module
,
requireForCJS
);
return
module
.
exports
;
}
else
{
let
create
=
new
Function
(
'exports'
,
code
);
...
...
@@ -253,7 +257,7 @@ export function strShort(str, limit, replace = '…'){
export
function
instantiateScript
(
node
,
ScriptConfig
)
{
const
{
script
:
scriptName
,
props
,
disabled
}
=
ScriptConfig
;
const
script
=
node
.
scripts
Proxy
.
add
(
scriptName
,
props
,
disabled
);
const
script
=
node
.
scripts
.
add
(
scriptName
,
props
,
disabled
);
}
export
function
injectProperties
(
target
,
source
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment