Initial commit.

This commit is contained in:
genxium
2022-09-20 23:50:01 +08:00
commit e90a335c56
432 changed files with 101884 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
(function () {
if (!(cc && cc.Audio)) {
return;
}
cc.Audio.prototype.stop = function () {
if (!this._element) return;
this._element.stop();
this._element.currentTime = 0;
this._unbindEnded();
this.emit('stop');
this._state = cc.Audio.State.STOPPED;
};
})();

View File

@@ -0,0 +1,79 @@
const inputManager = _cc.inputManager;
let isInit = false;
Object.assign(inputManager, {
setAccelerometerEnabled (isEnable) {
let scheduler = cc.director.getScheduler();
scheduler.enableForTarget(this);
if (isEnable) {
this._registerAccelerometerEvent();
scheduler.scheduleUpdate(this);
}
else {
this._unregisterAccelerometerEvent();
scheduler.unscheduleUpdate(this);
}
},
// No need to adapt
// setAccelerometerInterval (interval) { },
_registerAccelerometerEvent () {
this._accelCurTime = 0;
if (!isInit) {
isInit = true;
let self = this;
this._acceleration = new cc.Acceleration();
wx.onAccelerometerChange && wx.onAccelerometerChange(function (res) {
let x = res.x;
let y = res.y;
let systemInfo = wx.getSystemInfoSync();
let windowWidth = systemInfo.windowWidth;
let windowHeight = systemInfo.windowHeight;
if (windowHeight < windowWidth) {
// Landscape orientation
// For left landscape
// x = y;
// y = -x;
// For right landscape
// x = -y;
// y = x;
// We suggest to use right landscape by default
let tmp = x;
x = -y;
y = tmp;
}
self._acceleration.x = x;
self._acceleration.y = y;
self._acceleration.z = res.z;
});
}
else {
wx.startAccelerometer && wx.startAccelerometer({
fail: function (err) {
cc.error('register Accelerometer failed ! err: ' + err);
},
success: function () {},
complete: function () {},
});
}
},
_unregisterAccelerometerEvent () {
this._accelCurTime = 0;
wx.stopAccelerometer && wx.stopAccelerometer({
fail: function (err) {
cc.error('unregister Accelerometer failed ! err: ' + err);
},
success: function () {},
complete: function () {},
});
},
});

View File

@@ -0,0 +1,140 @@
(function () {
if (!(cc && cc.EditBox)) {
return;
}
var KeyboardReturnType = cc.EditBox.KeyboardReturnType;
var _p = cc.EditBox._EditBoxImpl.prototype;
var _currentEditBoxImpl = null;
function getKeyboardReturnType (type) {
switch (type) {
case KeyboardReturnType.DEFAULT:
case KeyboardReturnType.DONE:
return 'done';
case KeyboardReturnType.SEND:
return 'send';
case KeyboardReturnType.SEARCH:
return 'search';
case KeyboardReturnType.GO:
return 'go';
case KeyboardReturnType.NEXT:
return 'next';
}
return 'done';
}
function updateLabelsVisibility(editBox) {
var placeholderLabel = editBox._placeholderLabel;
var textLabel = editBox._textLabel;
var displayText = editBox._impl._text;
placeholderLabel.node.active = displayText === '';
textLabel.node.active = displayText !== '';
}
cc.EditBox.prototype.editBoxEditingDidBegan = function () {
cc.Component.EventHandler.emitEvents(this.editingDidBegan, this);
this.node.emit('editing-did-began', this);
};
cc.EditBox.prototype.editBoxEditingDidEnded = function () {
cc.Component.EventHandler.emitEvents(this.editingDidEnded, this);
this.node.emit('editing-did-ended', this);
};
cc.EditBox.prototype._updateStayOnTop = function () {
// wx not support
};
_p.setFocus = function () {
this._beginEditing();
};
_p.isFocused = function () {
return this._editing;
};
_p.setInputMode = function (inputMode) {
this._inputMode = inputMode;
};
_p._beginEditing = function () {
this.createInput();
};
_p._endEditing = function () {
this._delegate && this._delegate.editBoxEditingDidEnded();
this._editing = false;
};
_p.createInput = function () {
// Unregister keyboard event listener in old editBoxImpl if keyboard haven't hidden.
if (_currentEditBoxImpl !== this) {
if (_currentEditBoxImpl) {
_currentEditBoxImpl._endEditing();
wx.offKeyboardConfirm(_currentEditBoxImpl.onKeyboardConfirmCallback);
wx.offKeyboardInput(_currentEditBoxImpl.onKeyboardInputCallback);
wx.offKeyboardComplete(_currentEditBoxImpl.onKeyboardCompleteCallback);
}
_currentEditBoxImpl = this;
}
var multiline = this._inputMode === cc.EditBox.InputMode.ANY;
var editBoxImpl = this;
this._editing = true;
function onKeyboardConfirmCallback (res) {
editBoxImpl._text = res.value;
editBoxImpl._delegate && editBoxImpl._delegate.editBoxEditingReturn && editBoxImpl._delegate.editBoxEditingReturn();
wx.hideKeyboard({
success: function (res) {
},
fail: function (res) {
cc.warn(res.errMsg);
}
});
}
function onKeyboardInputCallback (res) {
if (res.value.length > editBoxImpl._maxLength) {
res.value = res.value.slice(0, editBoxImpl._maxLength);
}
if (editBoxImpl._delegate && editBoxImpl._delegate.editBoxTextChanged) {
if (editBoxImpl._text !== res.value) {
editBoxImpl._text = res.value;
editBoxImpl._delegate.editBoxTextChanged(editBoxImpl._text);
updateLabelsVisibility(editBoxImpl._delegate);
}
}
}
function onKeyboardCompleteCallback () {
editBoxImpl._endEditing();
wx.offKeyboardConfirm(onKeyboardConfirmCallback);
wx.offKeyboardInput(onKeyboardInputCallback);
wx.offKeyboardComplete(onKeyboardCompleteCallback);
_currentEditBoxImpl = null;
}
wx.showKeyboard({
defaultValue: editBoxImpl._text,
maxLength: editBoxImpl._maxLength,
multiple: multiline,
confirmHold: false, // hide keyboard mannually by wx.onKeyboardConfirm
confirmType: getKeyboardReturnType(editBoxImpl._returnType),
success: function (res) {
editBoxImpl._delegate && editBoxImpl._delegate.editBoxEditingDidBegan && editBoxImpl._delegate.editBoxEditingDidBegan();
},
fail: function (res) {
cc.warn(res.errMsg);
editBoxImpl._endEditing();
}
});
wx.onKeyboardConfirm(onKeyboardConfirmCallback);
wx.onKeyboardInput(onKeyboardInputCallback);
wx.onKeyboardComplete(onKeyboardCompleteCallback);
};
})();

View File

@@ -0,0 +1,59 @@
var _frameRate = 60;
cc.game.setFrameRate = function (frameRate) {
_frameRate = frameRate;
if (wx.setPreferredFramesPerSecond) {
wx.setPreferredFramesPerSecond(frameRate);
}
else {
if (this._intervalId) {
window.cancelAnimFrame(this._intervalId);
}
this._intervalId = 0;
this._paused = true;
this._setAnimFrame();
this._runMainLoop();
}
};
cc.game._setAnimFrame = function () {
this._lastTime = performance.now();
this._frameTime = 1000 / _frameRate;
if (_frameRate !== 60 && _frameRate !== 30) {
window.requestAnimFrame = this._stTime;
window.cancelAnimFrame = this._ctTime;
}
else {
window.requestAnimFrame = window.requestAnimationFrame || this._stTime;
window.cancelAnimFrame = window.cancelAnimationFrame || this._ctTime;
}
};
cc.game.getFrameRate = function () {
return _frameRate;
};
cc.game._runMainLoop = function () {
var self = this, callback, config = self.config,
director = cc.director,
skip = true, frameRate = config.frameRate;
cc.debug.setDisplayStats(config.showFPS);
callback = function () {
if (!self._paused) {
self._intervalId = window.requestAnimFrame(callback);
if (frameRate === 30) {
if (skip = !skip) {
return;
}
}
director.mainLoop();
}
};
self._intervalId = window.requestAnimFrame(callback);
self._paused = false;
};
// wechat game platform not support this api
cc.game.end = function () {};

View File

@@ -0,0 +1,37 @@
cc.loader.downloader.loadSubpackage = function (name, completeCallback) {
wx.loadSubpackage({
name: name,
success: function () {
if (completeCallback) completeCallback();
},
fail: function () {
if (completeCallback) completeCallback(new Error(`Failed to load subpackage ${name}`));
}
})
};
function downloadScript (item, callback, isAsync) {
var url = '../../' + item.url;
require(url);
callback(null, item.url);
}
function loadFont (item) {
var url = item.url;
var fontFamily = wx.loadFont(url);
return fontFamily || 'Arial';
}
cc.loader.downloader.addHandlers({
js : downloadScript
});
cc.loader.loader.addHandlers({
// Font
font: loadFont,
eot: loadFont,
ttf: loadFont,
woff: loadFont,
svg: loadFont,
ttc: loadFont,
});

View File

@@ -0,0 +1,6 @@
require('./Game');
require('./Audio');
require('./Editbox');
require('./DeviceMotionEvent');
require('./downloader');
require('./misc');

View File

@@ -0,0 +1,7 @@
// cc.AuidioEngine
if (cc && cc.audioEngine) {
cc.audioEngine._maxAudioInstance = 10;
}
// cc.Macro
cc.macro.DOWNLOAD_MAX_CONCURRENT = 10;