Skip to content

Commit

Permalink
Merge commit '0cd3bb6672baa96ab1a9a08608d740b3fcb4331d'
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMyzrailGorynych committed Mar 28, 2021
2 parents 502c47b + 0cd3bb6 commit 0a9b109
Show file tree
Hide file tree
Showing 138 changed files with 9,249 additions and 1,042 deletions.
51 changes: 51 additions & 0 deletions app/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
## v1.6.0

*Sun Mar 28 2021*

### ✨ New Features

* Add `ct.filters` module by SN frrom our Discord server. The module allows creating special visual effects with filters or custom shaders, applied to your copies or a whole viewport
* Add `ct.light` module for adding ambient lighting and textured lights
* Add `ct.matter` module for 2D physics. See the new example!
* Bundle `ct.nakama` module by @alexandargyurov — you can now create online games with ct.js!
* Group modded fields into collapsible sections with a new field type
* Nano ID catmod of the same-named tiny library by Andrei Sitnik
* Optionally make a camera stay inside a specific rectangle with new rooms' settings.

### ⚡️ General Improvements

* :bento: Update Electron used in desktop builds to v11.1.1
* Allow Background class to accept a pixi.js texture
* Modify emitter tandems to use `PIXI.ParticleContainer`. Provides better performance, and also fixes issue with un-tintable emitters.
* Renovate `ct.desktop` -> quit method
* Select only the needed Nw.js version for debugging

### 🐛 Bug Fixes

* Allow resetting values in type and texture inputs at modded fields
* Fix "}" at the end of some texture files' names
* Fix bitmap font's XML ("kerings" typo")
* Fix broken context menu entry for textures to create a type from them
* Fix crashes of built-in debugger; disable nw and node in the devtools
* Fix `ct.place.meet` returning duplicated references to copies if querying for multiple obstacles
* Fix icons for nightly and regular releases
* Fix Point2D initialization for modded fields
* In rooms' copy spawning code, check for scaling extensions separately
* Remove the old main-menu tag

### 🍱 Demos, Dependencies and Stuff

* Update nw.js to v0.51.1

### 📝 Docs

* Add "Dragging Copies Around" tutorial by @qewer33
* :bug: Add missing methods `ct.types.isCopy`, `ct.u.hexToPixi`, `ct.u.pixiToHex`
* :bug: Add `moveTo` and `teleportTo` methods in `ct.camera` (#49 by @firecakes)
* :sparkles: Add a list of gamedev resources
* :zap: Add categories to ct.u methods list
* :zap: Minor edits for JS intro, pt. 1
* :zap: Refurbish the home page. Move most old content to "Basic concepts". Add links to tutorials and the cheatsheet.
* 🐛 remove duplicate instruction to draw `scoreLabel`.
* Add a memo about `ct.desktop.isNw` and `ct.desktop.isElectron`
* Fixed typos in the Space Shooter tutorial by @sarturodev

## v1.5.1

Expand Down
4 changes: 3 additions & 1 deletion app/data/ct.libs/desktop/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Currently just has a method `ct.desktop.quit()`, which exits the game when packaged into executables.
Currently just has a method `ct.desktop.quit()`, which exits the game when packaged into executables.

Also has variables `ct.desktop.isNw` and `ct.desktop.isElectron` to differentiate between these two platforms.
27 changes: 17 additions & 10 deletions app/data/ct.libs/desktop/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
/* global nw */
ct.desktop = {
isNw: window.nw && window.nw.App,
isElectron: null,
quit() {
if (window.nw && window.nw.App) {
if (ct.desktop.isNw) {
if (window.iAmInCtIdeDebugger) {
nw.Window.get().close();
// eslint-disable-next-line no-console
console.warn('We don\'t quit because ct.js would quit as well. Let\'s imagine that the game has exited! :D');
} else {
nw.App.quit();
}
return true;
}
try {
} else if (ct.desktop.isElectron) {
require('electron').remote.getCurrentWindow().close();
return true;
} catch (e) {
console.error('Could not exit the game :c Are we in a browser?');
return false;
} else {
console.error('[ct.desktop/quit] Unknown environment :c Are we in a browser?');
}
}
};

try {
require('electron');
ct.desktop.isElectron = true;
} catch (e) {
ct.desktop.isElectron = false;
}

ct.desktop.isDesktop = ct.desktop.isNw || ct.desktop.isElectron;
4 changes: 4 additions & 0 deletions app/data/ct.libs/filters/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Version 1.0.0

- Initial release

111 changes: 111 additions & 0 deletions app/data/ct.libs/filters/DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# ct.filters

This module is a collection of shader filters.
It includes [PixiJS built-in filters](https://pixijs.download/dev/docs/PIXI.filters.html) and [additional PixiJS community-authored filters](https://filters.pixijs.download/main/docs/PIXI.filters.html) (version 3.2.2, 30 december 2020).

For each filter, you can check the PixiJS doc (links above) or use the ct.js autocomplete (to get all filters, all options of each filter, descriptions, types, and default values).

You can also interactively play with those filters to see how they work [here](https://pixijs.io/pixi-filters/tools/demo/).

## How it works?

All PIXI.DisplayObject (stage, room, copy, container, etc.) have a `filters` property.
It's an `array`.
You can add/remove/enable/disable several filters on the same element (beware of performance of course).

## How to add a filter with default options?

```js
const fx = ct.filters.addCRT(this);
```

## How to add a filter with mandatory params?

```js
// Replaces pure red with pure blue, and replaces pure green with pure white
const replacements = [
[0xff0000, 0x0000ff],
[0x00ff00, 0xffffff],
];
const fx = ct.filters.addMultiColorReplace(this, replacements);
```

## How to edit a filter?

```js
const fx = ct.filters.addGlow(this);
fx.color = 0xff004d;
fx.innerStrength = 1;
```

If you type `fx.` the autocomplete will show all the available options (with description, type and default value) for that filter.

Tip: You can `console.log` your `fx`, unfold the object and live tweak properties.

## Example of a very interesting filter with presets/methods:

```js
const fx = ct.filters.addColorMatrix(this);
// You can determine your own color matrix:
fx.matrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0.5, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
// Or use some nice predefined ones:
fx.night(0.1, true);
fx.polaroid(true);
fx.vintage(true);
```

For more (`browni`, `kodachrome`, `predator`, etc.) check the doc:
http://pixijs.download/release/docs/PIXI.filters.ColorMatrixFilter.html

## How to enable/disable a filter?

```js
const fx = ct.filters.addGodray(this);
fx.enabled = false;
```

If enabled is `true` the filter is applied, if `false` it will not.

## How to remove a filter?

```js
const fx = ct.filters.addCRT(this);
ct.filters.removeFilter(this, fx);
```

It removes a filter (`fx` in this example) from `this.filters`.

## How to add a custom filter?

```js
const fragment = `
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform float red;
uniform float green;
uniform float blue;
void main(void)
{
vec4 c = texture2D(uSampler, vTextureCoord);
vec3 rgb = c.rgb;
rgb.r *= red;
rgb.g *= green;
rgb.b *= blue;
c.rgb = rgb;
gl_FragColor = c;
}
`;

const uniforms = {
red: 1,
green: 0.8,
blue: 0.2}

const fx = ct.filters.custom(this, undefined, fragment, uniforms);
```
Mind, PIXI has a default vertex shader and a default fragment shader.
For more info, you can check these links:

* https://pixijs.download/dev/docs/PIXI.Filter.html
* https://github.com/pixijs/pixi.js/wiki/v5-Creating-filters
9 changes: 9 additions & 0 deletions app/data/ct.libs/filters/includes/pixi-filters.js

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions app/data/ct.libs/filters/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* Based on https://pixijs.io/pixi-filters/docs/PIXI.filters */
/* Sandbox demo: https://pixijs.io/pixi-filters/tools/demo/ */

(() => {
const filters = [
'Adjustment',
'AdvancedBloom',
'Ascii',
'Bevel',
'Bloom',
'BulgePinch',
'ColorMap',
'ColorOverlay',
'ColorReplace',
'Convolution',
'CrossHatch',
'CRT',
'Dot',
'DropShadow',
'Emboss',
'Glitch',
'Glow',
'Godray',
'KawaseBlur',
'MotionBlur',
'MultiColorReplace',
'OldFilm',
'Outline',
'Pixelate',
'RadialBlur',
'Reflection',
'RGBSplit',
'Shockwave',
'SimpleLightmap',
'TiltShift',
'Twist',
'ZoomBlur',
//Built-in filters
'Alpha',
'Blur',
'BlurPass',
'ColorMatrix',
'Displacement',
'FXAA',
'Noise'
];

const addFilter = (target, fx) => {
if (!target.filters) {
target.filters = [fx];
} else {
target.filters.push(fx);
}
return fx;
};

const createFilter = (target, filter, ...args) => {
let fx;
let filterName = filter + 'Filter';
if (filterName === 'BlurPassFilter') {
filterName = 'BlurFilterPass';
}
if (args.length > 0) {
fx = new PIXI.filters[filterName](...args);
} else {
fx = new PIXI.filters[filterName]();
}
return addFilter(target, fx);
};

ct.filters = {};

for (const filter of filters) {
ct.filters['add' + filter] = (target, ...args) =>
createFilter(target, filter, ...args);
}

ct.filters.remove = (target, filter) => {
for (const f in target.filters) {
if (target.filters[f] === filter) {
target.filters.splice(f, 1);
}
}
};

ct.filters.custom = (target, vertex, fragment, uniforms) => {
const fx = new PIXI.Filter(vertex, fragment, uniforms);
return addFilter(target, fx);
}

})();
1 change: 1 addition & 0 deletions app/data/ct.libs/filters/injects/htmlbottom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script type="text/javascript" src="./pixi-filters.js"></script>
16 changes: 16 additions & 0 deletions app/data/ct.libs/filters/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"main": {
"name": "Filters",
"tagline": "Add filters and custom shaders to create special effects on your copies or whole viewport",
"version": "1.0.0",
"packageName": "filters",
"authors": [
{
"name": "SN"
}
],
"categories": [
"FX"
]
}
}
14 changes: 14 additions & 0 deletions app/data/ct.libs/filters/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Filters",
"version": "1.0.0",
"description": "Add shaders filters",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"devDependencies": {
"eslint": "^6.5.1"
}
}
Loading

0 comments on commit 0a9b109

Please sign in to comment.