Skip to content

Commit

Permalink
Merge commit 'b152d471637781c3e0242c2b9f06122d1ea56afa'
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMyzrailGorynych committed Apr 17, 2022
2 parents 8782b6a + b152d47 commit 237fce6
Show file tree
Hide file tree
Showing 39 changed files with 1,574 additions and 470 deletions.
35 changes: 35 additions & 0 deletions app/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
## v2.0.2

*Sun Apr 17 2022*

### ✨ New Features

* Internal: Add two utility classes to change cursor on specific elements

### ⚡️ General Improvements

* Add an explicit close button to the asset-selector, if there is a cancel action defined to it. Also adds an example of a "close" button pattern inside a dimmer to the CSS stylebook
* Add basic typings to Window object and to the global scope (setTimeout and co, atob, btoa and such)
* Add support for ct.pointer to ct.vkeys
* Do not show "there is nothing here" filler if an asset viewer has to display a "none" option
* Move particles' node modules to the same folder as tandems'; enforce type checks on default emitters and tandems; add the missing uid property to emitter tandems.
* Tweak UI animations' duration; add subtle animations to most modal dialogues
* Update Chinese Simplified translations (#335 by @emaoshushu)
* Update Turkish translation. 100% coverage thanks to Sarpmanon.js!

### 🐛 Bug Fixes

* 🍱 Fix music stopping on the third level of the Lab Raid demo. Thanks mugeen for finding the issue and its source.
* Changing speed of a copy from zero should reuse its saved direction (zeroDirectionAccessor). Closes #334
* Fix asset inputs' styles affecting button groups deeper into its tree
* Fix broken project-aware code completions
* Fix ct.place.moveAlong (which is also this.moveContinuous for copies) using v1 directions values and not handling the latest bit of the path properly
* Fix ct.pointer not writing pointer.PrimaryKey, pointer.SecondaryKey to the Actions system
* Fix the asset selector applying styles to more than it should have. Fixes the group editor inside asset selection models being large as heck.
* Fix the asset-selector incorrectly capturing clicks on its modal's background
* Fix the usage of non-existent ct.place methods in ct.pointer

### 🌐 Website

* :zap: Update list of features in the presskit

## v2.0.1

*Sat Mar 26 2022*
Expand Down
259 changes: 131 additions & 128 deletions app/data/ct.libs/gamepad/index.js
Original file line number Diff line number Diff line change
@@ -1,128 +1,131 @@
/* Based on https://github.com/luser/gamepadtest */

(function() {
const standardMapping = {
controllers: {},
buttonsMapping: [
'Button1',
'Button2',
'Button3',
'Button4',
'L1',
'R1',
'L2',
'R2',
'Select',
'Start',
// here, must have same name as in module.js
'L3',
//'LStickButton',
// here, too...
'R3',
//'RStickButton',
// up, down, left and right are all mapped as axes.
'Up',
'Down',
'Left',
'Right'

// + a special button code `Any`, that requires special handling
],
axesMapping: ['LStickX', 'LStickY', 'RStickX', 'RStickY']
};

const prefix = 'gamepad.';

const setRegistry = function(key, value) {
ct.inputs.registry[prefix + key] = value;
};
const getRegistry = function(key) {
return ct.inputs.registry[prefix + key] || 0;
};

const getGamepads = function() {
return navigator.getGamepads();
};

const addGamepad = function(gamepad) {
standardMapping.controllers[gamepad.index] = gamepad;
};

const scanGamepads = function() {
const gamepads = getGamepads();
for (let i = 0, len = gamepads.length; i < len; i++) {
if (gamepads[i]) {
const {controllers} = standardMapping;
if (!(gamepads[i].index in controllers)) {
// add new gamepad object
addGamepad(gamepads[i]);
} else {
// update gamepad object state
controllers[gamepads[i].index] = gamepads[i];
}
}
}
};

const updateStatus = function() {
scanGamepads();
let j;
const {controllers} = standardMapping;
const {buttonsMapping} = standardMapping;
const {axesMapping} = standardMapping;
for (j in controllers) {
/**
* @type {Gamepad}
*/
const controller = controllers[j];
const buttonsLen = controller.buttons.length;

// Reset the 'any button' input
setRegistry('Any', 0);
// loop through all the known button codes and update their state
for (let i = 0; i < buttonsLen; i++) {
setRegistry(buttonsMapping[i], controller.buttons[i].value);
// update the 'any button', if needed
setRegistry('Any', Math.max(getRegistry('Any'), controller.buttons[i].value));
ct.gamepad.lastButton = buttonsMapping[i];
}

// loop through all the known axes and update their state
const axesLen = controller.axes.length;
for (let i = 0; i < axesLen; i++) {
setRegistry(axesMapping[i], controller.axes[i]);
}
}
};

ct.gamepad = Object.assign(new PIXI.utils.EventEmitter(), {
list: getGamepads(),
connected(e) {
ct.gamepad.emit('connected', e.gamepad, e);
addGamepad(e.gamepad);
},
disconnected(e) {
ct.gamepad.emit('disconnected', e.gamepad, e);
delete standardMapping.controllers[e.gamepad.index];
},
getButton: code => {
if (standardMapping.buttonsMapping.indexOf(code) === -1 && code !== 'Any') {
throw new Error(`[ct.gamepad] Attempt to get the state of a non-existing button ${code}. A typo?`);
}
return getRegistry(code);
},
getAxis: code => {
if (standardMapping.axesMapping.indexOf(code) === -1) {
throw new Error(`[ct.gamepad] Attempt to get the state of a non-existing axis ${code}. A typo?`);
}
return getRegistry(code);
},
lastButton: null
});

// register events
window.addEventListener('gamepadconnected', ct.gamepad.connected);
window.addEventListener('gamepaddisconnected', ct.gamepad.disconnected);
// register a ticker listener
ct.pixiApp.ticker.add(updateStatus);
})();
/* Based on https://github.com/luser/gamepadtest */

(function ctGamepad() {
const standardMapping = {
controllers: {},
buttonsMapping: [
'Button1',
'Button2',
'Button3',
'Button4',
'L1',
'R1',
'L2',
'R2',
'Select',
'Start',
// here, must have same name as in module.js
'L3',
//'LStickButton',
// here, too...
'R3',
//'RStickButton',
// up, down, left and right are all mapped as axes.
'Up',
'Down',
'Left',
'Right'

// + a special button code `Any`, that requires special handling
],
axesMapping: ['LStickX', 'LStickY', 'RStickX', 'RStickY']
};

const prefix = 'gamepad.';

const setRegistry = function (key, value) {
ct.inputs.registry[prefix + key] = value;
};
const getRegistry = function (key) {
return ct.inputs.registry[prefix + key] || 0;
};

const getGamepads = function () {
if (navigator.getGamepads) {
return navigator.getGamepads();
}
return [];
};

const addGamepad = function (gamepad) {
standardMapping.controllers[gamepad.index] = gamepad;
};

const scanGamepads = function () {
const gamepads = getGamepads();
for (let i = 0, len = gamepads.length; i < len; i++) {
if (gamepads[i]) {
const {controllers} = standardMapping;
if (!(gamepads[i].index in controllers)) {
// add new gamepad object
addGamepad(gamepads[i]);
} else {
// update gamepad object state
controllers[gamepads[i].index] = gamepads[i];
}
}
}
};

const updateStatus = function () {
scanGamepads();
let j;
const {controllers} = standardMapping;
const {buttonsMapping} = standardMapping;
const {axesMapping} = standardMapping;
for (j in controllers) {
/**
* @type {Gamepad}
*/
const controller = controllers[j];
const buttonsLen = controller.buttons.length;

// Reset the 'any button' input
setRegistry('Any', 0);
// loop through all the known button codes and update their state
for (let i = 0; i < buttonsLen; i++) {
setRegistry(buttonsMapping[i], controller.buttons[i].value);
// update the 'any button', if needed
setRegistry('Any', Math.max(getRegistry('Any'), controller.buttons[i].value));
ct.gamepad.lastButton = buttonsMapping[i];
}

// loop through all the known axes and update their state
const axesLen = controller.axes.length;
for (let i = 0; i < axesLen; i++) {
setRegistry(axesMapping[i], controller.axes[i]);
}
}
};

ct.gamepad = Object.assign(new PIXI.utils.EventEmitter(), {
list: getGamepads(),
connected(e) {
ct.gamepad.emit('connected', e.gamepad, e);
addGamepad(e.gamepad);
},
disconnected(e) {
ct.gamepad.emit('disconnected', e.gamepad, e);
delete standardMapping.controllers[e.gamepad.index];
},
getButton: code => {
if (standardMapping.buttonsMapping.indexOf(code) === -1 && code !== 'Any') {
throw new Error(`[ct.gamepad] Attempt to get the state of a non-existing button ${code}. A typo?`);
}
return getRegistry(code);
},
getAxis: code => {
if (standardMapping.axesMapping.indexOf(code) === -1) {
throw new Error(`[ct.gamepad] Attempt to get the state of a non-existing axis ${code}. A typo?`);
}
return getRegistry(code);
},
lastButton: null
});

// register events
window.addEventListener('gamepadconnected', ct.gamepad.connected);
window.addEventListener('gamepaddisconnected', ct.gamepad.disconnected);
// register a ticker listener
ct.pixiApp.ticker.add(updateStatus);
})();
2 changes: 1 addition & 1 deletion app/data/ct.libs/gamepad/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"tagline": "Connect your gamepad to the Actions system.",
"name_Ru": "Геймпад",
"tagline_Ru": "Подключает джойстики к системе Действий.",
"version": "1.0.0",
"version": "1.0.1",
"packageName": "gamepad",
"authors": [
{
Expand Down
11 changes: 8 additions & 3 deletions app/data/ct.libs/place/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,13 @@
length *= -1;
dir += 180;
}
var dx = Math.cos(dir * Math.PI / -180) * precision,
dy = Math.sin(dir * Math.PI / -180) * precision;
for (let i = 0; i < length; i += precision) {
var dx = Math.cos(dir * Math.PI / 180) * precision,
dy = Math.sin(dir * Math.PI / 180) * precision;
while (length > 0) {
if (length < 1) {
dx *= length;
dy *= length;
}
const occupied = ct.place.occupied(me, me.x + dx, me.y + dy, cgroup);
if (!occupied) {
me.x += dx;
Expand All @@ -613,6 +617,7 @@
} else {
return occupied;
}
length--;
}
return false;
},
Expand Down
16 changes: 11 additions & 5 deletions app/data/ct.libs/pointer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@
tiltY: pointer.tiltY,
twist: pointer.twist
});
for (const button in buttonMappings) {
// eslint-disable-next-line no-bitwise
setKey(button, (pointer.buttons & buttonMappings[button]) === button ? 1 : 0);
}
};

var handleHoverStart = function (e) {
Expand Down Expand Up @@ -184,7 +180,7 @@
if (specificPointer && pointer.id !== specificPointer.id) {
continue;
}
if (ct.place[uiSpace ? 'collideUi' : 'collide'](copy, {
if (ct.place.collide(copy, {
x: uiSpace ? pointer.xui : pointer.x,
y: uiSpace ? pointer.yui : pointer.y,
scale: {
Expand Down Expand Up @@ -356,6 +352,16 @@
lastPanY = y;
lastAngle = angle;
lastScaleDistance = distance;

for (const button in buttonMappings) {
setKey(button, 0);
for (const pointer of ct.pointer.down) {
// eslint-disable-next-line no-bitwise
if ((pointer.buttons & buttonMappings[button]) === buttonMappings[button]) {
setKey(button, 1);
}
}
}
},
lock() {
if (locking) {
Expand Down
2 changes: 1 addition & 1 deletion app/data/ct.libs/pointer/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name_Ru": "Указатель",
"tagline": "A uniform API for any type of pointer devices, be it touchscreens, pen tablets, or mouse.",
"tagline_Ru": "Единый API для всех видов указателей — мышек, тач-экранов, графических планшетов и т.д.",
"version": "1.0.0",
"version": "1.0.1",
"authors": [{
"name": "Cosmo Myzrail Gorynych",
"mail": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion app/data/ct.libs/vkeys/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function () {
(function ctVkeys() {
ct.vkeys = {
button(options) {
var opts = ct.u.ext({
Expand Down
Loading

0 comments on commit 237fce6

Please sign in to comment.