Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
saqsun committed Mar 12, 2018
0 parents commit f11f249
Show file tree
Hide file tree
Showing 15 changed files with 8,078 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const settings = {
env: {
browser: true,
},
parser: 'babel-eslint',
extends: 'standard',
plugins: ['import'],
settings: {
'import/parser': 'babel-eslint',
'import/resolver': {
webpack: {
config: 'config/webpack.config.js',
},
},
},
globals: {
NODE_ENV: true,
Phaser: true,
},
rules: {
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
},
],
'no-fallthrough': ['error', { commentPattern: 'break[\\s\\w]*omitted' }],
'standard/computed-property-even-spacing': 0,
},
}

module.exports = settings
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Remove some common IDE working directories
.idea
.vscode
.DS_Store
/lib/
/dist/
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
trailingComma: 'es5',
}
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
sudo: required
before_install:
- npm install -g npm
- npm --version
script:
- npm run build
node_js:
- '8'
deploy:
provider: npm
skip_cleanup: true
on:
tags: true
email: sargsyan.sargis.89@gmail.com
api_key:
secure: Vn83By0WtQ+ShTX6CGvTrXtRKf9LJtNsXABm5Lh+v5FxBz2mO91Py79mTrrlQBlVPh2tsHfhuMIxa2Lw4Z4C1mNeevUZl81Ktlwq71DD0FOKiqWS/ks7bvRFRah65AuYwcVnIbgaXc2Mf+O+vzhocan6LxGa96aQcAoDn0Nt+cbRT+obOedhOEDhCWBcgsZBz1caVF61oihYAJhBvdtpLeG2mpNygUmUPiqu3qg9UjP1V9u4ZfXQ+WHzqSoqPTU78jNVzhhNkse0ezj1JUV7/0OvOmM5gG011ybRJzZzCG51yMjbn7rdNnPSgs8wulz/k2lz40D/rTO0Xig0o5QloNXzfIUAiUR2LQatK3N5Fu9L/2tR7YggiDhrdODhaQhJwFy6VX5lBJZaNGZf/7nRQ7khgB6ATIaxwIlxPj8manFCi8tyS+ZugsS5QhP58z2BvrRiAcUDGo2YewFKXOvBiCMFeMm0p4oI6zkksQ/rVurCA9uxoASiHDYMtcZj/RzjbKQBEPGRLXm2oeOws+TlnUFjMA5wARpfaH8fGKZyXY2EWlrXBMWXi1Q/f7PDFMSp3mTSCua1glL42wv3NpQPM4t2tEaRg2DM+JgZeSmdC/nqlTC1FReOK3PBJMdVfB3VtlRZtB/FZka9bb2YhBgdnjXoiCyPEsCf6dx6r7Or2Ds=
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
108 changes: 108 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Phaser3 i18n Plugin

[![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)

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.

Key features:

* Support for translations namespaces
* Simple key/value JSON
* Seamless switching of languages
* No extra function calls for translating strings, directly build into Phaser's Text object

## Getting Started

### Installation

#### **_Using script tag:_**

[![](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)

```html
<script src="//cdn.jsdelivr.net/npm/@koreez/phaser3-i18n-plugin/dist/phaseri18n.min.js"></script>
```

#### **_Using npm:_**

[![npm](https://img.shields.io/npm/dt/@koreez/phaser3-i18n-plugin.svg)](https://www.npmjs.com/package/@koreez/phaser3-i18n-plugin)

```shell
$ npm i -g npm
$ npm i --save @koreez/phaser3-i18n-plugin
```

## Usage

### Import the plugin

##### **_CommonJS_**

```javascript
var I18nPlugin = require("@koreez/phaser3-i18n-plugin");
```

##### **_ES2015_**

```javascript
import I18nPlugin from "@koreez/phaser3-i18n-plugin";
```

### Load the plugin

You need to load the plugin in your game. This is done just like any other plugin in Phaser 3.
So, to load the plugin, include it one of the Phaser Scenes _preload_ method.

```javascript
preload () {
this.load.plugin('I18nPlugin', I18nPlugin)
}
```

### Initialize the plugin

Afther plugin has beeen loaded you need to initialize it.

```javascript
create () {
this.sys.install('I18nPlugin')
this.sys.i18n.init(
{
fallbackLng: 'en',
loadPath: 'assets/i18n/{{lng}}/{{ns}}.json',
debug: false,
},
function () {
console.log('I18nPlugin initialized!')
},
)
}
```

The plugin will patch _add.text, add.bitmapText and add.dynamicBitmapText / make.text, make.bitmapText and make.dynamicBitmapText_ methods with additional functionality.

### Create localized texts

```javascript
// x - any
// y - any
// font - bitmap font
// text - should be translation key
// size - font size
// interpolations - interpolation for transleation (for example { 0: "value0", 1: "value1" }), note this is not required parametr
this.add.bitmapText(x, y, font, text, size, interpolations);
```

##### **_or via config_**

```javascript
var config = {
x: 100,
y: 100,
text: "translationKey",
font: "atari-classic",
size: 64,
interpolations: { 0: "value0", 1: "value1" },
};
this.make.dynamicBitmapText(config);
```
21 changes: 21 additions & 0 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const settings = {
env: {
browser: false,
node: true,
},
extends: 'standard',
rules: {
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
},
],
},
}

module.exports = settings
109 changes: 109 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const path = require('path')
const merge = require('webpack-merge')
const packagejson = require('../package.json')

const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')

const parts = require('./webpack.parts.config')

let main = packagejson.main
main = main.replace(/^.*[\\/]/, '')

const libraryName = main.substring(0, main.lastIndexOf('.'))

// Phaser webpack config
const phaserModule = path.resolve('node_modules/phaser-ce/')

const paths = {
base: path.resolve('src'),
app: path.resolve('src/index.js'),
dist: path.resolve('dist'),
phaser: path.join(phaserModule, 'build/custom/phaser-arcade-physics.js'),
}

const libConfig = merge([
{
target: 'web',
context: paths.base,
entry: {
app: paths.app,
},
output: {
path: paths.dist,
libraryExport: 'default',
},
resolve: {
alias: {
phaser: paths.phaser,
},
modules: [path.resolve('./node_modules'), path.resolve('./src')],
extensions: ['.json', '.js'],
},
plugins: [new CaseSensitivePathsPlugin()],
},

parts.loadJs({
babelOptions: {
presets: [
[
'babel-preset-env',
{
modules: false,
useBuiltIns: 'entry',
shippedProposals: true,
},
],
'stage-2',
],
plugins: [],
},
}),

parts.sourceMaps('source-map'),

parts.cleanup([paths.dist]),

parts.minifyJavaScript(),

parts.scopeHoisting(),

// parts.attachRevision(),
])

const varConfig = merge([
{
output: {
filename: 'phaseri18n.min.js',
library: 'I18nPlugin',
libraryTarget: 'var',
umdNamedDefine: false,
},
externals: {
phaser: 'Phaser',
},
},
])

const umdConfig = merge([
{
output: {
library: libraryName,
filename: libraryName + '.js',
libraryTarget: 'umd',
umdNamedDefine: true,
},
externals: {
phaser: {
commonjs: 'phaser',
commonjs2: 'phaser',
amd: 'phaser',
root: 'phaser',
},
},
},
])

module.exports = env => {
const config = merge(libConfig, env === 'var' ? varConfig : umdConfig)
return config
}
Loading

0 comments on commit f11f249

Please sign in to comment.