Commit f053e91f authored by rockyl's avatar rockyl

修改默认适配为左上角对齐

过程、脚本、自定义模块代码抽离功能
parent 4066646b
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -373,8 +373,8 @@ export class Stage extends Container { ...@@ -373,8 +373,8 @@ export class Stage extends Container {
s.rootDiv = div; s.rootDiv = div;
s.setFrameRate(frameRate); s.setFrameRate(frameRate);
s._scaleMode = scaleMode; s._scaleMode = scaleMode;
s.anchorX = desW >> 1; //s.anchorX = desW >> 1;
s.anchorY = desH >> 1; //s.anchorY = desH >> 1;
//初始化canvas //初始化canvas
var canvas = document.createElement("canvas"); var canvas = document.createElement("canvas");
...@@ -840,16 +840,16 @@ export class Stage extends Container { ...@@ -840,16 +840,16 @@ export class Stage extends Container {
let divW = s.divWidth * devicePixelRatio; let divW = s.divWidth * devicePixelRatio;
let desH = s.desHeight; let desH = s.desHeight;
let desW = s.desWidth; let desW = s.desWidth;
s.anchorX = desW >> 1; //s.anchorX = desW >> 1;
s.anchorY = desH >> 1; //s.anchorY = desH >> 1;
//设备是否为竖屏 //设备是否为竖屏
let isDivH = divH > divW; let isDivH = divH > divW;
//内容是否为竖屏内容 //内容是否为竖屏内容
let isDesH = desH > desW; let isDesH = desH > desW;
let scaleY = 1; let scaleY = 1;
let scaleX = 1; let scaleX = 1;
s.x = (divW - desW) >> 1; //s.x = (divW - desW) >> 1;
s.y = (divH - desH) >> 1; //s.y = (divH - desH) >> 1;
if (s.autoSteering) { if (s.autoSteering) {
if (isDesH != isDivH) { if (isDesH != isDivH) {
let d = divH; let d = divH;
......
...@@ -42,7 +42,7 @@ export class WebglRenderer extends SystemRenderer { ...@@ -42,7 +42,7 @@ export class WebglRenderer extends SystemRenderer {
/** /**
* 批处理管理 * 批处理管理
*/ */
batchManager: BatchManager batchManager: BatchManager;
/** /**
* 纹理管理 * 纹理管理
*/ */
...@@ -91,7 +91,7 @@ export class WebglRenderer extends SystemRenderer { ...@@ -91,7 +91,7 @@ export class WebglRenderer extends SystemRenderer {
//The options passed in to create a new webgl context. //The options passed in to create a new webgl context.
var contextOptions = { var contextOptions = {
alpha: this.transparent, alpha: this.transparent,
antialias: this.options.antialias, antialias: !!this.options.antialias,
premultipliedAlpha: true, //一般png图片都不会预乘alpha,所以必为true,除非有些图集工具选择了premultipliedAlpha premultipliedAlpha: true, //一般png图片都不会预乘alpha,所以必为true,除非有些图集工具选择了premultipliedAlpha
stencil: true, stencil: true,
preserveDrawingBuffer: this.options.preserveDrawingBuffer, preserveDrawingBuffer: this.options.preserveDrawingBuffer,
......
...@@ -10,6 +10,7 @@ import {dataCenter} from "../game-warpper/data-center"; ...@@ -10,6 +10,7 @@ import {dataCenter} from "../game-warpper/data-center";
import {env} from "../game-warpper/enviroment"; import {env} from "../game-warpper/enviroment";
const log = true; const log = true;
const linkScheme = 'link://';
export class Process { export class Process {
private _config; private _config;
...@@ -94,7 +95,15 @@ export class Process { ...@@ -94,7 +95,15 @@ export class Process {
if (metaConfig) { if (metaConfig) {
this.updateProps(this._config.props = {}, payload, this._originProps, this._meta.props); this.updateProps(this._config.props = {}, payload, this._originProps, this._meta.props);
if (metaConfig.script) { if (metaConfig.script) {
let func = new Function('args', 'props', 'target', 'global', 'vm', warpAsyncScript(metaConfig.script)); let func;
if(metaConfig.script.indexOf(linkScheme) === 0){
func = this._vm.getScript(metaConfig.script.replace(linkScheme, ''));
}else{
func = new Function('args', 'props', 'target', 'global', 'vm', warpAsyncScript(metaConfig.script));
}
if(!func){
console.log();
}
let globalContext = this._vm.globalContext; let globalContext = this._vm.globalContext;
result = await func(payload, this._config.props, this._target, globalContext, this._vm); result = await func(payload, this._config.props, this._target, globalContext, this._vm);
} }
......
...@@ -12,14 +12,16 @@ export class VM { ...@@ -12,14 +12,16 @@ export class VM {
_globalContext; _globalContext;
_target; _target;
_id; _id;
_scriptMap;
setup(context) { setup(context) {
const {processMetaLibs, globalContext, target} = context; const {processMetaLibs, globalContext, target, scriptMap} = context;
this._processMetaLibs = processMetaLibs; this._processMetaLibs = processMetaLibs;
this._globalContext = globalContext; this._globalContext = globalContext;
this._target = target; this._target = target;
this._id = ID_INK++; this._id = ID_INK++;
this._scriptMap = scriptMap;
} }
async executeProcess(sequence, id, parentProcess, args) { async executeProcess(sequence, id, parentProcess, args) {
...@@ -44,6 +46,10 @@ export class VM { ...@@ -44,6 +46,10 @@ export class VM {
} }
} }
getScript(hash){
return this._scriptMap[hash];
}
get globalContext() { get globalContext() {
return this._globalContext; return this._globalContext;
} }
......
...@@ -6,6 +6,7 @@ import {VM} from "./VM"; ...@@ -6,6 +6,7 @@ import {VM} from "./VM";
let processMetaLibs = []; let processMetaLibs = [];
let globalContext = {}; let globalContext = {};
let scriptMap = {};
/** /**
* 设置过程库 * 设置过程库
...@@ -28,6 +29,10 @@ export function setGlobalContext(context) { ...@@ -28,6 +29,10 @@ export function setGlobalContext(context) {
} }
} }
export function setScriptMap(_scriptMap){
scriptMap = _scriptMap;
}
/** /**
* 执行行为 * 执行行为
* @param sequence * @param sequence
...@@ -41,6 +46,7 @@ export function executeBehavior(sequence, subEntry = 'main', target, args?) { ...@@ -41,6 +46,7 @@ export function executeBehavior(sequence, subEntry = 'main', target, args?) {
processMetaLibs, processMetaLibs,
globalContext, globalContext,
target, target,
scriptMap,
}); });
vm.executeProcess(sequence, subEntry, null, args) vm.executeProcess(sequence, subEntry, null, args)
.then(result => { .then(result => {
......
...@@ -115,7 +115,7 @@ class ScriptsProxy { ...@@ -115,7 +115,7 @@ class ScriptsProxy {
add(name, options, disabled): ScriptBase { add(name, options, disabled): ScriptBase {
let def = scriptDefs[name]; let def = scriptDefs[name];
if (!def) { if (!def) {
console.warn('script def not exists'); console.warn(`script[${name}] def not exists`);
return; return;
} }
let script: ScriptBase = new def(); let script: ScriptBase = new def();
......
...@@ -133,8 +133,8 @@ export class GameStage extends Container { ...@@ -133,8 +133,8 @@ export class GameStage extends Container {
injectEnv(env); injectEnv(env);
registerScripts(scripts); //registerScripts(scripts);
registerCustomModuleFromConfig(customs); //registerCustomModuleFromConfig(customs);
this.dataCenter.registerDataMapping(dataMapping); this.dataCenter.registerDataMapping(dataMapping);
setProcessMetaLibs(processes, builtinProcesses); setProcessMetaLibs(processes, builtinProcesses);
......
...@@ -6,15 +6,19 @@ import {Container} from "../../2d/display"; ...@@ -6,15 +6,19 @@ import {Container} from "../../2d/display";
const customMap = {}; const customMap = {};
export function registerCustomModule(config) { export function registerCustomModule(id, def) {
customMap[id] = def;
}
export function registerCustomCodeModule(config) {
const {id, code} = config; const {id, code} = config;
customMap[id] = importCJSCode(code, true); registerCustomModule(id, importCJSCode(code, true));
} }
export function registerCustomModuleFromConfig(config) { export function registerCustomModuleFromConfig(config) {
if(config){ if(config){
for (let item of config) { for (let item of config) {
registerCustomModule(item); registerCustomCodeModule(item);
} }
} }
} }
......
...@@ -8,6 +8,7 @@ export * from './decorators/events' ...@@ -8,6 +8,7 @@ export * from './decorators/events'
export * from './utils' export * from './utils'
export * from './decorators' export * from './decorators'
export * from './game-warpper' export * from './game-warpper'
export * from './behavior-runtime'
import {instantiate} from './game-warpper/view-interpreter' import {instantiate} from './game-warpper/view-interpreter'
export { export {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment