mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 00:21:04 +00:00
Removed 'create' namespace and palettes
This commit is contained in:
parent
72efe3a79c
commit
dabc0b906b
14 changed files with 0 additions and 366 deletions
|
@ -1,116 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Arne16 = require('./palettes/Arne16');
|
||||
var CanvasPool = require('../display/canvas/CanvasPool');
|
||||
var GetValue = require('../utils/object/GetValue');
|
||||
|
||||
/**
|
||||
* Generates a texture based on the given Create configuration object.
|
||||
*
|
||||
* The texture is drawn using a fixed-size indexed palette of 16 colors, where the hex value in the
|
||||
* data cells map to a single color. For example, if the texture config looked like this:
|
||||
*
|
||||
* ```javascript
|
||||
* var star = [
|
||||
* '.....828.....',
|
||||
* '....72227....',
|
||||
* '....82228....',
|
||||
* '...7222227...',
|
||||
* '2222222222222',
|
||||
* '8222222222228',
|
||||
* '.72222222227.',
|
||||
* '..787777787..',
|
||||
* '..877777778..',
|
||||
* '.78778887787.',
|
||||
* '.27887.78872.',
|
||||
* '.787.....787.'
|
||||
* ];
|
||||
*
|
||||
* this.textures.generate('star', { data: star, pixelWidth: 4 });
|
||||
* ```
|
||||
*
|
||||
* Then it would generate a texture that is 52 x 48 pixels in size, because each cell of the data array
|
||||
* represents 1 pixel multiplied by the `pixelWidth` value. The cell values, such as `8`, maps to color
|
||||
* number 8 in the palette. If a cell contains a period character `.` then it is transparent.
|
||||
*
|
||||
* The default palette is Arne16, but you can specify your own using the `palette` property.
|
||||
*
|
||||
* @function Phaser.Create.GenerateTexture
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Types.Create.GenerateTextureConfig} config - The Generate Texture Configuration object.
|
||||
*
|
||||
* @return {HTMLCanvasElement} An HTMLCanvasElement which contains the generated texture drawn to it.
|
||||
*/
|
||||
var GenerateTexture = function (config)
|
||||
{
|
||||
var data = GetValue(config, 'data', []);
|
||||
var canvas = GetValue(config, 'canvas', null);
|
||||
var palette = GetValue(config, 'palette', Arne16);
|
||||
var pixelWidth = GetValue(config, 'pixelWidth', 1);
|
||||
var pixelHeight = GetValue(config, 'pixelHeight', pixelWidth);
|
||||
var resizeCanvas = GetValue(config, 'resizeCanvas', true);
|
||||
var clearCanvas = GetValue(config, 'clearCanvas', true);
|
||||
var preRender = GetValue(config, 'preRender', null);
|
||||
var postRender = GetValue(config, 'postRender', null);
|
||||
|
||||
var width = Math.floor(Math.abs(data[0].length * pixelWidth));
|
||||
var height = Math.floor(Math.abs(data.length * pixelHeight));
|
||||
|
||||
if (!canvas)
|
||||
{
|
||||
canvas = CanvasPool.create2D(this, width, height);
|
||||
resizeCanvas = false;
|
||||
clearCanvas = false;
|
||||
}
|
||||
|
||||
if (resizeCanvas)
|
||||
{
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
}
|
||||
|
||||
var ctx = canvas.getContext('2d', { willReadFrequently: true });
|
||||
|
||||
if (clearCanvas)
|
||||
{
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
// preRender Callback?
|
||||
if (preRender)
|
||||
{
|
||||
preRender(canvas, ctx);
|
||||
}
|
||||
|
||||
// Draw it
|
||||
for (var y = 0; y < data.length; y++)
|
||||
{
|
||||
var row = data[y];
|
||||
|
||||
for (var x = 0; x < row.length; x++)
|
||||
{
|
||||
var d = row[x];
|
||||
|
||||
if (d !== '.' && d !== ' ')
|
||||
{
|
||||
ctx.fillStyle = palette[d];
|
||||
ctx.fillRect(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// postRender Callback?
|
||||
if (postRender)
|
||||
{
|
||||
postRender(canvas, ctx);
|
||||
}
|
||||
|
||||
return canvas;
|
||||
};
|
||||
|
||||
module.exports = GenerateTexture;
|
|
@ -1,16 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @namespace Phaser.Create
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
GenerateTexture: require('./GenerateTexture'),
|
||||
Palettes: require('./palettes')
|
||||
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A 16 color palette by [Arne](http://androidarts.com/palette/16pal.htm)
|
||||
*
|
||||
* @name Phaser.Create.Palettes.ARNE16
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @type {Phaser.Types.Create.Palette}
|
||||
*/
|
||||
module.exports = {
|
||||
0: '#000',
|
||||
1: '#9D9D9D',
|
||||
2: '#FFF',
|
||||
3: '#BE2633',
|
||||
4: '#E06F8B',
|
||||
5: '#493C2B',
|
||||
6: '#A46422',
|
||||
7: '#EB8931',
|
||||
8: '#F7E26B',
|
||||
9: '#2F484E',
|
||||
A: '#44891A',
|
||||
B: '#A3CE27',
|
||||
C: '#1B2632',
|
||||
D: '#005784',
|
||||
E: '#31A2F2',
|
||||
F: '#B2DCEF'
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A 16 color palette inspired by the Commodore 64.
|
||||
*
|
||||
* @name Phaser.Create.Palettes.C64
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @type {Phaser.Types.Create.Palette}
|
||||
*/
|
||||
module.exports = {
|
||||
0: '#000',
|
||||
1: '#fff',
|
||||
2: '#8b4131',
|
||||
3: '#7bbdc5',
|
||||
4: '#8b41ac',
|
||||
5: '#6aac41',
|
||||
6: '#3931a4',
|
||||
7: '#d5de73',
|
||||
8: '#945a20',
|
||||
9: '#5a4100',
|
||||
A: '#bd736a',
|
||||
B: '#525252',
|
||||
C: '#838383',
|
||||
D: '#acee8b',
|
||||
E: '#7b73de',
|
||||
F: '#acacac'
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A 16 color CGA inspired palette by [Arne](http://androidarts.com/palette/16pal.htm)
|
||||
*
|
||||
* @name Phaser.Create.Palettes.CGA
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @type {Phaser.Types.Create.Palette}
|
||||
*/
|
||||
module.exports = {
|
||||
0: '#000',
|
||||
1: '#2234d1',
|
||||
2: '#0c7e45',
|
||||
3: '#44aacc',
|
||||
4: '#8a3622',
|
||||
5: '#5c2e78',
|
||||
6: '#aa5c3d',
|
||||
7: '#b5b5b5',
|
||||
8: '#5e606e',
|
||||
9: '#4c81fb',
|
||||
A: '#6cd947',
|
||||
B: '#7be2f9',
|
||||
C: '#eb8a60',
|
||||
D: '#e23d69',
|
||||
E: '#ffd93f',
|
||||
F: '#fff'
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A 16 color JMP palette by [Arne](http://androidarts.com/palette/16pal.htm)
|
||||
*
|
||||
* @name Phaser.Create.Palettes.JMP
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @type {Phaser.Types.Create.Palette}
|
||||
*/
|
||||
module.exports = {
|
||||
0: '#000',
|
||||
1: '#191028',
|
||||
2: '#46af45',
|
||||
3: '#a1d685',
|
||||
4: '#453e78',
|
||||
5: '#7664fe',
|
||||
6: '#833129',
|
||||
7: '#9ec2e8',
|
||||
8: '#dc534b',
|
||||
9: '#e18d79',
|
||||
A: '#d6b97b',
|
||||
B: '#e9d8a1',
|
||||
C: '#216c4b',
|
||||
D: '#d365c8',
|
||||
E: '#afaab9',
|
||||
F: '#f5f4eb'
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A 16 color palette inspired by Japanese computers like the MSX.
|
||||
*
|
||||
* @name Phaser.Create.Palettes.MSX
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @type {Phaser.Types.Create.Palette}
|
||||
*/
|
||||
module.exports = {
|
||||
0: '#000',
|
||||
1: '#191028',
|
||||
2: '#46af45',
|
||||
3: '#a1d685',
|
||||
4: '#453e78',
|
||||
5: '#7664fe',
|
||||
6: '#833129',
|
||||
7: '#9ec2e8',
|
||||
8: '#dc534b',
|
||||
9: '#e18d79',
|
||||
A: '#d6b97b',
|
||||
B: '#e9d8a1',
|
||||
C: '#216c4b',
|
||||
D: '#d365c8',
|
||||
E: '#afaab9',
|
||||
F: '#fff'
|
||||
};
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @namespace Phaser.Create.Palettes
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
ARNE16: require('./Arne16'),
|
||||
C64: require('./C64'),
|
||||
CGA: require('./CGA'),
|
||||
JMP: require('./JMP'),
|
||||
MSX: require('./MSX')
|
||||
|
||||
};
|
|
@ -1,22 +0,0 @@
|
|||
/**
|
||||
* @callback Phaser.Types.Create.GenerateTextureCallback
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {HTMLCanvasElement} canvas - The HTML Canvas element to operate on.
|
||||
* @param {CanvasRenderingContext2D} context - The context of the HTML Canvas element.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} Phaser.Types.Create.GenerateTextureConfig
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @property {array} [data=[]] - An array of data, where each row is a string of single values 0-9A-F, or the period character.
|
||||
* @property {HTMLCanvasElement} [canvas=null] - The HTML Canvas to draw the texture to.
|
||||
* @property {Phaser.Types.Create.Palette} [palette=Arne16] - The indexed palette that the data cell values map to.
|
||||
* @property {number} [pixelWidth=1] - The width of each 'pixel' in the generated texture.
|
||||
* @property {number} [pixelHeight=1] - The height of each 'pixel' in the generated texture.
|
||||
* @property {boolean} [resizeCanvas=true] - Should the canvas be resized before the texture is drawn?
|
||||
* @property {boolean} [clearCanvas=true] - Should the canvas be cleared before the texture is drawn?
|
||||
* @property {Phaser.Types.Create.GenerateTextureCallback} [preRender] - A callback to send the canvas to prior to the texture being drawn.
|
||||
* @property {Phaser.Types.Create.GenerateTextureCallback} [postRender] - A callback to send the canvas to after the texture has been drawn.
|
||||
*/
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* @typedef {object} Phaser.Types.Create.Palette
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @property {string} 0 - Color value 1.
|
||||
* @property {string} 1 - Color value 2.
|
||||
* @property {string} 2 - Color value 3.
|
||||
* @property {string} 3 - Color value 4.
|
||||
* @property {string} 4 - Color value 5.
|
||||
* @property {string} 5 - Color value 6.
|
||||
* @property {string} 6 - Color value 7.
|
||||
* @property {string} 7 - Color value 8.
|
||||
* @property {string} 8 - Color value 9.
|
||||
* @property {string} 9 - Color value 10.
|
||||
* @property {string} A - Color value 11.
|
||||
* @property {string} B - Color value 12.
|
||||
* @property {string} C - Color value 13.
|
||||
* @property {string} D - Color value 14.
|
||||
* @property {string} E - Color value 15.
|
||||
* @property {string} F - Color value 16.
|
||||
*/
|
|
@ -1,9 +0,0 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @namespace Phaser.Types.Create
|
||||
*/
|
|
@ -22,7 +22,6 @@ var Phaser = {
|
|||
Cameras: require('./cameras'),
|
||||
Core: require('./core'),
|
||||
Class: require('./utils/Class'),
|
||||
Create: require('./create'),
|
||||
Curves: require('./curves'),
|
||||
Data: require('./data'),
|
||||
Display: require('./display'),
|
||||
|
|
|
@ -14,7 +14,6 @@ export const BlendModes = require('./renderer/BlendModes');
|
|||
export const Cache = require('./cache');
|
||||
export const Cameras = require('./cameras');
|
||||
export const Core = require('./core');
|
||||
export const Create = require('./create');
|
||||
export const Curves = require('./curves');
|
||||
export const Data = require('./data');
|
||||
export const Display = require('./display');
|
||||
|
|
|
@ -22,7 +22,6 @@ var Phaser = {
|
|||
Cameras: require('./cameras'),
|
||||
Core: require('./core'),
|
||||
Class: require('./utils/Class'),
|
||||
Create: require('./create'),
|
||||
Curves: require('./curves'),
|
||||
Data: require('./data'),
|
||||
Display: require('./display'),
|
||||
|
|
Loading…
Reference in a new issue