Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scilla-core
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
劳工
scilla-core
Commits
860ceae5
Commit
860ceae5
authored
Jun 26, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加script类型
parent
31ca7375
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
86 deletions
+132
-86
ReType.ts
src/ReType.ts
+5
-0
interpreter.ts
src/core/interpreter.ts
+19
-8
DataCenter.ts
src/support/DataCenter.ts
+68
-70
utils.ts
src/tools/utils.ts
+40
-8
No files found.
src/ReType.ts
View file @
860ceae5
...
...
@@ -22,6 +22,11 @@ export type raw = any;
*/
export
type
dynamic
=
any
;
/**
* 脚本数据
*/
export
type
script
=
any
;
/**
* 常用框类型
*/
...
...
src/core/interpreter.ts
View file @
860ceae5
...
...
@@ -33,7 +33,7 @@ export function unregisterDef(name: string) {
delete
defMap
[
name
];
}
export
function
setGetResProxy
(
func
:
Function
){
export
function
setGetResProxy
(
func
:
Function
)
{
_getResProxy
=
func
;
}
...
...
@@ -76,7 +76,7 @@ export function instantiate(config: any): Entity {
* @param root
* @param pid
*/
function
instantiateConfig
(
config
,
root
?:
Entity
,
pid
?:
number
):
Entity
{
function
instantiateConfig
(
config
,
root
?:
Entity
,
pid
?:
number
):
Entity
{
let
rootConfig
=
config
.
root
;
const
entity
=
setupEntity
(
rootConfig
,
root
,
pid
);
...
...
@@ -209,7 +209,7 @@ function injectComponents(entity: Entity, config: any, pid?: number) {
* @param config
* @param pid
*/
export
function
injectComponentProperties
(
component
,
config
,
pid
?:
number
){
export
function
injectComponentProperties
(
component
,
config
,
pid
?:
number
)
{
const
{
properties
}
=
config
;
if
(
properties
)
{
...
...
@@ -223,7 +223,7 @@ export function injectComponentProperties(component, config, pid?: number){
* @param config
*/
export
function
instantiateComponent
(
entity
:
Entity
,
config
:
any
)
{
const
{
script
,
}
=
config
;
const
{
script
,}
=
config
;
let
def
=
getDefByName
(
script
);
...
...
@@ -279,7 +279,7 @@ function injectProperties(node, propertiesConfig, pid?: number) {
let
propertyOfInstance
=
node
[
key
];
if
(
typeof
propertyOfConfig
===
'object'
)
{
if
(
propertyOfInstance
instanceof
ScillaEvent
)
{
if
(
!
EngineConfig
.
editorMode
)
{
if
(
!
EngineConfig
.
editorMode
)
{
injectEvent
(
propertyOfInstance
,
propertyOfConfig
,
pid
);
}
}
else
if
(
propertyOfConfig
.
_type_
===
'raw'
)
{
...
...
@@ -325,14 +325,14 @@ function injectBaseType(node, key, propertyOfConfig, pid?: number) {
}
let
keyAvatar
=
key
;
if
(
propertyValue
instanceof
Promise
)
{
if
(
propertyValue
instanceof
Promise
)
{
keyAvatar
=
'async_'
+
keyAvatar
;
}
if
(
typeof
propertyValue
===
'function'
)
{
Object
.
defineProperty
(
node
,
keyAvatar
,
{
get
()
{
return
this
[
`func_
${
keyAvatar
}
`
]()
return
this
[
`func_
${
keyAvatar
}
`
](
node
,
engine
.
dataCenter
)
},
set
(
v
)
{
this
[
`func_
${
keyAvatar
}
`
]
=
v
;
...
...
@@ -372,6 +372,9 @@ function getLink(str: string, pid?: number) {
result
=
()
=>
{
return
engine
.
dataCenter
.
parse
(
type
,
expression
)
};
}
else
if
(
str
.
indexOf
(
'script|'
)
==
0
)
{
//script
const
script
=
str
.
substr
(
7
);
result
=
wrapperScript
(
script
);
}
else
{
result
=
str
;
}
...
...
@@ -381,3 +384,11 @@ function getLink(str: string, pid?: number) {
function
transPrefabUUID
(
uuid
,
pid
:
number
)
{
return
pid
?
pid
+
'_'
+
uuid
:
uuid
;
}
function
wrapperScript
(
script
){
try
{
return
new
Function
(
'component'
,
'dataCenter'
,
script
);
}
catch
(
e
)
{
console
.
warn
(
'script is correct :'
,
script
);
}
}
src/support/DataCenter.ts
View file @
860ceae5
/**
* 数据中心类
*/
import
EventEmitter
from
"./EventEmitter"
;
import
{
utils
}
from
"../tools"
;
export
default
class
DataCenter
extends
EventEmitter
{
export
default
class
DataCenter
extends
EventEmitter
{
private
store
:
any
=
{};
/**
...
...
@@ -18,11 +20,11 @@ export default class DataCenter extends EventEmitter{
* 清空数据,如果type为false值,就清空整个数据中心
* @param type
*/
public
clean
(
type
?:
string
)
{
public
clean
(
type
?:
string
)
{
let
target
=
type
?
this
.
store
[
type
]
:
this
.
store
;
if
(
target
)
{
if
(
target
)
{
let
keys
=
Object
.
keys
(
target
);
for
(
let
key
of
keys
)
{
for
(
let
key
of
keys
)
{
delete
target
[
key
];
}
}
...
...
@@ -67,17 +69,13 @@ export default class DataCenter extends EventEmitter{
*/
public
parse
(
type
:
string
,
expression
:
string
)
{
let
node
=
this
.
store
[
type
];
let
segments
=
expression
.
split
(
'.'
);
while
(
segments
.
length
>
0
){
const
segment
=
segments
.
shift
();
if
(
!
node
){
console
.
warn
(
`can not get
${
segment
}
on
${
segment
}
`
);
break
;
}
node
=
node
[
segment
];
}
return
node
;
//return eval(`(this.store['${type}'].${expression})`);
let
result
=
null
;
try
{
result
=
utils
.
dotEval
(
expression
,
node
);
}
catch
(
e
)
{
}
return
result
;
}
}
src/tools/utils.ts
View file @
860ceae5
...
...
@@ -28,7 +28,7 @@ export function injectProp(target: any, data?: any, callback?: Function, ignoreM
}
else
{
try
{
target
[
key
]
=
value
;
}
catch
(
e
)
{
}
catch
(
e
)
{
}
}
...
...
@@ -45,18 +45,18 @@ export function injectProp(target: any, data?: any, callback?: Function, ignoreM
* @param data
* @param config
*/
export
function
copyProp
(
target
,
data
?,
config
?){
if
(
config
)
{
for
(
let
key
in
config
)
{
export
function
copyProp
(
target
,
data
?,
config
?)
{
if
(
config
)
{
for
(
let
key
in
config
)
{
let
valueConfig
=
config
[
key
];
if
(
Array
.
isArray
(
valueConfig
))
{
if
(
Array
.
isArray
(
valueConfig
))
{
target
[
key
]
=
{};
for
(
let
field
of
valueConfig
)
{
for
(
let
field
of
valueConfig
)
{
target
[
key
][
field
]
=
data
[
key
][
field
];
}
}
else
if
(
typeof
valueConfig
===
'string'
)
{
}
else
if
(
typeof
valueConfig
===
'string'
)
{
target
[
valueConfig
]
=
data
[
valueConfig
];
}
else
if
(
typeof
valueConfig
===
'object'
)
{
}
else
if
(
typeof
valueConfig
===
'object'
)
{
target
[
key
]
=
{};
copyProp
(
target
[
key
],
data
[
key
],
valueConfig
)
}
...
...
@@ -138,3 +138,35 @@ export function supplement(value: number, count: number): string {
}
return
zeros
[
index
]
+
value
;
}
/**
* 点eval
* @param expression
* @param context
* @param strict
* @param dotChar
*/
export
function
dotEval
(
expression
:
string
,
context
=
window
,
strict
=
true
,
dotChar
=
'.'
)
{
if
(
!
expression
||
!
context
)
{
return
context
;
}
let
result
=
expression
.
split
(
dotChar
)
.
reduce
(
function
(
pre
,
cur
,
index
,
arr
)
{
let
ref
;
if
(
strict
)
{
if
(
pre
&&
pre
.
hasOwnProperty
(
cur
))
{
ref
=
pre
[
cur
];
}
else
{
const
e
=
`can not get
${
cur
}
on
${
index
===
0
?
'context'
:
arr
.
slice
(
0
,
index
).
join
(
dotChar
)}
`
;
console
.
warn
(
e
);
throw
new
Error
(
e
);
}
}
else
{
ref
=
cur
&&
pre
[
cur
]
||
pre
}
return
ref
;
},
context
);
return
result
;
}
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