invoke shaderplugin success

This commit is contained in:
pengfei.zhou
2019-12-19 13:34:56 +08:00
parent 1b65fd5ba0
commit 5854d29b93
8 changed files with 65 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
import { jsObtainContext } from 'doric/src/runtime/sandbox'
import { jsObtainContext, jsCallEntityMethod } from 'doric/src/runtime/sandbox'
import { Panel } from 'doric'
import { DoricPlugin } from "./DoricPlugin"
import { createContext } from "./DoricDriver"
@@ -20,16 +20,24 @@ export class DoricContext {
createContext(this.contextId, content)
doricContexts.set(this.contextId, this)
}
get context() {
return jsObtainContext(this.contextId)
}
get panel() {
return this.context?.entity as Panel
return jsObtainContext(this.contextId)?.entity as Panel
}
getEntityMethod(method: string) {
return Reflect.get(this.panel, method, this.panel) as Function
invokeEntityMethod(method: string, ...otherArgs: any) {
const argumentsList: any = [this.contextId]
for (let i = 0; i < arguments.length; i++) {
argumentsList.push(arguments[i])
}
Reflect.apply(jsCallEntityMethod, this.panel, argumentsList)
}
init(frame: {
width: number,
height: number,
}, extra?: object) {
this.invokeEntityMethod("__init__", frame, extra ? JSON.stringify(extra) : undefined)
}
}

View File

@@ -35,6 +35,8 @@ ${content}
}
function initDoric() {
injectGlobalObject("nativeEmpty", () => undefined)
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {
switch (type) {
case 'd':
@@ -92,7 +94,7 @@ function initDoric() {
e => {
jsCallReject(contextId, callbackId, e)
})
} else {
} else if (ret !== undefined) {
jsCallResolve(contextId, callbackId, ret)
}
return true

View File

@@ -17,6 +17,9 @@ export class DoricElement extends HTMLElement {
load(content: string) {
this.context = new DoricContext(content)
this.context.getEntityMethod('log')()
this.context.init({
width: 100,
height: 100
})
}
}

View File

@@ -1,4 +1,5 @@
import { DoricPluginClass } from "./DoricPlugin"
import { ShaderPlugin } from "./plugins/ShaderPlugin"
const bundles: Map<string, string> = new Map
@@ -20,3 +21,5 @@ export function registerPlugin(name: string, plugin: DoricPluginClass) {
export function acquirePlugin(name: string) {
return plugins.get(name)
}
registerPlugin('shader', ShaderPlugin)

View File

@@ -0,0 +1,7 @@
import { DoricPlugin } from "../DoricPlugin";
export class ShaderPlugin extends DoricPlugin {
render(ret: any) {
console.log('render', ret)
}
}