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
eb2f29c0
Commit
eb2f29c0
authored
Dec 04, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
过程、脚本、自定义模块代码抽离功能
parent
e9c9c132
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
391 additions
and
102 deletions
+391
-102
engine.js
debug/engine.js
+196
-41
engine.js.map
debug/engine.js.map
+1
-1
engine.ebd02dd4ddd6da8037464b8067061b2a2d4e5c90.js
dist/engine.ebd02dd4ddd6da8037464b8067061b2a2d4e5c90.js
+0
-1
package.json
package.json
+1
-1
EventDispatcher.ts
src/2d/events/EventDispatcher.ts
+1
-1
net.ts
src/2d/net.ts
+3
-0
TextField.ts
src/2d/text/TextField.ts
+16
-5
Process.ts
src/zeroing/behavior-runtime/Process.ts
+6
-5
auto-adjust.ts
src/zeroing/decorators/auto-adjust.ts
+1
-1
scripts.ts
src/zeroing/decorators/scripts.ts
+23
-7
GameStage.ts
src/zeroing/game-warpper/GameStage.ts
+8
-0
Toast.ts
src/zeroing/game-warpper/Toast.ts
+64
-22
data-center.ts
src/zeroing/game-warpper/data-center.ts
+39
-13
Image.ts
src/zeroing/game-warpper/nodes/Image.ts
+5
-2
Label.ts
src/zeroing/game-warpper/nodes/Label.ts
+26
-1
utils.ts
src/zeroing/utils/utils.ts
+1
-1
No files found.
debug/engine.js
View file @
eb2f29c0
This diff is collapsed.
Click to expand it.
debug/engine.js.map
View file @
eb2f29c0
This diff is collapsed.
Click to expand it.
dist/engine.ebd02dd4ddd6da8037464b8067061b2a2d4e5c90.js
deleted
100644 → 0
View file @
e9c9c132
This source diff could not be displayed because it is too large. You can
view the blob
instead.
package.json
View file @
eb2f29c0
...
...
@@ -25,7 +25,7 @@
},
"scripts"
:
{
"build-webpack"
:
"webpack"
,
"rollup"
:
"rollup -c -o dist/engine.js --environment BUILD:production"
,
"rollup"
:
"rollup -c -o dist/engine.js --environment BUILD:production
1
"
,
"rollup:debug"
:
"rollup -c -m "
,
"rename"
:
"node scripts/rename-hash.js dist/engine.js"
,
"build"
:
"rm -rf dist&&yarn rollup && yarn rename"
,
...
...
src/2d/events/EventDispatcher.ts
View file @
eb2f29c0
...
...
@@ -98,7 +98,7 @@ export class EventDispatcher extends HashObject {
for
(
var
i
=
0
,
len
=
eventTypes
[
type
].
length
;
i
<
len
;
i
++
)
{
let
ee
:
EE
=
eventTypes
[
type
][
i
]
if
(
ee
.
fn
===
listener
&&
ee
.
context
===
context
)
{
console
.
log
(
"已添加过该事件"
)
//
console.log("已添加过该事件")
return
}
}
...
...
src/2d/net.ts
View file @
eb2f29c0
...
...
@@ -31,6 +31,9 @@ export function httpRequest(callback: Function, url: string, method: string = 'g
url
=
urlJoin
(
url
,
queryStr
);
}
_req
.
open
(
method
,
url
,
true
);
if
(
!
isGet
){
_req
.
setRequestHeader
(
'Content-Type'
,
'application/x-www-form-urlencoded'
)
}
_req
.
responseType
=
type
;
if
(
isGet
)
{
_req
.
send
();
...
...
src/2d/text/TextField.ts
View file @
eb2f29c0
...
...
@@ -229,7 +229,7 @@ export class TextField extends Sprite {
return
this
.
_lineType
;
}
private
_lineType
:
TEXT_lINETYPE
=
TEXT_lINETYPE
.
SINGLE
;
private
_lineType
:
TEXT_lINETYPE
=
TEXT_lINETYPE
.
MULTI
;
/**
* 文本内容
...
...
@@ -252,6 +252,8 @@ export class TextField extends Sprite {
protected
_setText
(
value
)
{
this
.
_text
=
value
;
this
.
dirty
=
true
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
protected
_text
:
string
=
""
;
...
...
@@ -558,22 +560,31 @@ export class TextField extends Sprite {
}
}
else
{
//textWidth取每行最大值,如果没设置过textWidth
let
measureCache
=
{};
if
(
!
textWidth
)
{
for
(
let
i
=
0
,
l
=
hardLines
.
length
;
i
<
l
;
i
++
)
{
let
str
=
hardLines
[
i
];
if
(
!
str
)
continue
;
textWidth
=
Math
.
max
(
s
.
_getMeasuredWidth
(
str
),
textWidth
);
let
lineWidth
=
0
;
for
(
let
char
of
str
)
{
let
charWidth
=
measureCache
[
char
];
if
(
charWidth
===
undefined
)
{
charWidth
=
measureCache
[
char
]
=
s
.
_getMeasuredWidth
(
char
);
}
lineWidth
+=
charWidth
;
}
textWidth
=
Math
.
max
(
lineWidth
,
textWidth
);
}
}
for
(
let
i
=
0
,
l
=
hardLines
.
length
;
i
<
l
;
i
++
)
{
let
str
=
hardLines
[
i
];
if
(
!
str
)
continue
;
let
w
=
s
.
_getMeasuredWidth
(
str
[
0
])
;
let
w
=
measureCache
[
str
[
0
]]
;
let
lineStr
=
str
[
0
];
let
wordW
=
0
;
let
strLen
=
str
.
length
;
for
(
let
j
=
1
;
j
<
strLen
;
j
++
)
{
wordW
=
ctx
.
measureText
(
str
[
j
]).
width
;
wordW
=
measureCache
[
str
[
j
]]
;
w
+=
wordW
;
if
(
w
>
textWidth
)
{
realLines
[
realLines
.
length
]
=
lineStr
;
...
...
@@ -633,7 +644,7 @@ export class TextField extends Sprite {
this
.
anchorTexture
=
{
x
:
(
padding
+
0.5
)
/
can
.
width
,
y
:
padding
/
can
.
height
}
//
document.body.appendChild(can)
//document.body.appendChild(can)
// s._bounds.height = maxH;
// s._bounds.width = maxW;
//x,y都是0
...
...
src/zeroing/behavior-runtime/Process.ts
View file @
eb2f29c0
...
...
@@ -96,15 +96,16 @@ export class Process {
this
.
updateProps
(
this
.
_config
.
props
=
{},
payload
,
this
.
_originProps
,
this
.
_meta
.
props
);
if
(
metaConfig
.
script
)
{
let
func
;
if
(
metaConfig
.
script
.
indexOf
(
linkScheme
)
===
0
)
{
if
(
metaConfig
.
script
.
indexOf
(
linkScheme
)
===
0
)
{
func
=
this
.
_vm
.
getScript
(
metaConfig
.
script
.
replace
(
linkScheme
,
''
));
}
else
{
}
else
{
func
=
new
Function
(
'args'
,
'props'
,
'target'
,
'global'
,
'vm'
,
warpAsyncScript
(
metaConfig
.
script
));
}
if
(
!
func
)
{
if
(
!
func
)
{
console
.
log
();
}
let
globalContext
=
this
.
_vm
.
globalContext
;
globalContext
.
dataCenter
=
globalContext
.
gameStage
.
dataCenter
;
result
=
await
func
(
payload
,
this
.
_config
.
props
,
this
.
_target
,
globalContext
,
this
.
_vm
);
}
}
else
{
...
...
@@ -193,7 +194,7 @@ export class Process {
let
linkedValue
=
this
.
resolveLinkedProp
(
value
,
key
);
if
(
linkedValue
!==
undefined
)
{
props
[
key
]
=
linkedValue
;
}
else
{
}
else
{
props
[
key
]
=
undefined
;
}
break
;
...
...
@@ -219,7 +220,7 @@ export class Process {
if
(
uuid
)
{
props
[
key
]
=
findNodeByUUID
(
this
.
_vm
.
globalContext
.
gameStage
,
uuid
);
}
}
else
if
(
originProps
[
key
]
!==
undefined
)
{
}
else
if
(
originProps
[
key
]
!==
undefined
)
{
props
[
key
]
=
originProps
[
key
];
}
...
...
src/zeroing/decorators/auto-adjust.ts
View file @
eb2f29c0
...
...
@@ -68,7 +68,7 @@ class AdjustProxy {
}
onRemovedFromStage
(
e
)
{
this
.
_host
.
parent
.
removeEventListener
(
Event
.
RESIZE
,
this
.
onResize
);
//
this._host.parent.removeEventListener(Event.RESIZE, this.onResize);
this
.
_host
.
removeEventListener
(
Event
.
RESIZE
,
this
.
onResize
,
this
);
this
.
_host
.
removeEventListener
(
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
);
}
...
...
src/zeroing/decorators/scripts.ts
View file @
eb2f29c0
...
...
@@ -28,12 +28,27 @@ export function applyScript(ctor: Function) {
*/
export
class
ScriptBase
{
private
_host
:
Container
;
disabled
:
boolean
;
private
_
disabled
:
boolean
;
get
host
()
{
return
this
.
_host
}
get
disabled
(){
return
this
.
_disabled
;
}
set
disabled
(
v
){
if
(
this
.
_disabled
!==
v
)
{
this
.
_disabled
=
v
;
if
(
this
.
_disabled
)
{
this
.
sleep
();
}
else
{
this
.
awake
();
}
}
}
mounted
()
{
}
...
...
@@ -63,7 +78,7 @@ export class ScriptBase {
export
function
registerScriptDef
(
id
,
def
)
{
scriptDefs
[
id
]
=
def
;
Object
.
defineProperty
(
def
,
'disabled'
,
{
/*
Object.defineProperty(def, 'disabled', {
get: function () {
return !!this._disabled;
},
...
...
@@ -79,8 +94,7 @@ export function registerScriptDef(id, def) {
}
},
enumerable: true,
configurable
:
true
});
});*/
}
export
function
registerScripts
(
scripts
)
{
...
...
@@ -158,10 +172,12 @@ class ScriptsProxy {
/**
* 根据名字获取脚本
* @param
name
* @param
id
*/
get
(
name
):
ScriptBase
[]
{
return
this
.
_scripts
.
filter
(
script
=>
script
.
constructor
[
'name'
]
===
name
);
get
(
id
):
ScriptBase
[]
{
return
this
.
_scripts
.
filter
(
script
=>
{
return
script
.
constructor
[
'id'
]
===
id
;
});
}
/**
...
...
src/zeroing/game-warpper/GameStage.ts
View file @
eb2f29c0
...
...
@@ -47,6 +47,7 @@ export class GameStage extends Container {
this
.
addChild
(
this
.
_sceneContainer
=
new
StackContainer
());
this
.
addChild
(
blackLayer
);
this
.
addChild
(
this
.
_popupContainer
=
new
StackContainer
(
false
));
this
.
addChild
(
this
.
_toast
=
new
Toast
(
this
));
blackLayer
[
'percentWidth'
]
=
100
;
blackLayer
[
'percentHeight'
]
=
100
;
...
...
@@ -74,6 +75,13 @@ export class GameStage extends Container {
return
this
.
_popupContainer
;
}
/**
* Toast提示
*/
get
toast
():
Toast
{
return
this
.
_toast
;
}
/**
* 数据中心
*/
...
...
src/zeroing/game-warpper/Toast.ts
View file @
eb2f29c0
...
...
@@ -5,6 +5,7 @@
import
{
Container
}
from
"../../2d/display"
;
import
{
GameStage
}
from
"./GameStage"
;
import
{
Label
,
Rect
}
from
"./nodes"
;
import
{
Tween
}
from
"../../2d/tween"
;
export
class
Toast
extends
Container
{
private
_contentSample
:
Container
;
...
...
@@ -15,50 +16,91 @@ export class Toast extends Container {
constructor
(
gameStage
:
GameStage
)
{
super
();
this
.
_gameStage
=
gameStage
;
this
.
horizonCenter
=
0
;
this
.
verticalCenter
=
0
;
}
show
(
props
)
{
show
(
props
:
any
=
{}
)
{
if
(
!
props
.
text
)
{
return
;
}
const
{
text
,
duration
,
viewName
}
=
props
;
let
contentView
=
this
.
getContent
(
viewName
);
let
contentView
=
this
.
getContent
(
props
.
viewName
);
let
lab
=
contentView
.
getChildByName
(
'lab'
);
if
(
!
lab
)
{
console
.
warn
(
'[lab] child no exists on toast view'
);
return
;
}
const
{
text
,
padding
=
10
,
duration
=
1000
,
showDuration
=
300
,
hideDuration
=
200
}
=
props
;
lab
.
text
=
text
;
contentView
.
width
=
lab
.
width
;
contentView
.
height
=
lab
.
height
;
lab
.
x
=
lab
.
y
=
padding
;
this
.
width
=
contentView
.
width
=
lab
.
width
+
padding
*
2
;
this
.
height
=
contentView
.
height
=
lab
.
height
+
padding
*
2
;
this
.
addChild
(
contentView
);
if
(
!
contentView
.
visible
)
{
contentView
.
visible
=
true
;
contentView
.
alpha
=
0
;
}
Tween
.
get
(
contentView
,
null
,
null
,
true
)
.
to
({
alpha
:
1
},
showDuration
)
.
wait
(
duration
)
.
to
({
alpha
:
0
},
hideDuration
)
.
call
(
this
.
removeContentView
,
this
)
}
hide
()
{
hide
(
animation
=
true
,
hideDuration
=
200
)
{
if
(
this
.
_content
)
{
const
contentView
=
this
.
_content
;
if
(
animation
){
Tween
.
get
(
contentView
,
null
,
null
,
true
)
.
to
({
alpha
:
0
},
hideDuration
)
.
call
(
this
.
removeContentView
,
this
)
}
else
{
Tween
.
removeTweens
(
contentView
);
this
.
removeContentView
();
}
}
}
private
removeContentView
()
{
this
.
_content
.
visible
=
false
;
this
.
removeChild
(
this
.
_content
);
this
.
_content
=
null
;
}
private
getContent
(
viewName
)
{
let
view
;
if
(
viewName
)
{
view
=
this
.
_gameStage
.
instantiateView
(
viewName
);
}
if
(
!
view
)
{
if
(
!
this
.
_content
)
{
this
.
_content
=
new
Container
();
let
bg
=
new
Rect
();
bg
.
percentWidth
=
100
;
bg
.
percentHeight
=
100
;
bg
.
alpha
=
0.7
;
view
.
addChild
(
bg
);
let
lab
=
new
Label
();
lab
.
name
=
'lab'
;
view
.
addChild
(
bg
);
if
(
this
.
children
.
length
==
0
)
{
if
(
viewName
)
{
view
=
this
.
_gameStage
.
instantiateView
(
viewName
);
}
view
=
this
.
_content
;
if
(
!
view
)
{
if
(
!
this
.
_contentSample
)
{
this
.
_contentSample
=
new
Container
();
let
bg
=
new
Rect
();
bg
.
borderRadius
=
10
;
bg
.
percentWidth
=
100
;
bg
.
percentHeight
=
100
;
bg
.
fillColor
=
'black'
;
bg
.
alpha
=
0.7
;
this
.
_contentSample
.
addChild
(
bg
);
let
lab
=
new
Label
();
lab
.
name
=
'lab'
;
lab
.
fillColor
=
'white'
;
lab
.
size
=
30
;
this
.
_contentSample
.
addChild
(
lab
);
}
view
=
this
.
_contentSample
;
}
this
.
_content
=
view
;
this
.
addChild
(
view
);
}
else
{
view
=
this
.
getChildAt
(
0
);
}
return
view
;
}
}
src/zeroing/game-warpper/data-center.ts
View file @
eb2f29c0
...
...
@@ -46,10 +46,12 @@ export class DataCenter extends EventDispatcher {
/**
* 根据路径获取数据
* @param path
* @param groupName
* @param throwException
*/
getDataByPath
(
path
,
throwException
?)
{
return
getDataByPath
(
this
.
store
,
path
,
throwException
);
getDataByPath
(
path
,
groupName
?,
throwException
?)
{
let
scope
=
groupName
===
undefined
?
this
.
store
:
this
.
getGroup
(
groupName
)
||
this
.
store
;
return
getDataByPath
(
scope
,
path
,
throwException
);
}
/**
...
...
@@ -59,7 +61,7 @@ export class DataCenter extends EventDispatcher {
*/
getDataByName
(
name
,
throwException
?)
{
let
watcher
=
this
.
getWatcher
(
name
);
if
(
watcher
)
{
if
(
watcher
)
{
return
getDataByPath
(
this
.
store
,
watcher
.
path
,
throwException
);
}
}
...
...
@@ -76,10 +78,13 @@ export class DataCenter extends EventDispatcher {
let
name
=
args
[
0
];
let
watcher
=
this
.
getWatcher
(
name
);
try
{
let
data
=
this
.
getDataByPath
(
watcher
.
path
,
true
);
if
(
args
[
1
]
!==
undefined
)
{
let
data
:
any
=
this
.
getDataByPath
(
watcher
.
path
,
undefined
,
true
);
if
(
args
[
1
]
!==
undefined
)
{
data
=
data
[
args
[
1
]];
}
if
(
data
===
undefined
)
{
data
=
''
;
}
result
=
result
.
replace
(
new
RegExp
(
'
\\
$
\\
{'
+
escape
.
replace
(
/
\|
/g
,
'
\\
|'
)
+
'
\\
}'
,
'g'
),
data
);
}
catch
(
e
)
{
...
...
@@ -88,20 +93,41 @@ export class DataCenter extends EventDispatcher {
return
result
;
}
/**
* 数值递增
* @param groupName
* @param step
* @param path
* @param dispatch
*/
increase
(
groupName
,
step
?,
path
?,
dispatch
=
true
)
{
if
(
step
<
0
||
step
>
0
){
let
data
:
any
=
this
.
getDataByPath
(
path
,
groupName
);
if
(
data
===
undefined
)
{
data
=
0
;
}
else
{
data
=
parseInt
(
data
);
}
data
+=
step
;
this
.
mutate
(
groupName
,
data
,
path
,
dispatch
);
}
}
/**
* 修改数据
* @param
n
ame
* @param
groupN
ame
* @param data
* @param path
* @param dispatch
*/
mutate
(
n
ame
,
data
?,
path
?,
dispatch
=
true
)
{
let
group
=
this
.
getGroup
(
n
ame
);
mutate
(
groupN
ame
,
data
?,
path
?,
dispatch
=
true
)
{
let
group
=
this
.
getGroup
(
groupN
ame
);
if
(
!
group
)
{
this
.
registerGroup
(
n
ame
);
this
.
registerGroup
(
groupN
ame
);
}
if
(
data
)
{
if
(
data
!==
undefined
)
{
if
(
path
)
{
let
func
=
new
Function
(
'scope'
,
'data'
,
`scope.
${
path
}
=data`
);
try
{
...
...
@@ -110,13 +136,13 @@ export class DataCenter extends EventDispatcher {
console
.
warn
(
e
);
}
}
else
{
this
.
registerGroup
(
n
ame
,
data
);
this
.
registerGroup
(
groupN
ame
,
data
);
}
}
if
(
dispatch
)
{
for
(
let
watcher
of
this
.
watchers
)
{
if
(
watcher
.
path
.
indexOf
(
n
ame
)
===
0
)
{
if
(
watcher
.
path
.
indexOf
(
groupN
ame
)
===
0
)
{
this
.
dispatchEvent
(
watcher
.
name
,
{
name
:
watcher
.
name
,
path
:
watcher
.
path
,
...
...
@@ -127,7 +153,7 @@ export class DataCenter extends EventDispatcher {
}
globalEvent
.
dispatchEvent
(
DATA_CENTER_EVENT
,
{
name
,
name
:
groupName
,
path
,
data
,
})
...
...
src/zeroing/game-warpper/nodes/Image.ts
View file @
eb2f29c0
...
...
@@ -33,15 +33,18 @@ export class Image extends Sprite {
if
(
url
.
indexOf
(
assetScheme
)
===
0
)
{
let
uuid
=
url
.
replace
(
assetScheme
,
''
);
const
assetConfig
=
getAssetByUUID
(
uuid
);
url
=
assetConfig
.
url
;
if
(
assetConfig
){
url
=
assetConfig
.
url
;
this
.
texture
=
Texture
.
fromImage
(
url
);
}
}
}
else
{
//否则就使用素材名
const
assetConfig
=
getAssetByName
(
url
);
if
(
assetConfig
){
url
=
assetConfig
.
url
;
}
this
.
texture
=
Texture
.
fromImage
(
url
);
}
this
.
texture
=
Texture
.
fromImage
(
url
);
}
private
_setSourceDirect
(
value
){
...
...
src/zeroing/game-warpper/nodes/Label.ts
View file @
eb2f29c0
...
...
@@ -13,6 +13,8 @@ export class Label extends TextField {
private
_originText
;
private
_escapes
=
[];
private
_registeredEvents
=
[];
private
_htmlText
;
private
_el
;
/**
* 重载文本设置
...
...
@@ -20,7 +22,7 @@ export class Label extends TextField {
* @private
*/
protected
_setText
(
value
)
{
if
(
value
!==
this
.
_text
)
{
if
(
value
!==
this
.
_text
)
{
let
matchResult
=
value
.
match
(
ESCAPE_REG_EXP
);
if
(
matchResult
)
{
...
...
@@ -42,6 +44,29 @@ export class Label extends TextField {
}
}
get
htmlText
()
{
return
this
.
_htmlText
;
}
/**
* 设置html文本
*/
set
htmlText
(
v
)
{
if
(
this
.
_htmlText
!=
v
)
{
this
.
_htmlText
=
v
;
let
el
=
this
.
_el
;
if
(
!
el
){
el
=
this
.
_el
=
document
.
createElement
(
'div'
);
}
el
.
innerHTML
=
v
;
document
.
body
.
append
(
el
);
let
pureText
=
el
.
innerText
;
document
.
body
.
removeChild
(
el
);
this
.
text
=
pureText
;
}
}
/**
* 把之前侦听的全部移除
*/
...
...
src/zeroing/utils/utils.ts
View file @
eb2f29c0
...
...
@@ -45,7 +45,7 @@ export function propertyParse(key, node, properties) {
* @param throwException
*/
export
function
getDataByPath
(
scope
,
path
,
throwException
?)
{
let
func
=
new
Function
(
'scope'
,
`return scope
.
${
path
}
`
);
let
func
=
new
Function
(
'scope'
,
`return scope
`
+
(
path
===
undefined
?
''
:
(
'.'
+
path
))
);
try
{
return
func
(
scope
);
}
catch
(
e
)
{
...
...
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