Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.0rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
dualface committed Oct 8, 2016
2 parents db1f50c + d9efe96 commit bd8f6e0
Show file tree
Hide file tree
Showing 60 changed files with 245 additions and 100 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ lua-project/simulator/

contents.xcworkspacedata
xcuserdata

installer/mac/Install\ Lua\ Support.app/Contents/Resources/dists/
installer/mac/*.dmg

installer/win/*.exe

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Creator 插件功能:
cocos new -l lua luaproject
```

2. 将 `creator-project/packages/creator-legacy-support` 目录复制到你的 Creator 工程的 `packages` 目录中。如果 `packages` 目录不存在,则需要创建一个。
2. 将 `creator-project/packages/creator-lua-support` 目录复制到你的 Creator 工程的 `packages` 目录中。如果 `packages` 目录不存在,则需要创建一个。

3. 用 Creator 打开工程,然后选择菜单 "Project(工程) -> Legacy Support -> Setup Target Project",打开目标工程设置对话框:
3. 用 Creator 打开工程,然后选择菜单 "Project(工程) -> Lua Support -> Setup Target Project",打开目标工程设置对话框:

![](docs/plugin-setup-dialog.png)

Expand All @@ -68,7 +68,7 @@ Creator 插件功能:
提示:

- 如果希望每次保存场景后自动更新 Lua 文件,请在设置对话框中选中“Auto Build”选项。
- 对于大型项目,自动构建可能较慢。此时应该禁用自动构建,然后通过菜单“Project(工程) -> Legacy Support -> Build Now”进行构建操作。
- 对于大型项目,自动构建可能较慢。此时应该禁用自动构建,然后通过菜单“Project(工程) -> Lua Support -> Build Now”进行构建操作。

~

Expand Down
43 changes: 0 additions & 43 deletions creator-project/packages/creator-legacy-support/package.json

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ function _convertId(props) {

class BuildWorker extends WorkerBase {
run(state, callback) {
Editor.Ipc.sendToAll('creator-legacy-support:state-changed', 'start', 0);
printlog('[creator-legacy-support] build start');
Editor.Ipc.sendToAll('creator-lua-support:state-changed', 'start', 0);
printlog('[creator-lua-support] build start');

Editor.require('app://asset-db');

Expand Down Expand Up @@ -118,8 +118,8 @@ class BuildWorker extends WorkerBase {
this._dumplua('files', Path.join(basedir, 'files.lua'), this.results.files);
this._dumplua('scenes', Path.join(basedir, 'scenes.lua'), this.results.scenes);

Editor.Ipc.sendToAll('creator-legacy-support:state-changed', 'finish', 100);
printlog('[creator-legacy-support] build completed');
Editor.Ipc.sendToAll('creator-lua-support:state-changed', 'finish', 100);
printlog('[creator-lua-support] build completed');

this._usedUuids = null;
this._db = null;
Expand All @@ -129,7 +129,7 @@ class BuildWorker extends WorkerBase {

_convertScenes() {
if (this._debug) {
printlog('[creator-legacy-support] converting scenes');
printlog('[creator-lua-support] converting scenes');
}

let selectedScenes = this.project.getSelectedScenes();
Expand All @@ -151,7 +151,7 @@ class BuildWorker extends WorkerBase {

_convertResources() {
if (this._debug) {
printlog('[creator-legacy-support] converting resources');
printlog('[creator-lua-support] converting resources');
}

this._db.queryMetas('db://assets/resources/**/', null, (err, metas) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const Project = require('./Project');

class CopyLibraryWorker extends WorkerBase {
run(state, callback) {
let files = JSON.parse(Fs.readFileSync(Editor.url('packages://creator-legacy-support/lua/files.json')));
let srcdir = Editor.url('packages://creator-legacy-support/lua/');
let files = JSON.parse(Fs.readFileSync(Editor.url('packages://creator-lua-support/lua/files.json')));
let srcdir = Editor.url('packages://creator-lua-support/lua/');
let destdir = state.path;

let step = 100 / files.length;
Expand All @@ -27,7 +27,10 @@ class CopyLibraryWorker extends WorkerBase {
this._updateProgress(step);
});

Editor.Ipc.sendToAll('creator-legacy-support:state-changed', 'finish', 100);
let contents = '\nreturn "' + this._opts.version + '"\n\n';
Fs.writeFileSync(Path.join(destdir, 'src', 'creator', 'version.lua'), contents);

Editor.Ipc.sendToAll('creator-lua-support:state-changed', 'finish', 100);

callback();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ module.exports = class Project {

validate() {
if (typeof this.path !== 'string' || this.path === '') {
Editor.warn('[Legacy Support] not set Target Project Path');
Editor.warn('[Lua Support] not set Target Project Path');
return false;
}

try {
let stat = Fs.statSync(this.path);
if (!stat.isDirectory()) {
Editor.warn('[Legacy Support] ' + this.path + ' is not directory');
Editor.warn('[Lua Support] ' + this.path + ' is not directory');
return false;
}
} catch (e) {
Editor.warn('[Legacy Support] invalid path: ' + this.path);
Editor.warn('[Lua Support] invalid path: ' + this.path);
return false;
}

Expand All @@ -44,11 +44,11 @@ module.exports = class Project {
configPath = Path.join(this.path, 'config.json');
let config = JSON.parse(Fs.readFileSync(configPath));
if (!config.init_cfg || !config.init_cfg.name) {
Editor.warn('[Legacy Support] ' + configPath + ' is not Cocos JSON file');
Editor.warn('[Lua Support] ' + configPath + ' is not Cocos JSON file');
return false;
}
} catch (e) {
Editor.warn('[Legacy Support] ' + configPath + ' is not Cocos JSON file');
Editor.warn('[Lua Support] ' + configPath + ' is not Cocos JSON file');
return false
}

Expand Down Expand Up @@ -82,9 +82,10 @@ module.exports = class Project {
return item.uuid == startSceneUuid;
});

if (!startSceneUuid || !found) {
if (!found) {
if (this.scenes.length) {
this.startSceneUuid = this.scenes[0].uuid;
this.scenes[0].checked = true;
} else {
this.startSceneUuid = '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
const Electron = require('electron');

class WorkerBase {
constructor(debug) {
constructor(opts) {
this._time = new Date();
this._progress = 0;
this._debug = debug;
this._opts = opts;
this._debug = opts.debug;
}

_updateProgress(step) {
this._progress += step;
Editor.Ipc.sendToAll('creator-legacy-support:state-changed',
Editor.Ipc.sendToAll('creator-lua-support:state-changed',
'progress ' + Math.floor(this._progress) + '%',
this._progress);
}
Expand All @@ -24,16 +25,16 @@ class WorkerBase {
let current = new Date();
if (this._debug) {
let times = (current.getTime() - this._time.getTime()) / 1000;
Editor.log('[creator-legacy-support] [' + tag + '] ' + times.toString() + 's');
Editor.log('[creator-lua-support] [' + tag + '] ' + times.toString() + 's');
}
this._time = current;
}
}


function registerWorker(workerClass, runEvent) {
Electron.ipcRenderer.on('creator-legacy-support:' + runEvent, (event, state, debug) => {
let worker = new workerClass(debug);
Electron.ipcRenderer.on('creator-lua-support:' + runEvent, (event, state, opts) => {
let worker = new workerClass(opts);
worker.run(state, () => {
event.reply();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"./src/creator/Connector.lua",
"./src/creator/Factory.lua",
"./src/creator/init.lua",
"./src/creator/version.lua",
"./src/JeffreyJSON.lua",
"./src/main.lua"
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
local string_sub = string.sub
local table_makeweak = table.makeweak

local creator = {
VERSION = "1.1.0"
}
local creator = {}
creator.VERSION = cc.import(".version")

local PrefabProtocol = cc.import(".assets.PrefabProtocol")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return ""
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ const Path = require('path');

const Electron = require('electron');

const PACKAGE_NAME = 'creator-lua-support';
const TIMEOUT = -1;
const DEBUG_WORKER = false;
let PACKAGE_VERSION = '';

const Project = require('./core/Project');


let _buildState = 'sleep';

function _fetchVersion() {
let info = Editor.Package.packageInfo(Editor.Package.packagePath(PACKAGE_NAME));
PACKAGE_VERSION = info.version;
}

function _runWorker(url, message, project) {
let worker;
worker = Editor.App.spawnWorker(url, () => {
worker.send(message, project.dumpState(), DEBUG_WORKER, (err) => {
let opts = {version: PACKAGE_VERSION, debug: DEBUG_WORKER};
let state = project.dumpState();
worker.send(message, state, opts, (err) => {
if (err) {
Editor.error(err);
}
Expand All @@ -33,22 +43,22 @@ function _runWorker(url, message, project) {
}

function _checkProject(reason) {
let state = Editor.Profile.load('creator-legacy-support.01', 'project');
let state = Editor.Profile.load(PACKAGE_NAME, 'project');
let project = new Project(state);

if (project.validate()) {
return project;
} else {
if (reason === 'ui') {
if (reason !== 'scene:saved') {
Editor.Dialog.messageBox({
type: 'warning',
buttons: [Editor.T('MESSAGE.ok')],
title: 'Warning - Legacy Support',
title: 'Warning - Lua Support',
message: 'Please setup Target Project first',
noLink: true,
});
} else {
Editor.warn('[Legacy Support] Please setup Target Project first');
Editor.warn('[Lua Support] Please setup Target Project first');
}
}

Expand All @@ -57,18 +67,18 @@ function _checkProject(reason) {

function _build(reason) {
if (_buildState !== 'sleep' && _buildState !== 'finish') {
Editor.warn('[Legacy Support] Building in progress');
Editor.warn('[Lua Support] Building in progress');
return;
}

let project = _checkProject(reason);
if (!project) return;
if (reason === 'scene:saved' && !project.autoBuild) return;

Editor.Ipc.sendToAll('creator-legacy-support:state-changed', 'start', 0);
Editor.Ipc.sendToAll('creator-lua-support:state-changed', 'start', 0);

let workerUrl = 'packages://creator-legacy-support/core/BuildWorker';
_runWorker(workerUrl, 'creator-legacy-support:run-build-worker', project);
let workerUrl = 'packages://creator-lua-support/core/BuildWorker';
_runWorker(workerUrl, 'creator-lua-support:run-build-worker', project);
}

function _copyLibrary(reason) {
Expand All @@ -87,30 +97,32 @@ function _copyLibrary(reason) {
let res = Editor.Dialog.messageBox({
type: 'warning',
buttons: ['Copy', Editor.T('MESSAGE.cancel')],
title: 'Warning - Legacy Support',
title: 'Warning - Lua Support',
message: message,
noLink: true,
});

if (res == 0) {
// 0: Copy
Editor.Ipc.sendToAll('creator-legacy-support:state-changed', 'start', 0);
Editor.Ipc.sendToAll('creator-lua-support:state-changed', 'start', 0);

let workerUrl = 'packages://creator-legacy-support/core/CopyLibraryWorker';
_runWorker(workerUrl, 'creator-legacy-support:run-copy-library-worker', project);
let workerUrl = 'packages://creator-lua-support/core/CopyLibraryWorker';
_runWorker(workerUrl, 'creator-lua-support:run-copy-library-worker', project);
}
}

module.exports = {
load() {
_fetchVersion();
Editor.log('[Lua Support] version ' + PACKAGE_VERSION);
},

unload() {
},

messages: {
'setup-target-project'() {
Editor.Panel.open('creator-legacy-support.01');
Editor.Panel.open(PACKAGE_NAME, {version: PACKAGE_VERSION});
},

'build'(event, reason) {
Expand All @@ -125,9 +137,9 @@ module.exports = {
_build('scene:saved');
},

'creator-legacy-support:state-changed'(event, state, progress) {
'creator-lua-support:state-changed'(event, state, progress) {
_buildState = state;
Editor.Ipc.sendToWins('creator-legacy-support:state-changed', state, progress);
Editor.Ipc.sendToWins('creator-lua-support:state-changed', state, progress);
}
}
};
Expand Down
Loading

0 comments on commit bd8f6e0

Please sign in to comment.