Skip to content

Commit

Permalink
release version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
koreanlancer committed Nov 15, 2020
1 parent 208e8e0 commit 468b47e
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 114 deletions.
71 changes: 42 additions & 29 deletions runtime_module/framework/entity/X9AutoReduceStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ var X9AutoReduceStyle = cc.Class({
mixins: [X9OrientedCommand],

statics: {
TYPE_ARG: "__type__",
CLASS_ARG: "__class__",
STATE_ID_ARG: "__state_id__"
},

ctor(){
Expand Down Expand Up @@ -75,12 +74,17 @@ var X9AutoReduceStyle = cc.Class({

getStateType(){
let state = this.getState();
return state[X9OrientedCommand.TYPE_ARG] ? state[X9OrientedCommand.TYPE_ARG] : 'default';
return state && state[X9OrientedCommand.TYPE_ARG] ? state[X9OrientedCommand.TYPE_ARG] : 'default';
},

getStateId(){
let state = this.getState();
return state && state[X9AutoReduceStyle.STATE_ID_ARG] ? state[X9AutoReduceStyle.STATE_ID_ARG] : 1;
},

getError(){
let state = this.getState();
return state[X9OrientedCommand.ERROR_ARG] ? state[X9OrientedCommand.ERROR_ARG] : null;
return state && state[X9OrientedCommand.ERROR_ARG] ? state[X9OrientedCommand.ERROR_ARG] : null;
},

export(){
Expand Down Expand Up @@ -125,6 +129,13 @@ var X9AutoReduceStyle = cc.Class({
}else{
newState = Object.assign(Object.create(null), state, mergedPayload);
}
//
// STATE_ID_ARG
let stateId = this.getStateId();
stateId++;
stateId = (stateId == Number.MAX_SAFE_INTEGER) ? 1 : stateId;
newState[X9AutoReduceStyle.STATE_ID_ARG] = stateId;
//
}else{
newState = state;
}
Expand All @@ -135,7 +146,7 @@ var X9AutoReduceStyle = cc.Class({
return newState;
}
}else{
throw new Error(this.__className + "::reduce(state, payload) : " +" Chỉ gọi trong Subclass của X9Com")
throw new Error(this.__className + "::reduce(state, payload) : " +" Chỉ gọi trong Subclass của X9Com");
}
return state;
},
Expand All @@ -152,9 +163,9 @@ var X9AutoReduceStyle = cc.Class({
let stateType = newState[X9OrientedCommand.TYPE_ARG];
this._exportData = this.onUpdateState(this._prepareUpdatingState(newState));
if( this._asyncViewCmds && this._asyncViewCmds.indexOf(stateType) == -1){
this._excuteViewTasks(stateType, ()=>{
this._excuteViewTasks(stateType, (stateId)=>{
// ket thuc xu ly view
this.clearThenEndUp();
this.clearThenEndUp(stateId);
CC_DEBUG && cc.log('End Task View ' + (this.__className ? this.__className : this.constructor.name));
});
}
Expand Down Expand Up @@ -200,17 +211,27 @@ var X9AutoReduceStyle = cc.Class({
}
},


clearThenEndUp(stateId){
let currentStateId = this.getStateId();
let state = this.getState();
if(stateId == currentStateId){
this._clearPrivateArgs(state);
}
},

//----------------------------------
// PRIVATE FUNCTION
//----------------------------------

//----------private command --------------------

clearThenEndUp(){
let state = this.getState();
delete state[X9OrientedCommand.TYPE_ARG];
delete state[X9OrientedCommand.CLASS_ARG];
delete state[X9OrientedCommand.ERROR_ARG];
_clearPrivateArgs(state){
if(state){
delete state[X9OrientedCommand.TYPE_ARG];
delete state[X9OrientedCommand.CLASS_ARG];
delete state[X9OrientedCommand.ERROR_ARG];
}
},

/**
Expand Down Expand Up @@ -266,26 +287,31 @@ var X9AutoReduceStyle = cc.Class({
}
asyncTasks.push(endTask);
asyncTasks.reduce( (accumulatorPromise, nextID) => {
return accumulatorPromise.then(() => {
return accumulatorPromise.then(() => {
return ((x9CompName)=>{
const x9Comp = (x9CompName === this) ? x9CompName : ( (typeof(x9CompName) !== 'function') ? this.use(x9CompName) : null );
const x9CompStateId = x9Comp ? x9Comp.getStateId() : null;
return new Promise((resolve, reject) => {
if( x9Comp && x9Comp.onUpdateView && (x9Comp.getError() == null) ){
// Có lỗi không vào view nữa.
x9Comp.onUpdateView(resolve);
x9Comp.clearThenEndUp(x9CompStateId);
}else{
x9Comp.clearThenEndUp();
// endTask
resolve();
}
});
})(nextID);
});
}, Promise.resolve());
}else{
const lastStateId = this.getStateId();
if(this.getError() == null){
this.onUpdateView(endTask);
this.onUpdateView(()=>{
endTask(lastStateId);
});
}else{
endTask();
endTask(lastStateId);
}
}
//
Expand Down Expand Up @@ -346,19 +372,6 @@ var X9AutoReduceStyle = cc.Class({
this._asyncViewTasks[cmdType] = taskView;
},



// methodThatReturnsAPromise(x9CompName) {
// let x9Comp = this.use(x9CompName);
// return new Promise((resolve, reject) => {
// if(x9Comp.onUpdateView){
// x9Comp.onUpdateView(resolve);
// }else{
// resolve();
// }
// });
// },

//--------------------------------------------\

/**
Expand Down
23 changes: 14 additions & 9 deletions runtime_module/framework/entity/X9Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ var Helper = {
return Dispatcher.instance();
},

decodeBase64URL(){

},

editCCClass: function(manualOptionHandler, completedDefineClassHandler){
if(!this.__edited){
var newCCClass = (function(superCCClass){
Expand Down Expand Up @@ -90,7 +94,7 @@ Helper.editCCClass(function(options){
let className = cc.js.getClassName(cls);
if(!className) return;
if(options && options.extends && options.extends !== cc.Class && (typeof options.extends !== 'object') ){
let catalogName = '';
let catalogName;
let superClass = options.extends;
let X9Command = require("X9Cmd");
let X9Component = require("X9Com");
Expand All @@ -100,14 +104,15 @@ Helper.editCCClass(function(options){
}else if(cc.js.isChildClassOf(superClass, X9Command)){
catalogName = 'X9 Command';
}
// Sửa lại nội dung của menu theo custome catalog.
let menuPath = catalogName + '/' + className;
cc._componentMenuItems.forEach(item => {
if(item.component === cls){
item.menuPath = menuPath;
}
});

if(catalogName){
// Sửa lại nội dung của menu theo custome catalog.
let menuPath = catalogName + '/' + className;
cc._componentMenuItems.forEach(item => {
if(item.component === cls){
item.menuPath = menuPath;
}
});
}
}
}
});
Expand Down
8 changes: 5 additions & 3 deletions runtime_module/framework/entity/X9LocalData.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const SAVEANDSHARE_URI = 'x9data://';
const DATA_URI = 'x9data://';
const DATA_NODE_NAME = 'share-data';
/**
* Tính năng save và share data cho X9Cmd và X9Com.
Expand All @@ -14,6 +14,7 @@ const X9LocalData = cc.Class({
statics:{
SEPARATE : '::',
},


/**
* Lấy share data trước. Nếu không có sẽ lấy vào từ localStorage.
Expand All @@ -30,7 +31,7 @@ const X9LocalData = cc.Class({
if(uuid && data){
data = data[uuid]
if(!data){
let classDataId = dataId.replace(SAVEANDSHARE_URI,'');
let classDataId = dataId.replace(DATA_URI,'');
return (classDataId != id) ? this.getData(classDataId) : null;
}
}else if(data && typeof data === 'object'){
Expand All @@ -49,6 +50,7 @@ const X9LocalData = cc.Class({
_splitDataIdToArray(id){
let uuid = null;
let dataId = this._validateId(id);
dataId = id ? dataId : (dataId + X9LocalData.SEPARATE + this.uuid) ;
if(dataId.indexOf(X9LocalData.SEPARATE) !== -1){
let dataIdArr = dataId.split(X9LocalData.SEPARATE);
dataId = dataIdArr[0];
Expand All @@ -60,7 +62,7 @@ const X9LocalData = cc.Class({
_validateId(id){
// Do not encript uri by Hash
let className = this.__className || cc.js.getClassName(this.constructor);
return SAVEANDSHARE_URI + (id ? id : (className + X9LocalData.SEPARATE + this.uuid));
return DATA_URI + (id ? id : className);
},

_validateData(data, keyPass){
Expand Down
44 changes: 0 additions & 44 deletions runtime_module/framework/entity/X9NetworkCommand.js

This file was deleted.

103 changes: 103 additions & 0 deletions runtime_module/framework/entity/X9NetworkData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
var X9NetworkData = cc.Class({
statics:{
TOKEN_KEY: '__token__',
},

/**
* Lấy character id từ URL
*/
// getCharacterIDFromURL() {
// let id, token;
// if (cc.sys.isBrowser) {
// let searchParams = new URLSearchParams(location.search);
// token = searchParams.get("i");
// if(token){
// let base64Url = token.split('.')[1];
// let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
// let jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
// return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
// }).join(''));
// // Verify
// // if(KJUR){
// // var isValid = KJUR.jws.JWS.verify(jsonPayload, "x9.guru.1M$$$", ["HS256"]);
// // cc.log('>>>> Charid :: ' + id + ' valid: ' + isValid);
// // }
// // Save token
// let buf = new ArrayBuffer(jsonPayload.length*2); // 2 bytes for each char
// let bufView = new Uint16Array(buf);
// for (var i=0, strLen=jsonPayload.length; i < strLen; i++) {
// bufView[i] = str.charCodeAt(i);
// }
// this._jwtToken = buf;
// //
// let payloadObj = JSON.parse(jsonPayload);
// id = payloadObj.charId;
// //
// cc.log('parse token:: ' + String.fromCharCode.apply(null, new Uint16Array(this._jwtToken)))
// //

// }else if(CC_DEBUG){
// id = searchParams.get("id");
// }
// //
// id = parseInt(id);
// if (id == NaN) return null;
// }
// return id;
// },

getURLParams(key){
return new URLSearchParams(location.search).get(key);
},

/**
*
* @param {*} tokenKey
*/
setToken(tokenKey){
let classPrototype = this.constructor.prototype;
classPrototype.__$request = classPrototype.__$request ? classPrototype.__$request : classPrototype.request;
classPrototype.request = function(url, data, token){
let requestToken = token ? token : tokenKey;
return this.__$request(url, data, requestToken);
}
},


/**
*
* @param {*} url
* @param {*} data
*/
request(url, data, token) {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = ()=>{
// this._httpStatus = xhr.status;
if (xhr.readyState == 4) {
if(xhr.status >= 200 && xhr.status < 400){
let response = xhr.responseText;
resolve(response);
}else{
reject(url);
}
}
};
xhr.onerror = ()=>{
reject(url);
} ;

xhr.open( (data ? 'POST' : 'GET'), url, true );
xhr.setRequestHeader("Content-type", "application/json");
if(token){
CC_DEBUG && cc.log(this.uuid + ' Request with Token:: ' + token);
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
}
data ? xhr.send(JSON.stringify(data)) : xhr.send();

});
},



})
Loading

0 comments on commit 468b47e

Please sign in to comment.