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
f5222b22
Commit
f5222b22
authored
Dec 17, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
内容太多,懒得写
parent
64dc3214
Changes
29
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
4254 additions
and
18997 deletions
+4254
-18997
data.json
data/data.json
+296
-3600
engine.js
debug/engine.js
+3513
-63
engine.js.map
debug/engine.js.map
+1
-1
engine.d20665eae76962ad21c153fe7a719130b08e292c.js
dist/engine.d20665eae76962ad21c153fe7a719130b08e292c.js
+0
-15244
package.json
package.json
+2
-1
Container.ts
src/2d/display/Container.ts
+8
-0
DisplayObject.ts
src/2d/display/DisplayObject.ts
+2
-1
FloatDisplay.ts
src/2d/display/FloatDisplay.ts
+30
-12
Sprite.ts
src/2d/display/Sprite.ts
+17
-17
Stage.ts
src/2d/display/Stage.ts
+2
-2
Event.ts
src/2d/events/Event.ts
+20
-0
Loader.ts
src/2d/loader/Loader.ts
+4
-0
InputText.ts
src/2d/text/InputText.ts
+2
-2
TextField.ts
src/2d/text/TextField.ts
+8
-9
BaseTexture.ts
src/2d/texture/BaseTexture.ts
+1
-1
after-constructor.ts
src/zeroing/decorators/after-constructor.ts
+1
-2
events.ts
src/zeroing/decorators/events.ts
+32
-13
GameStage.ts
src/zeroing/game-warpper/GameStage.ts
+7
-3
assets-manager.ts
src/zeroing/game-warpper/assets-manager.ts
+16
-10
index.ts
src/zeroing/game-warpper/index.ts
+2
-0
Image.ts
src/zeroing/game-warpper/nodes/Image.ts
+2
-3
TextInput.ts
src/zeroing/game-warpper/nodes/TextInput.ts
+224
-0
index.ts
src/zeroing/game-warpper/nodes/index.ts
+1
-0
sound.ts
src/zeroing/game-warpper/sound.ts
+41
-0
view-interpreter.ts
src/zeroing/game-warpper/view-interpreter.ts
+3
-3
index.ts
src/zeroing/index.ts
+2
-0
launcher.ts
src/zeroing/launcher.ts
+6
-6
node-utils.ts
src/zeroing/node-utils.ts
+6
-4
yarn.lock
yarn.lock
+5
-0
No files found.
data/data.json
View file @
f5222b22
This diff is collapsed.
Click to expand it.
debug/engine.js
View file @
f5222b22
This diff is collapsed.
Click to expand it.
debug/engine.js.map
View file @
f5222b22
This diff is collapsed.
Click to expand it.
dist/engine.d20665eae76962ad21c153fe7a719130b08e292c.js
deleted
100644 → 0
View file @
64dc3214
This diff is collapsed.
Click to expand it.
package.json
View file @
f5222b22
...
...
@@ -5,7 +5,8 @@
"main"
:
"index.js"
,
"types"
:
"index.d.ts"
,
"dependencies"
:
{
"
color
"
:
"
^3.1.2
"
"
color
"
:
"
^3.1.2
"
,
"
howler
"
:
"
^2.1.2
"
},
"devDependencies"
:
{
"
dts-bundle
"
:
"
^0.7.3
"
,
...
...
src/2d/display/Container.ts
View file @
f5222b22
...
...
@@ -180,6 +180,14 @@ export default class Container extends DisplayObject {
return
index
;
}
/**
* 是否含有child
* @param child
*/
contains
(
child
:
DisplayObject
):
boolean
{
return
!!
this
.
getChildIndex
(
child
);
}
/**
* 设置child的层级
* @param {DisplayObject} child
...
...
src/2d/display/DisplayObject.ts
View file @
f5222b22
...
...
@@ -5,6 +5,7 @@ import { Point } from "../math/Point";
import
{
Event
}
from
"../events/Event"
;
import
Graphics
from
'../graphics/Graphics'
;
import
{
DEG_TO_RAD
,
RAD_TO_DEG
}
from
'../const'
;
import
{
Stage
}
from
"./Stage"
;
/**
* 基础显示对象抽象类
...
...
@@ -36,7 +37,7 @@ export class DisplayObject extends EventDispatcher {
/**
* 舞台
*/
stage
:
any
;
stage
:
Stage
;
/**
* 名字,预留
...
...
src/2d/display/FloatDisplay.ts
View file @
f5222b22
...
...
@@ -2,6 +2,8 @@ import {Event} from "../events/Event";
import
{
DisplayObject
}
from
"./DisplayObject"
;
import
{
devicePixelRatio
}
from
"../const"
;
let
container
;
/**
* 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/>
* 比如有时候我们需要放置一个注册,登录或者其他的内容.这些内容包含了输入框<br/>
...
...
@@ -22,7 +24,7 @@ export class FloatDisplay extends DisplayObject {
* @since 1.0.0
* @type{HtmlElement}
*/
p
ublic
htmlElement
:
any
=
null
;
p
rivate
_
htmlElement
:
any
=
null
;
/**
* 是否已经添加了舞台事件
* @property _isAdded
...
...
@@ -75,19 +77,26 @@ export class FloatDisplay extends DisplayObject {
let
s
=
this
;
s
.
_instanceType
=
"FloatDisplay"
;
s
.
addEventListener
(
Event
.
REMOVED_FROM_STAGE
,
function
(
e
:
Event
)
{
if
(
s
.
htmlElement
)
{
s
.
htmlElement
.
style
.
display
=
"none"
;
if
(
s
.
_
htmlElement
)
{
s
.
_
htmlElement
.
style
.
display
=
"none"
;
}
});
s
.
addEventListener
(
Event
.
ADDED_TO_STAGE
,
function
(
e
:
Event
)
{
if
(
s
.
htmlElement
)
{
let
style
=
s
.
htmlElement
.
style
;
if
(
!
container
){
container
=
document
.
createElement
(
'div'
);
container
.
style
.
position
=
"absolute"
;
container
.
style
.
left
=
"0"
;
container
.
style
.
top
=
"0"
;
s
.
stage
.
rootDiv
.
appendChild
(
container
);
//, s.stage.rootDiv.childNodes[0]
}
if
(
s
.
_htmlElement
)
{
let
style
=
s
.
_htmlElement
.
style
;
if
(
!
s
.
_isAdded
)
{
s
.
_isAdded
=
true
;
s
.
stage
.
rootDiv
.
insertBefore
(
s
.
htmlElement
,
s
.
stage
.
rootDiv
.
childNodes
[
0
]
);
container
.
appendChild
(
s
.
_htmlElement
);
s
.
stage
[
"_floatDisplayList"
].
push
(
s
);
}
else
{
if
(
s
.
htmlElement
&&
s
.
visible
)
{
if
(
s
.
_
htmlElement
&&
s
.
visible
)
{
style
.
display
=
"block"
;
}
}
...
...
@@ -97,6 +106,15 @@ export class FloatDisplay extends DisplayObject {
this
.
_transformID
=
-
1
;
}
get
htmlElement
()
{
return
this
.
_htmlElement
;
}
set
htmlElement
(
v
)
{
this
.
init
(
v
);
this
.
updateStyle
();
}
/**
* 初始化方法,htmlElement 一定要设置width和height样式,并且一定要用px单位
* @method init
...
...
@@ -104,7 +122,7 @@ export class FloatDisplay extends DisplayObject {
* @since 1.0.0
* @param {HtmlElement} htmlElement 需要封装起来的html元素的引用。你可以通过这个引用来调用或设置此元素自身的属性方法和事件,甚至是样式
*/
p
ublic
init
(
htmlElement
:
any
):
void
{
p
rotected
init
(
htmlElement
:
any
):
void
{
let
s
=
this
;
let
she
:
any
;
if
(
typeof
(
htmlElement
)
==
"string"
)
{
...
...
@@ -131,7 +149,7 @@ export class FloatDisplay extends DisplayObject {
// s._bounds.height = h;
s
.
_localBoundsSelf
.
width
=
w
;
s
.
_localBoundsSelf
.
height
=
h
;
s
.
htmlElement
=
she
;
s
.
_
htmlElement
=
she
;
}
/**
...
...
@@ -163,7 +181,7 @@ export class FloatDisplay extends DisplayObject {
*/
public
updateStyle
():
void
{
let
s
=
this
;
let
o
=
s
.
htmlElement
;
let
o
=
s
.
_
htmlElement
;
if
(
o
)
{
let
style
=
o
.
style
;
let
visible
=
s
.
visible
;
...
...
@@ -201,14 +219,14 @@ export class FloatDisplay extends DisplayObject {
public
destroy
():
void
{
//清除相应的数据引用
let
s
=
this
;
let
elem
=
s
.
htmlElement
;
let
elem
=
s
.
_
htmlElement
;
if
(
elem
)
{
elem
.
style
.
display
=
"none"
;
if
(
elem
.
parentNode
)
{
elem
.
parentNode
.
removeChild
(
elem
);
}
s
.
_isAdded
=
false
;
s
.
htmlElement
=
null
;
s
.
_
htmlElement
=
null
;
}
let
sf
:
any
=
s
.
stage
[
"_floatDisplayList"
];
let
len
=
sf
.
length
;
...
...
src/2d/display/Sprite.ts
View file @
f5222b22
...
...
@@ -371,30 +371,30 @@ export default class Sprite extends Container {
* texture的宽度和缩放乘积
* @member {number}
*/
//
get width() {
//
return Math.abs(this.scale.x) * this._texture.orig.width;
//
}
get
width
()
{
return
Math
.
abs
(
this
.
scale
.
x
)
*
this
.
_texture
.
orig
.
width
;
}
//
set width(value) {
//
const s = sign(this.scale.x) || 1;
set
width
(
value
)
{
const
s
=
sign
(
this
.
scale
.
x
)
||
1
;
//
this.scale.x = s * value / this._texture.orig.width;
//
this._width = value;
//
}
this
.
scale
.
x
=
s
*
value
/
this
.
_texture
.
orig
.
width
;
this
.
_width
=
value
;
}
/**
* texture的高度和缩放乘积
* @member {number}
*/
//
get height() {
//
return Math.abs(this.scale.y) * this._texture.orig.height;
//
}
//
set height(value) {
//
const s = sign(this.scale.y) || 1;
//
this.scale.y = s * value / this._texture.orig.height;
//
this._height = value;
//
}
get
height
()
{
return
Math
.
abs
(
this
.
scale
.
y
)
*
this
.
_texture
.
orig
.
height
;
}
set
height
(
value
)
{
const
s
=
sign
(
this
.
scale
.
y
)
||
1
;
this
.
scale
.
y
=
s
*
value
/
this
.
_texture
.
orig
.
height
;
this
.
_height
=
value
;
}
/**
* 0,0标识左上角,0.5,0.5表示中间,1,1表示右下角
...
...
src/2d/display/Stage.ts
View file @
f5222b22
...
...
@@ -72,7 +72,7 @@ export class Stage extends Container {
* @type {Html Div}
* @default null
*/
public
rootDiv
:
any
=
null
;
public
rootDiv
:
any
=
HTMLElement
;
/**
* 当前stage所使用的渲染器
* 渲染器有两种,一种是canvas 一种是webGl
...
...
@@ -432,7 +432,7 @@ export class Stage extends Container {
s
.
dispatchEvent
(
Event
.
ON_INIT_STAGE
);
// }
},
100
);
let
rc
=
s
.
rootDiv
;
let
rc
=
canvas
;
//
s.rootDiv;
let
mouseEvent
=
s
.
onMouseEvent
.
bind
(
s
);
//鼠标事件
if
(
osType
!=
"pc"
)
{
...
...
src/2d/events/Event.ts
View file @
f5222b22
...
...
@@ -133,6 +133,26 @@ export class Event extends HashObject {
* @since 1.0.0
*/
public
static
PROGRESS
:
string
=
"onProgress"
;
/**
* 获取焦点
* @Event
* @property FOCUS
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public
static
FOCUS
:
string
=
"focus"
;
/**
* 失去焦点
* @Event
* @property BLUR
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public
static
BLUR
:
string
=
"blur"
;
/**
* 出错事件
* @Event
...
...
src/2d/loader/Loader.ts
View file @
f5222b22
...
...
@@ -113,6 +113,10 @@ export class Loader extends EventDispatcher {
}
this
.
caches
[
name
]
=
data
;
}
get
(
name
:
string
){
return
this
.
caches
[
name
];
}
}
async
function
fetchAsync
(
url
:
string
)
{
...
...
src/2d/text/InputText.ts
View file @
f5222b22
...
...
@@ -9,7 +9,7 @@ import {TextField} from "./TextField";
* @class InputText
* @public
* @since 1.0.0
* @extends
annie.
FloatDisplay
* @extends FloatDisplay
*/
export
class
InputText
extends
FloatDisplay
{
/**
...
...
@@ -90,7 +90,7 @@ export class InputText extends FloatDisplay {
* @return {void}
* @since 1.0.0
*/
p
ublic
init
(
htmlElement
:
any
):
void
{
p
rotected
init
(
htmlElement
:
any
):
void
{
super
.
init
(
htmlElement
);
//默认设置
let
s
=
this
;
...
...
src/2d/text/TextField.ts
View file @
f5222b22
...
...
@@ -170,9 +170,9 @@ export class TextField extends Sprite {
set
width
(
value
:
number
)
{
if
(
this
.
_width
!==
value
)
{
this
.
dispatchEvent
(
Event
.
RESIZE
);
this
.
_width
=
value
;
this
.
dirty
=
true
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
...
...
@@ -184,9 +184,9 @@ export class TextField extends Sprite {
set
height
(
value
:
number
)
{
if
(
this
.
_height
!==
value
)
{
this
.
dispatchEvent
(
Event
.
RESIZE
);
this
.
_height
=
value
;
this
.
dirty
=
true
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
...
...
@@ -240,21 +240,21 @@ export class TextField extends Sprite {
* @since 1.0.0
*/
public
set
text
(
value
:
string
)
{
if
(
this
.
_text
!=
value
)
{
this
.
_setText
(
value
);
}
}
public
get
text
():
string
{
return
this
.
_text
;
}
protected
_setText
(
value
)
{
if
(
this
.
_text
!=
value
)
{
this
.
_text
=
value
;
this
.
dirty
=
true
;
this
.
dispatchEvent
(
Event
.
RESIZE
);
}
}
protected
_text
:
string
=
""
;
...
...
@@ -271,7 +271,6 @@ export class TextField extends Sprite {
this
.
_font
=
value
;
this
.
dirty
=
true
;
}
;
}
public
get
font
():
string
{
...
...
src/2d/texture/BaseTexture.ts
View file @
f5222b22
...
...
@@ -137,7 +137,7 @@ export default class BaseTexture extends EventDispatcher {
update
()
{
this
.
width
=
this
.
source
.
width
;
this
.
height
=
this
.
source
.
height
;
this
.
isPowerOfTwo
=
isPow2
(
this
.
width
)
&&
isPow2
(
this
.
width
);
this
.
isPowerOfTwo
=
isPow2
(
this
.
width
)
&&
isPow2
(
this
.
height
);
this
.
dispatchEvent
(
"update"
)
}
...
...
src/zeroing/decorators/after-constructor.ts
View file @
f5222b22
...
...
@@ -38,9 +38,8 @@ export function afterConstructor(ctor: Function) {
}
if
(
withEvents
){
if
(
events
)
{
target
.
eventsProxy
.
eventsConfig
=
events
;
target
.
eventsProxy
.
start
(
events
)
;
}
target
.
eventsProxy
.
start
();
}
for
(
let
child
of
this
.
children
){
...
...
src/zeroing/decorators/events.ts
View file @
f5222b22
...
...
@@ -28,7 +28,7 @@ export function applyEvents(ctor: Function) {
ctor
.
prototype
.
applyEvents
=
function
()
{
let
eventsProxy
=
this
.
eventsProxy
=
new
EventsProxy
(
this
);
for
(
let
k
in
eventsMapping
)
{
this
.
addEventListener
(
k
,
eventsProxy
.
onEvent
,
eventsProxy
);
this
.
addEventListener
(
k
,
eventsProxy
.
on
Builtin
Event
,
eventsProxy
);
}
globalEvent
.
addEventListener
(
DATA_CENTER_EVENT
,
eventsProxy
.
onDateCenterEvent
,
eventsProxy
);
...
...
@@ -37,37 +37,56 @@ export function applyEvents(ctor: Function) {
class
EventsProxy
extends
HashObject
{
host
;
eventsConfig
:
any
;
private
_eventsConfig
:
any
;
constructor
(
host
)
{
super
();
this
.
host
=
host
;
}
start
()
{
this
.
invoke
(
'init'
,
this
.
host
);
get
eventsConfig
()
{
return
this
.
_eventsConfig
;
}
start
(
eventsConfig
)
{
this
.
_eventsConfig
=
eventsConfig
;
for
(
let
name
in
eventsConfig
){
globalEvent
.
addEventListener
(
name
,
this
.
onCustomEvent
,
this
);
}
this
.
invokeBehavior
(
'init'
,
this
.
host
);
}
invoke
(
name
,
target
,
payload
?)
{
if
(
this
.
eventsConfig
)
{
const
eventConfig
=
this
.
eventsConfig
[
name
];
invoke
Behavior
(
name
,
target
,
payload
?)
{
if
(
this
.
_
eventsConfig
)
{
const
eventConfig
=
this
.
_
eventsConfig
[
name
];
if
(
eventConfig
)
{
for
(
let
behavior
of
eventConfig
.
behaviors
){
if
(
behavior
.
disabled
){
continue
;
}
executeBehavior
({
main
:
eventConfig
.
behaviors
[
0
]
,
main
:
behavior
,
},
'main'
,
target
,
payload
);
}
}
}
}
onEvent
(
e
)
{
on
Builtin
Event
(
e
)
{
let
eventName
=
eventsMapping
[
e
.
type
];
if
(
eventName
)
{
this
.
invoke
(
eventName
,
e
.
target
,
e
.
data
);
this
.
invoke
Behavior
(
eventName
,
e
.
target
,
e
.
data
);
}
}
onCustomEvent
(
e
)
{
this
.
invokeBehavior
(
e
.
type
,
this
.
host
,
e
.
data
);
}
onDateCenterEvent
(
e
)
{
this
.
invoke
(
'data-center'
,
this
.
host
,
e
.
data
);
this
.
invoke
Behavior
(
'data-center'
,
this
.
host
,
e
.
data
);
}
destroy
():
void
{
...
...
src/zeroing/game-warpper/GameStage.ts
View file @
f5222b22
...
...
@@ -49,7 +49,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
.
_popupContainer
=
new
StackContainer
());
this
.
addChild
(
this
.
_toast
=
new
Toast
(
this
));
blackLayer
.
percentWidth
=
100
;
...
...
@@ -98,7 +98,7 @@ export class GameStage extends Container {
* @param onAssetsProgress
* @param onAssetsComplete
*/
async
launch
(
config
,
onAssetsProgress
?,
onAssetsComplete
?)
{
async
launch
(
config
,
onAssetsProgress
?,
onAssetsComplete
?
,
onStart
?
)
{
this
.
_config
=
config
;
const
{
assets
,
customs
}
=
config
;
let
loaded
=
0
;
...
...
@@ -128,6 +128,8 @@ export class GameStage extends Container {
this
.
start
();
onStart
&&
onStart
();
function
p
()
{
loaded
++
;
...
...
@@ -150,7 +152,9 @@ export class GameStage extends Container {
//registerScripts(scripts);
//registerCustomModuleFromConfig(customs);
if
(
dataMapping
){
this
.
dataCenter
.
registerDataMapping
(
dataMapping
);
}
setProcessMetaLibs
(
processes
,
builtinProcesses
);
let
sceneEntry
=
this
.
instantiateView
(
entrySceneView
);
...
...
src/zeroing/game-warpper/assets-manager.ts
View file @
f5222b22
...
...
@@ -32,7 +32,8 @@ export function loadAssets(config, onProgress?, onComplete?) {
config
.
map
(
assetConfig
=>
{
assetsConfig
.
push
(
assetConfig
);
const
loadFunc
=
loaderMapping
[
assetConfig
.
ext
]
||
'Raw'
;
let
method
=
globalLoader
[
'load'
+
loadFunc
]
||
globalLoader
.
loadRaw
;
let
method
=
globalLoader
[
'load'
+
loadFunc
];
if
(
method
){
return
method
.
call
(
globalLoader
,
assetConfig
.
url
,
assetConfig
.
uuid
).
then
(
(
data
)
=>
{
loaded
++
;
...
...
@@ -42,6 +43,11 @@ export function loadAssets(config, onProgress?, onComplete?) {
failedList
.
push
(
assetConfig
.
url
);
}
);
}
else
{
loaded
++
;
onProgress
&&
onProgress
(
loaded
,
total
);
return
Promise
.
resolve
();
}
})
).
then
(
()
=>
{
...
...
src/zeroing/game-warpper/index.ts
View file @
f5222b22
...
...
@@ -6,3 +6,5 @@ export * from './GameStage'
export
*
from
'./enviroment'
export
*
from
'./custom-module'
export
*
from
'./nodes'
export
*
from
'./sound'
export
*
from
'./assets-manager'
src/zeroing/game-warpper/nodes/Image.ts
View file @
f5222b22
...
...
@@ -31,21 +31,20 @@ export class Image extends Sprite {
let
url
=
this
.
_source
;
if
(
url
.
indexOf
(
'://'
)
>=
0
){
//如果是有协议的地址
if
(
url
.
indexOf
(
assetScheme
)
===
0
)
{
let
uuid
=
url
.
replace
(
assetScheme
,
''
);
url
=
url
.
replace
(
assetScheme
,
''
);
/*const assetConfig = getAssetByUUID(uuid);
if(assetConfig){
url = assetConfig.url;
this.texture = Texture.fromImage(url);
}*/
this
.
texture
=
Texture
.
from
(
uuid
);
}
}
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/TextInput.ts
0 → 100644
View file @
f5222b22
/**
* Created by rockyl on 2019-12-13.
*/
import
{
Label
}
from
"./Label"
;
import
{
MouseEvent
}
from
"../../../2d/events/MouseEvent"
;
import
{
Event
}
from
"../../../2d/events/Event"
;
import
{
FloatDisplay
}
from
"../../../2d/display/FloatDisplay"
;
import
{
TextField
}
from
"../../../2d/text"
;
import
{
Point
}
from
"../../../2d/math"
;
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
;
private
_oldFillColor
;
private
_oldStrokeColor
;
constructor
()
{
super
();
this
.
setup
();
this
.
addEventListener
(
MouseEvent
.
CLICK
,
this
.
onClickStatic
,
this
);
this
.
addEventListener
(
Event
.
RESIZE
,
this
.
onResize
,
this
);
this
.
text
=
''
;
}
get
placeholder
():
string
{
return
this
.
_placeholder
;
}
set
placeholder
(
value
:
string
)
{
this
.
_placeholder
=
value
;
this
.
_placeholderLabel
.
text
=
value
;
}
get
placeholderColor
():
any
{
return
this
.
_placeholderColor
;
}
set
placeholderColor
(
value
:
any
)
{
this
.
_placeholderColor
=
value
;
this
.
_placeholderLabel
.
fillColor
=
value
;
}
get
maxLength
():
number
{
return
this
.
_maxLength
;
}
set
maxLength
(
value
:
number
)
{
if
(
this
.
_maxLength
!=
value
){
this
.
_maxLength
=
value
;
this
.
setMaxLength
();
}
}
private
setup
()
{
let
fd
=
this
.
_floatDisplay
=
new
FloatDisplay
();
let
input
=
this
.
_input
=
document
.
createElement
(
'input'
);
fd
.
htmlElement
=
input
;
fd
.
alpha
=
0
;
input
.
style
.
pointerEvents
=
'none'
;
let
style
=
input
.
style
;
style
.
outline
=
'none'
;
style
.
padding
=
'0'
;
style
.
border
=
'0'
;
style
.
backgroundColor
=
'transparent'
;
input
.
type
=
'text'
;
input
.
addEventListener
(
'blur'
,
this
.
onBlur
);
let
pl
=
this
.
_placeholderLabel
=
new
TextField
();
pl
.
fillColor
=
this
.
_placeholderColor
;
this
.
verticalAlign
=
pl
.
verticalAlign
=
VERTICAL_ALIGN
.
MIDDLE
;
this
.
addChild
(
fd
);
}
protected
_setText
(
value
)
{
super
.
_setText
(
value
);
this
.
setMaxLength
();
setTimeout
(()
=>
{
this
.
showPlaceholderLabel
(
value
)
},
1
);
}
private
setMaxLength
()
{
let
value
=
this
.
_text
;
let
maxLength
=
this
.
_maxLength
;
if
(
maxLength
>
0
&&
value
&&
value
.
length
>
maxLength
)
{
this
.
text
=
value
.
substr
(
0
,
maxLength
);
}
}
private
showPlaceholderLabel
(
value
)
{
let
pl
=
this
.
_placeholderLabel
;
if
(
value
){
let
pl
=
this
.
_placeholderLabel
;
if
(
pl
.
parent
)
{
pl
.
parent
.
removeChild
(
pl
);
}
}
else
{
if
(
!
pl
.
parent
)
{
pl
.
text
=
this
.
_placeholder
;
pl
.
size
=
this
.
size
;
pl
.
font
=
this
.
font
;
this
.
addChildAt
(
pl
,
0
);
}
}
}
setFocus
()
{
let
fd
=
this
.
_floatDisplay
;
let
input
=
this
.
_input
;
let
pl
=
this
.
_placeholderLabel
;
fd
.
width
=
this
.
width
;
fd
.
height
=
this
.
height
;
input
.
value
=
this
.
text
;
let
style
=
input
.
style
;
style
.
fontSize
=
this
.
size
+
'px'
;
style
.
color
=
this
.
fillColor
;
style
.
width
=
this
.
width
+
'px'
;
style
.
height
=
this
.
height
+
'px'
;
style
.
fontFamily
=
this
.
font
;
this
.
_oldFillColor
=
this
.
fillColor
;
this
.
_oldStrokeColor
=
this
.
strokeColor
;
this
.
fillColor
=
'transparent'
;
this
.
strokeColor
=
'transparent'
;
if
(
pl
.
parent
)
{
pl
.
parent
.
removeChild
(
pl
);
}
//this.addChild(this._floatDisplay);
this
.
_floatDisplay
.
alpha
=
1
;
input
.
style
.
pointerEvents
=
'auto'
;
if
(
this
.
_maxLength
>
0
){
input
.
maxLength
=
this
.
_maxLength
;
}
else
{
input
.
removeAttribute
(
'maxLength'
)
}
input
.
focus
();
this
.
dispatchEvent
(
Event
.
FOCUS
);
}
setBlur
()
{
let
input
=
this
.
_input
;
this
.
_floatDisplay
.
alpha
=
0
;
input
.
style
.
pointerEvents
=
'none'
;
input
.
blur
();
this
.
text
=
input
.
value
;
this
.
fillColor
=
this
.
_oldFillColor
;
this
.
strokeColor
=
this
.
_oldStrokeColor
;
this
.
dispatchEvent
(
Event
.
BLUR
);
}
private
onBlur
=
(
e
)
=>
{
this
.
setBlur
();
};
private
onClickStage
(
e
){
if
(
e
.
currentTarget
!==
this
){
this
.
setBlur
();
}
}
private
onClickStatic
()
{
this
.
setFocus
();
this
.
stage
.
once
(
MouseEvent
.
CLICK
,
this
.
onClickStage
,
this
);
}
private
onResize
()
{
let
pl
=
this
.
_placeholderLabel
;
pl
.
width
=
this
.
width
;
pl
.
height
=
this
.
height
;
}
public
static
_bp
:
Point
=
new
Point
();
/**
* 检测点是否在任何child上
* 重写父类方法
*/
hitTestPoint
(
globalPoint
:
Point
,
isMouseEvent
:
boolean
=
false
)
{
const
s
=
this
;
//如果不可见
if
(
!
this
.
visible
)
return
null
;
//如果禁止子级的鼠标事件
if
(
isMouseEvent
&&
!
this
.
mouseChildren
)
return
null
;
if
(
!
isMouseEvent
)
{
//如果不是系统调用则不考虑这个点是从全局来的,只认为这个点就是当前要碰撞测试同级别下的坐标点
if
(
s
.
_localBoundsSelf
.
isPointIn
(
globalPoint
))
{
return
s
;
}
}
else
{
let
{
x
,
y
}
=
s
.
globalToLocal
(
globalPoint
,
TextInput
.
_bp
);
if
(
x
>
0
&&
x
<
s
.
width
&&
y
>
0
&&
y
<
s
.
height
)
{
return
s
;
}
}
return
null
;
}
}
src/zeroing/game-warpper/nodes/index.ts
View file @
f5222b22
...
...
@@ -5,4 +5,5 @@
export
*
from
'./shapes'
export
*
from
'./Image'
export
*
from
'./Label'
export
*
from
'./TextInput'
export
*
from
'./ScrollView'
\ No newline at end of file
src/zeroing/game-warpper/sound.ts
0 → 100644
View file @
f5222b22
/**
* Created by rockyl on 2019-12-16.
*/
import
{
getAssetByUUID
}
from
"./assets-manager"
;
import
{
Howl
,
Howler
}
from
'howler'
;
import
{
injectProperties
}
from
"../utils"
;
const
instances
=
{};
export
function
playSound
(
uuid
,
options
=
{},
name
?)
{
let
assetConfig
=
getAssetByUUID
(
uuid
);
if
(
assetConfig
)
{
let
url
=
assetConfig
.
url
;
let
opts
:
any
=
{
src
:
[
url
],
autoplay
:
true
,
};
injectProperties
(
opts
,
options
);
let
sound
=
new
Howl
(
opts
);
if
(
name
!==
undefined
)
{
instances
[
name
]
=
sound
;
sound
.
on
(
'end'
,
function
()
{
delete
instances
[
name
];
});
}
return
sound
;
}
}
export
function
stopSound
(
name
){
let
sound
=
instances
[
name
];
if
(
sound
){
sound
.
stop
();
delete
instances
[
name
];
}
}
src/zeroing/game-warpper/view-interpreter.ts
View file @
f5222b22
...
...
@@ -3,7 +3,7 @@
*/
import
{
Container
}
from
"../../2d/display"
;
import
{
Rect
,
Image
,
Label
,
Circle
,
ScrollView
}
from
"./nodes"
;
import
{
Rect
,
Image
,
Label
,
Circle
,
ScrollView
,
TextInput
}
from
"./nodes"
;
import
{
injectProperties
,
instantiateScript
,
propertyParse
}
from
"../utils"
;
const
nodeTypeMapping
=
{
...
...
@@ -12,6 +12,7 @@ const nodeTypeMapping = {
circle
:
Circle
,
label
:
Label
,
image
:
Image
,
textinput
:
TextInput
,
scrollView
:
ScrollView
,
};
...
...
@@ -41,9 +42,8 @@ function instantiateView(config) {
}
}
if
(
events
)
{
node
.
eventsProxy
.
eventsConfig
=
events
;
node
.
eventsProxy
.
start
(
events
)
;
}
node
.
eventsProxy
.
start
();
if
(
children
&&
children
.
length
>
0
)
{
for
(
let
childConfig
of
children
)
{
...
...
src/zeroing/index.ts
View file @
f5222b22
...
...
@@ -13,6 +13,8 @@ export * from './web'
export
*
from
'./log-switch'
import
{
instantiate
}
from
'./game-warpper/view-interpreter'
export
{
Howl
,
Howler
}
from
'howler'
;
export
{
instantiate
}
src/zeroing/launcher.ts
View file @
f5222b22
...
...
@@ -11,14 +11,14 @@ import {Event} from "../2d/events/Event";
export
let
gameStage
:
GameStage
;
export
function
launch
(
url
,
onAssetsProgress
,
onAssetsComplete
)
{
export
function
launch
(
url
,
onAssetsProgress
,
onAssetsComplete
,
onStart
)
{
return
globalLoader
.
loadJson
(
url
)
.
then
(
config
=>
{
return
launchWithConfig
(
config
,
onAssetsProgress
,
onAssetsComplete
);
return
launchWithConfig
(
config
,
onAssetsProgress
,
onAssetsComplete
,
onStart
);
});
}
export
function
launchWithLocalStorage
(
id
,
onAssetsProgress
,
onAssetsComplete
)
{
export
function
launchWithLocalStorage
(
id
,
onAssetsProgress
,
onAssetsComplete
,
onStart
)
{
const
storeKey
=
'preview-project-'
+
id
;
let
storeData
=
localStorage
.
getItem
(
storeKey
);
let
{
data
,
processes
,
scripts
,
customs
,}
=
JSON
.
parse
(
storeData
);
...
...
@@ -27,10 +27,10 @@ export function launchWithLocalStorage(id, onAssetsProgress, onAssetsComplete) {
registerScripts
(
scripts
);
registerCustomModuleFromConfig
(
customs
);
return
launchWithConfig
(
data
,
onAssetsProgress
,
onAssetsComplete
);
return
launchWithConfig
(
data
,
onAssetsProgress
,
onAssetsComplete
,
onStart
);
}
export
function
launchWithConfig
(
config
,
onAssetsProgress
,
onAssetsComplete
)
{
export
function
launchWithConfig
(
config
,
onAssetsProgress
,
onAssetsComplete
,
onStart
)
{
return
new
Promise
(
resolve
=>
{
const
{
containerId
,
designWidth
,
designHeight
,
frameRate
,
scaleMode
,
rendererType
,}
=
config
.
options
;
let
stage
=
window
[
'stage'
]
=
new
Stage
(
...
...
@@ -50,7 +50,7 @@ export function launchWithConfig(config, onAssetsProgress, onAssetsComplete) {
});
stage
.
addChild
(
gameStage
);
gameStage
.
launch
(
config
,
onAssetsProgress
,
onAssetsComplete
);
gameStage
.
launch
(
config
,
onAssetsProgress
,
onAssetsComplete
,
onStart
);
});
resolve
(
gameStage
);
...
...
src/zeroing/node-utils.ts
View file @
f5222b22
This diff is collapsed.
Click to expand it.
yarn.lock
View file @
f5222b22
This diff is collapsed.
Click to expand it.
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