Commit f053e91f authored by rockyl's avatar rockyl

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

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