Skip to content

Commit f11f249

Browse files
committed
initial commit
0 parents  commit f11f249

File tree

15 files changed

+8078
-0
lines changed

15 files changed

+8078
-0
lines changed

.eslintrc.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const settings = {
2+
env: {
3+
browser: true,
4+
},
5+
parser: 'babel-eslint',
6+
extends: 'standard',
7+
plugins: ['import'],
8+
settings: {
9+
'import/parser': 'babel-eslint',
10+
'import/resolver': {
11+
webpack: {
12+
config: 'config/webpack.config.js',
13+
},
14+
},
15+
},
16+
globals: {
17+
NODE_ENV: true,
18+
Phaser: true,
19+
},
20+
rules: {
21+
'comma-dangle': [
22+
'error',
23+
{
24+
arrays: 'always-multiline',
25+
objects: 'always-multiline',
26+
imports: 'always-multiline',
27+
exports: 'always-multiline',
28+
functions: 'always-multiline',
29+
},
30+
],
31+
'no-fallthrough': ['error', { commentPattern: 'break[\\s\\w]*omitted' }],
32+
'standard/computed-property-even-spacing': 0,
33+
},
34+
}
35+
36+
module.exports = settings

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules
28+
29+
# Remove some common IDE working directories
30+
.idea
31+
.vscode
32+
.DS_Store
33+
/lib/
34+
/dist/

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
trailingComma: 'es5',
3+
}

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: node_js
2+
sudo: required
3+
before_install:
4+
- npm install -g npm
5+
- npm --version
6+
script:
7+
- npm run build
8+
node_js:
9+
- '8'
10+
deploy:
11+
provider: npm
12+
skip_cleanup: true
13+
on:
14+
tags: true
15+
16+
api_key:
17+
secure: Vn83By0WtQ+ShTX6CGvTrXtRKf9LJtNsXABm5Lh+v5FxBz2mO91Py79mTrrlQBlVPh2tsHfhuMIxa2Lw4Z4C1mNeevUZl81Ktlwq71DD0FOKiqWS/ks7bvRFRah65AuYwcVnIbgaXc2Mf+O+vzhocan6LxGa96aQcAoDn0Nt+cbRT+obOedhOEDhCWBcgsZBz1caVF61oihYAJhBvdtpLeG2mpNygUmUPiqu3qg9UjP1V9u4ZfXQ+WHzqSoqPTU78jNVzhhNkse0ezj1JUV7/0OvOmM5gG011ybRJzZzCG51yMjbn7rdNnPSgs8wulz/k2lz40D/rTO0Xig0o5QloNXzfIUAiUR2LQatK3N5Fu9L/2tR7YggiDhrdODhaQhJwFy6VX5lBJZaNGZf/7nRQ7khgB6ATIaxwIlxPj8manFCi8tyS+ZugsS5QhP58z2BvrRiAcUDGo2YewFKXOvBiCMFeMm0p4oI6zkksQ/rVurCA9uxoASiHDYMtcZj/RzjbKQBEPGRLXm2oeOws+TlnUFjMA5wARpfaH8fGKZyXY2EWlrXBMWXi1Q/f7PDFMSp3mTSCua1glL42wv3NpQPM4t2tEaRg2DM+JgZeSmdC/nqlTC1FReOK3PBJMdVfB3VtlRZtB/FZka9bb2YhBgdnjXoiCyPEsCf6dx6r7Or2Ds=

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Phaser3 i18n Plugin
2+
3+
[![Build Status](https://github.com/koreezgames/phaser3-i18n-plugin.svg?branch=master)](https://github.com/koreezgames/phaser3-i18n-plugin) [![David](https://david-dm.org/koreezgames/phaser3-i18n-plugin.svg)]() [![Project status](https://img.shields.io/badge/status-active-brightgreen.svg)](#status)
4+
5+
Phaser3 i18n is a plugin for Phaser 3 that allows you to have seamless translations in your game. It uses **[i18next](https://github.com/i18next/i18next)** as it's source for translations management, which is widely adopted by the JS community in other projects as well.
6+
7+
Key features:
8+
9+
* Support for translations namespaces
10+
* Simple key/value JSON
11+
* Seamless switching of languages
12+
* No extra function calls for translating strings, directly build into Phaser's Text object
13+
14+
## Getting Started
15+
16+
### Installation
17+
18+
#### **_Using script tag:_**
19+
20+
[![](https://data.jsdelivr.com/v1/package/npm/@koreez/phaser3-i18n-plugin/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@koreez/phaser3-i18n-plugin/dist/phaseri18n.min.js)
21+
22+
```html
23+
<script src="//cdn.jsdelivr.net/npm/@koreez/phaser3-i18n-plugin/dist/phaseri18n.min.js"></script>
24+
```
25+
26+
#### **_Using npm:_**
27+
28+
[![npm](https://img.shields.io/npm/dt/@koreez/phaser3-i18n-plugin.svg)](https://www.npmjs.com/package/@koreez/phaser3-i18n-plugin)
29+
30+
```shell
31+
$ npm i -g npm
32+
$ npm i --save @koreez/phaser3-i18n-plugin
33+
```
34+
35+
## Usage
36+
37+
### Import the plugin
38+
39+
##### **_CommonJS_**
40+
41+
```javascript
42+
var I18nPlugin = require("@koreez/phaser3-i18n-plugin");
43+
```
44+
45+
##### **_ES2015_**
46+
47+
```javascript
48+
import I18nPlugin from "@koreez/phaser3-i18n-plugin";
49+
```
50+
51+
### Load the plugin
52+
53+
You need to load the plugin in your game. This is done just like any other plugin in Phaser 3.
54+
So, to load the plugin, include it one of the Phaser Scenes _preload_ method.
55+
56+
```javascript
57+
preload () {
58+
this.load.plugin('I18nPlugin', I18nPlugin)
59+
}
60+
```
61+
62+
### Initialize the plugin
63+
64+
Afther plugin has beeen loaded you need to initialize it.
65+
66+
```javascript
67+
create () {
68+
this.sys.install('I18nPlugin')
69+
this.sys.i18n.init(
70+
{
71+
fallbackLng: 'en',
72+
loadPath: 'assets/i18n/{{lng}}/{{ns}}.json',
73+
debug: false,
74+
},
75+
function () {
76+
console.log('I18nPlugin initialized!')
77+
},
78+
)
79+
}
80+
```
81+
82+
The plugin will patch _add.text, add.bitmapText and add.dynamicBitmapText / make.text, make.bitmapText and make.dynamicBitmapText_ methods with additional functionality.
83+
84+
### Create localized texts
85+
86+
```javascript
87+
// x - any
88+
// y - any
89+
// font - bitmap font
90+
// text - should be translation key
91+
// size - font size
92+
// interpolations - interpolation for transleation (for example { 0: "value0", 1: "value1" }), note this is not required parametr
93+
this.add.bitmapText(x, y, font, text, size, interpolations);
94+
```
95+
96+
##### **_or via config_**
97+
98+
```javascript
99+
var config = {
100+
x: 100,
101+
y: 100,
102+
text: "translationKey",
103+
font: "atari-classic",
104+
size: 64,
105+
interpolations: { 0: "value0", 1: "value1" },
106+
};
107+
this.make.dynamicBitmapText(config);
108+
```

config/.eslintrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const settings = {
2+
env: {
3+
browser: false,
4+
node: true,
5+
},
6+
extends: 'standard',
7+
rules: {
8+
'comma-dangle': [
9+
'error',
10+
{
11+
arrays: 'always-multiline',
12+
objects: 'always-multiline',
13+
imports: 'always-multiline',
14+
exports: 'always-multiline',
15+
functions: 'always-multiline',
16+
},
17+
],
18+
},
19+
}
20+
21+
module.exports = settings

config/webpack.config.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const path = require('path')
2+
const merge = require('webpack-merge')
3+
const packagejson = require('../package.json')
4+
5+
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
6+
7+
const parts = require('./webpack.parts.config')
8+
9+
let main = packagejson.main
10+
main = main.replace(/^.*[\\/]/, '')
11+
12+
const libraryName = main.substring(0, main.lastIndexOf('.'))
13+
14+
// Phaser webpack config
15+
const phaserModule = path.resolve('node_modules/phaser-ce/')
16+
17+
const paths = {
18+
base: path.resolve('src'),
19+
app: path.resolve('src/index.js'),
20+
dist: path.resolve('dist'),
21+
phaser: path.join(phaserModule, 'build/custom/phaser-arcade-physics.js'),
22+
}
23+
24+
const libConfig = merge([
25+
{
26+
target: 'web',
27+
context: paths.base,
28+
entry: {
29+
app: paths.app,
30+
},
31+
output: {
32+
path: paths.dist,
33+
libraryExport: 'default',
34+
},
35+
resolve: {
36+
alias: {
37+
phaser: paths.phaser,
38+
},
39+
modules: [path.resolve('./node_modules'), path.resolve('./src')],
40+
extensions: ['.json', '.js'],
41+
},
42+
plugins: [new CaseSensitivePathsPlugin()],
43+
},
44+
45+
parts.loadJs({
46+
babelOptions: {
47+
presets: [
48+
[
49+
'babel-preset-env',
50+
{
51+
modules: false,
52+
useBuiltIns: 'entry',
53+
shippedProposals: true,
54+
},
55+
],
56+
'stage-2',
57+
],
58+
plugins: [],
59+
},
60+
}),
61+
62+
parts.sourceMaps('source-map'),
63+
64+
parts.cleanup([paths.dist]),
65+
66+
parts.minifyJavaScript(),
67+
68+
parts.scopeHoisting(),
69+
70+
// parts.attachRevision(),
71+
])
72+
73+
const varConfig = merge([
74+
{
75+
output: {
76+
filename: 'phaseri18n.min.js',
77+
library: 'I18nPlugin',
78+
libraryTarget: 'var',
79+
umdNamedDefine: false,
80+
},
81+
externals: {
82+
phaser: 'Phaser',
83+
},
84+
},
85+
])
86+
87+
const umdConfig = merge([
88+
{
89+
output: {
90+
library: libraryName,
91+
filename: libraryName + '.js',
92+
libraryTarget: 'umd',
93+
umdNamedDefine: true,
94+
},
95+
externals: {
96+
phaser: {
97+
commonjs: 'phaser',
98+
commonjs2: 'phaser',
99+
amd: 'phaser',
100+
root: 'phaser',
101+
},
102+
},
103+
},
104+
])
105+
106+
module.exports = env => {
107+
const config = merge(libConfig, env === 'var' ? varConfig : umdConfig)
108+
return config
109+
}

0 commit comments

Comments
 (0)