├── .eslintrc.js ├── .github └── workflows │ └── npm.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── demo ├── .babelrc ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── decorations │ │ ├── controller.png │ │ ├── creep_effect1.svg │ │ ├── creep_effect2.svg │ │ ├── landscape.png │ │ ├── landscape2.png │ │ ├── test1.svg │ │ ├── test2.svg │ │ ├── test3.svg │ │ └── test_tile.png │ ├── favicon.ico │ └── index.html ├── server.js ├── src │ ├── App.jsx │ ├── StateDriver.js │ ├── components │ │ ├── Canvas.jsx │ │ └── CanvasWrapper.jsx │ ├── config │ │ ├── decorations.js │ │ ├── resourceMap.js │ │ └── worldConfigs.js │ ├── index.jsx │ ├── logo.svg │ ├── main.js │ ├── samples-js │ │ └── powerCreep.sample.js │ └── samples │ │ ├── factory.json │ │ ├── invaderCore.json │ │ ├── labs.json │ │ ├── room1.json │ │ ├── room2.json │ │ ├── room_replay.json │ │ ├── sample1.json │ │ ├── sample2.json │ │ ├── sample3.json │ │ ├── sample_nuke.json │ │ ├── sample_roads.json │ │ ├── sample_spawn.json │ │ ├── sample_walls.json │ │ ├── structures.json │ │ ├── terrain1.json │ │ └── terrain_empty.json └── webpack.config.js ├── engine ├── .babelrc ├── .eslintignore ├── .gitignore ├── .npmignore ├── dist │ ├── renderer.js │ └── renderer.js.map ├── main.d.ts ├── package-lock.json ├── package.json ├── src │ ├── index.js │ └── lib │ │ ├── GameObject.js │ │ ├── GameRenderer.js │ │ ├── ResourceManager.js │ │ ├── World.js │ │ ├── actions │ │ ├── Action.js │ │ ├── ActionHandle.js │ │ ├── ActionManager.js │ │ ├── AlphaBy.js │ │ ├── AlphaTo.js │ │ ├── Blink.js │ │ ├── CallFunc.js │ │ ├── DelayTime.js │ │ ├── Ease.js │ │ ├── FadeIn.js │ │ ├── FadeOut.js │ │ ├── FilterTo.js │ │ ├── MoveBy.js │ │ ├── MoveTo.js │ │ ├── PivotBy.js │ │ ├── PivotTo.js │ │ ├── Repeat.js │ │ ├── RotateBy.js │ │ ├── RotateTo.js │ │ ├── ScaleBy.js │ │ ├── ScaleTo.js │ │ ├── Sequence.js │ │ ├── SkewBy.js │ │ ├── SkewTo.js │ │ ├── Spawn.js │ │ ├── TimeableAction.js │ │ ├── TintBy.js │ │ ├── TintTo.js │ │ ├── easingHelper.js │ │ └── index.js │ │ ├── decorations.js │ │ ├── expressions │ │ ├── add.js │ │ ├── and.js │ │ ├── calc.js │ │ ├── concat.js │ │ ├── div.js │ │ ├── eq.js │ │ ├── gt.js │ │ ├── gte.js │ │ ├── if.js │ │ ├── index.js │ │ ├── lt.js │ │ ├── lte.js │ │ ├── max.js │ │ ├── min.js │ │ ├── mul.js │ │ ├── not.js │ │ ├── or.js │ │ ├── processorParam.js │ │ ├── random.js │ │ ├── rel.js │ │ ├── state.js │ │ └── sub.js │ │ ├── pathHelper.js │ │ ├── processors │ │ ├── circle.js │ │ ├── container.js │ │ ├── creepActions.js │ │ ├── creepBuildBody.js │ │ ├── creepDecoration.js │ │ ├── disappear.js │ │ ├── draw.js │ │ ├── index.js │ │ ├── moveTo.js │ │ ├── object.js │ │ ├── objectDecoration.js │ │ ├── powerInfluence.js │ │ ├── resourceCircle.js │ │ ├── road.js │ │ ├── runAction.js │ │ ├── say.js │ │ ├── setBadgeUrls.js │ │ ├── siteProgress.js │ │ ├── sprite.js │ │ ├── terrain.js │ │ ├── text.js │ │ └── userBadge.js │ │ └── utils │ │ ├── actionHelper.js │ │ ├── hsl.js │ │ └── resolveProp.js └── webpack.config.js ├── helpers └── mathHelper.js └── metadata ├── .eslintignore ├── .gitignore ├── .npmignore ├── dist ├── renderer-metadata.js └── renderer-metadata.js.map ├── images ├── berserk.svg ├── bodyPartBar.svg ├── commander-lvl0.svg ├── commander-lvl1.svg ├── commander-lvl2.svg ├── commander-lvl3.svg ├── commander-lvl4.svg ├── commander.svg ├── constructedWall.svg ├── controller-level.svg ├── controller.svg ├── cover.svg ├── creep-mask.png ├── creep-npc.svg ├── defend.svg ├── demolish.svg ├── deposit-biomass-fill.svg ├── deposit-biomass.svg ├── deposit-metal-fill.svg ├── deposit-metal.svg ├── deposit-mist-fill.svg ├── deposit-mist.svg ├── deposit-silicon-fill.svg ├── deposit-silicon.svg ├── disable.svg ├── disrupt-source.svg ├── disrupt-spawn.svg ├── disrupt-terminal.svg ├── disrupt-tower.svg ├── drain-extension.svg ├── encourage.svg ├── executor-lvl0.svg ├── executor-lvl1.svg ├── executor-lvl2.svg ├── executor-lvl3.svg ├── executor-lvl4.svg ├── executor.svg ├── exhaust.svg ├── exit-bottom.svg ├── exit-left.svg ├── exit-right.svg ├── exit-top.svg ├── extension-border100.svg ├── extension-border200.svg ├── extension-border50.svg ├── extension.svg ├── extractor.svg ├── factory-border.svg ├── factory-highlight.svg ├── factory-lvl0.svg ├── factory-lvl1.svg ├── factory-lvl2.svg ├── factory-lvl3.svg ├── factory-lvl4.svg ├── factory-lvl5.svg ├── factory.svg ├── flag-secondary.svg ├── flag.svg ├── flare1.png ├── flare2.png ├── flare3.png ├── fortify.svg ├── generate-ops.svg ├── glow.png ├── ground-mask.png ├── ground.png ├── harvest-energy.svg ├── harvest-mineral.svg ├── invaderCore.svg ├── kill.svg ├── lab-highlight.svg ├── lab-mineral.svg ├── lab.svg ├── link-border.svg ├── link-energy.svg ├── link.svg ├── mass-repair.svg ├── noise1.png ├── noise2.png ├── nuke.svg ├── nuker-border.svg ├── nuker.svg ├── operate-controller.svg ├── operate-extension.svg ├── operate-lab.svg ├── operate-observer.svg ├── operate-power.svg ├── operate-spawn.svg ├── operate-storage.svg ├── operate-terminal.svg ├── operate-tower.svg ├── operator-lvl0.svg ├── operator-lvl1.svg ├── operator-lvl2.svg ├── operator-lvl3.svg ├── operator-lvl4.svg ├── operator.svg ├── powerBank.svg ├── punch.svg ├── rampart.svg ├── rectangle.svg ├── reflect.svg ├── regen-mineral.svg ├── regen-source.svg ├── reinforce.svg ├── remote-transfer.svg ├── renew.svg ├── ruin.svg ├── shield.svg ├── sight.svg ├── snipe.svg ├── storage-border.svg ├── storage.svg ├── summon.svg ├── tbd.svg ├── terminal-arrows.svg ├── terminal-border.svg ├── terminal-highlight.svg ├── terminal.svg ├── tombstone-border.svg ├── tombstone-resource.svg ├── tombstone.svg ├── tough.svg ├── tower-base.svg ├── tower-rotatable-npc.svg └── tower-rotatable.svg ├── package-lock.json ├── package.json ├── src ├── action-templates │ ├── appear.js │ ├── blinking.js │ ├── displayName.js │ ├── flickering.js │ └── index.js ├── calculation-templates │ ├── index.js │ └── resourceTotal.js ├── index.js └── objects │ ├── _all.metadata.js │ ├── constructedWall.metadata.js │ ├── constructionSite.metadata.js │ ├── container.metadata.js │ ├── controller.metadata.js │ ├── creep.metadata.js │ ├── deposit.metadata.js │ ├── energy.metadata.js │ ├── extension.metadata.js │ ├── extractor.metadata.js │ ├── factory.metadata.js │ ├── flag.metadata.js │ ├── invaderCore.metadata.js │ ├── keeperLair.metadata.js │ ├── lab.metadata.js │ ├── link.metadata.js │ ├── mineral.metadata.js │ ├── nuke.metadata.js │ ├── nuker.metadata.js │ ├── observer.metadata.js │ ├── portal.metadata.js │ ├── powerBank.metadata.js │ ├── powerCreep.metadata.js │ ├── powerSpawn.metadata.js │ ├── rampart.metadata.js │ ├── road.metadata.js │ ├── ruin.metadata.js │ ├── source.metadata.js │ ├── spawn.metadata.js │ ├── storage.metadata.js │ ├── tbd.metadata.js │ ├── terminal.metadata.js │ ├── tombstone.metadata.js │ └── tower.metadata.js └── webpack.config.js /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: 'airbnb-base', 3 | rules: { 4 | 'class-methods-use-this': 0, 5 | 'comma-dangle': ['error', { 6 | arrays: 'always-multiline', 7 | objects: 'always-multiline', 8 | imports: 'always-multiline', 9 | exports: 'always-multiline', 10 | functions: 'never', 11 | }], 12 | 'consistent-return': 0, 13 | 'function-paren-newline': 0, 14 | indent: ['error', 4, { 15 | SwitchCase: 1, 16 | VariableDeclarator: 1, 17 | outerIIFEBody: 1, 18 | // MemberExpression: null, 19 | // CallExpression: { 20 | // parameters: null, 21 | // }, 22 | FunctionDeclaration: { 23 | parameters: 1, 24 | body: 1, 25 | }, 26 | FunctionExpression: { 27 | parameters: 1, 28 | body: 1, 29 | }, 30 | }], 31 | 'no-console': 0, 32 | 'no-else-return': 0, 33 | 'no-param-reassign': 0, 34 | 'no-shadow': 0, 35 | 'no-underscore-dangle': 0, 36 | 'object-curly-newline': 0, 37 | strict: ['error', 'global'], 38 | 'linebreak-style': 0, 39 | 'import/no-extraneous-dependencies': 0 40 | }, 41 | globals: { 42 | PIXI: true, 43 | RENDERER_METADATA: true, 44 | window: true 45 | }, 46 | parserOptions: { 47 | sourceType: 'module', 48 | }, 49 | 50 | settings: { 51 | 'import/resolver': { 52 | node: { 53 | moduleDirectory: [ 54 | 'node_modules', 55 | '.', 56 | ], 57 | }, 58 | }, 59 | }, 60 | }; 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Artem Chivchalov 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, 4 | provided that the above copyright notice and this permission notice appear in all copies. 5 | 6 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 7 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 8 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 9 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 10 | OF THIS SOFTWARE. -------------------------------------------------------------------------------- /demo/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets" : [ 3 | "es2015", 4 | "react" 5 | ], 6 | "plugins": [ 7 | "transform-class-properties", 8 | "transform-object-rest-spread", 9 | "transform-es2015-spread" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /demo/.eslintignore: -------------------------------------------------------------------------------- 1 | build 2 | config 3 | node_modules 4 | scripts 5 | src/render-engine 6 | -------------------------------------------------------------------------------- /demo/.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'airbnb', 5 | rules: { 6 | 'class-methods-use-this': 0, 7 | 'consistent-return': 0, 8 | 'function-paren-newline': 0, 9 | indent: ['error', 4, { 10 | SwitchCase: 1, 11 | VariableDeclarator: 1, 12 | outerIIFEBody: 1, 13 | // MemberExpression: null, 14 | // CallExpression: { 15 | // parameters: null, 16 | // }, 17 | FunctionDeclaration: { 18 | parameters: 1, 19 | body: 1, 20 | }, 21 | FunctionExpression: { 22 | parameters: 1, 23 | body: 1, 24 | }, 25 | }], 26 | 'jsx-a11y/anchor-is-valid': [ 27 | 'error', 28 | { 29 | components: ['Link'], 30 | specialLink: ['to'], 31 | }, 32 | ], 33 | 'jsx-a11y/label-has-for': 0, 34 | 'no-console': 0, 35 | 'no-else-return': 0, 36 | 'no-param-reassign': 0, 37 | 'no-underscore-dangle': ['error', { 'allow': ['_id', '__STATE'] }], 38 | 'object-curly-newline': 0, 39 | // 'react/forbid-component-props': ['error', { 'forbid': ['data', 'item'] }], 40 | 'react/jsx-indent': ['error', 4], 41 | 'react/jsx-indent-props': ['error', 4], 42 | 'react/prop-types': ['error', { 43 | ignore: [], 44 | customValidators: [], 45 | }, 46 | ], 47 | 'react/require-default-props': 0, 48 | semi: ['error', 'always'], 49 | 'linebreak-style': 0 50 | }, 51 | parser: 'babel-eslint', 52 | env: { 53 | browser: true, 54 | mocha: true, 55 | node: true, 56 | es6: true, 57 | }, 58 | settings: { 59 | 'import/resolver': { 60 | node: { 61 | moduleDirectory: [ 62 | 'node_modules', 63 | '.', 64 | ] 65 | } 66 | } 67 | } 68 | }; 69 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # build 5 | /public/js/bundle.js 6 | 7 | 8 | # misc 9 | .DS_Store 10 | .env 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | 15 | .idea 16 | -------------------------------------------------------------------------------- /demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "render-engine-example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "homepage": "./", 6 | "devDependencies": { 7 | "@screeps/common": "^2.15.4", 8 | "autoprefixer": "6.7.2", 9 | "chalk": "1.1.3", 10 | "connect-history-api-fallback": "1.3.0", 11 | "cross-spawn": "4.0.2", 12 | "detect-port": "1.1.0", 13 | "dotenv": "2.0.0", 14 | "eslint": "^4.9.0", 15 | "eslint-config-airbnb": "^16.1.0", 16 | "eslint-loader": "^1.7.1", 17 | "eslint-plugin-import": "^2.7.0", 18 | "eslint-plugin-jsx-a11y": "^6.0.2", 19 | "eslint-plugin-react": "^7.4.0", 20 | "file-loader": "0.10.0", 21 | "fs-extra": "0.30.0", 22 | "http-proxy-middleware": "0.17.3", 23 | "json-loader": "0.5.4", 24 | "object-assign": "4.1.1", 25 | "react-dev-utils": "^0.5.2", 26 | "url-loader": "0.5.7", 27 | "whatwg-fetch": "2.0.2" 28 | }, 29 | "dependencies": { 30 | "babel-core": "^6.26.0", 31 | "babel-loader": "^7.1.2", 32 | "babel-plugin-transform-class-properties": "^6.24.1", 33 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 34 | "babel-preset-es2015": "^6.24.1", 35 | "babel-preset-react": "^6.24.1", 36 | "electron": "^1.6.2", 37 | "lodash": "^4.17.4", 38 | "prop-types": "^15.6.0", 39 | "react": "^15.4.2", 40 | "react-dom": "^15.4.2", 41 | "webpack": "^3.10.0" 42 | }, 43 | "scripts": { 44 | "build": "webpack --progress --colors", 45 | "dev": "webpack --progress --colors --watch", 46 | "dev-no-progress": "webpack --colors --watch", 47 | "electron": "electron src/main.js", 48 | "prepublish": "npm run build" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /demo/public/decorations/controller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/demo/public/decorations/controller.png -------------------------------------------------------------------------------- /demo/public/decorations/creep_effect1.svg: -------------------------------------------------------------------------------- 1 | 22 -------------------------------------------------------------------------------- /demo/public/decorations/creep_effect2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /demo/public/decorations/landscape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/demo/public/decorations/landscape.png -------------------------------------------------------------------------------- /demo/public/decorations/landscape2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/demo/public/decorations/landscape2.png -------------------------------------------------------------------------------- /demo/public/decorations/test_tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/demo/public/decorations/test_tile.png -------------------------------------------------------------------------------- /demo/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/demo/public/favicon.ico -------------------------------------------------------------------------------- /demo/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 17 | React App 18 | 19 | 20 |
21 | 22 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /demo/src/App.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import CanvasWrapper from './components/CanvasWrapper'; 4 | 5 | const App = ({ samples, terrain }) => ( 6 |
7 | 8 |
9 | ); 10 | 11 | App.propTypes = { 12 | samples: PropTypes.arrayOf(PropTypes.shape()).isRequired, 13 | terrain: PropTypes.arrayOf(PropTypes.shape()).isRequired, 14 | }; 15 | 16 | export default App; 17 | -------------------------------------------------------------------------------- /demo/src/StateDriver.js: -------------------------------------------------------------------------------- 1 | import _ from 'lodash'; 2 | 3 | export default class StateDriver { 4 | constructor(initialState = { }) { 5 | this.state = { ...initialState }; 6 | if (!this.state.actionLog) { 7 | this.state.actionLog = {}; 8 | } 9 | } 10 | 11 | say(sayState = null) { 12 | this.setActionLog({ say: sayState }); 13 | return this; 14 | } 15 | 16 | moveBy(dx, dy) { 17 | Object.assign(this.state, { x: this.state.x + dx, y: this.state.y + dy }); 18 | return this; 19 | } 20 | 21 | setActionLog(actionLogStateChanges) { 22 | this.state.actionLog = { ...(this.state.actionLog || {}), ...actionLogStateChanges }; 23 | return this; 24 | } 25 | 26 | createState(stateChanges) { 27 | return { ...this.state, ...stateChanges }; 28 | } 29 | 30 | getState(...props) { 31 | return _.pick(this.state, ...props); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demo/src/config/worldConfigs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 07/04/2017. 3 | */ 4 | 5 | import '../../../metadata/dist/renderer-metadata'; 6 | 7 | export default { 8 | ATTACK_PENETRATION: 10, 9 | CELL_SIZE: 100, 10 | RENDER_SIZE: { 11 | width: 2048, 12 | height: 2048, 13 | }, 14 | VIEW_BOX: 5000, 15 | BADGE_URL: 'https://screeps.com/api/user/badge-svg?username=%1', 16 | metadata: RENDERER_METADATA, 17 | gameData: { 18 | player: '561e4d4645f3f7244a7622e8', 19 | showMyNames: { 20 | spawns: true, 21 | creeps: true, 22 | }, 23 | showEnemyNames: { 24 | spawns: false, 25 | creeps: false, 26 | }, 27 | showFlagsNames: true, 28 | showCreepSpeech: false, 29 | swampTexture: 'animated', 30 | }, 31 | lighting: 'normal', 32 | forceCanvas: false, 33 | }; 34 | -------------------------------------------------------------------------------- /demo/src/samples/terrain_empty.json: -------------------------------------------------------------------------------- 1 | [ 2 | 3 | ] 4 | -------------------------------------------------------------------------------- /demo/webpack.config.js: -------------------------------------------------------------------------------- 1 | require('webpack'); 2 | const path = require('path'); 3 | 4 | const BUILD_DIR = path.resolve(__dirname, 'public'); 5 | const APP_DIR = path.resolve(__dirname, 'src'); 6 | const ENGINE_DIR = path.resolve(__dirname, '../engine/src'); 7 | const isProd = process.env.NODE_ENV === 'production'; 8 | 9 | if (process.argv.includes('--watch')) { 10 | // eslint-disable-next-line global-require 11 | require('./server'); 12 | } 13 | 14 | const babelInclude = [APP_DIR, ...(!isProd ? [ENGINE_DIR] : [])]; 15 | 16 | const config = { 17 | entry: `${APP_DIR}/index.jsx`, 18 | module: { 19 | loaders: [ 20 | { 21 | test: /\.(js|jsx)$/, 22 | include: babelInclude, 23 | loader: 'babel-loader', 24 | }, 25 | { 26 | test: /\.json$/, 27 | loader: 'json-loader', 28 | }, 29 | ], 30 | }, 31 | output: { 32 | path: BUILD_DIR, 33 | filename: 'js/bundle.js', 34 | }, 35 | resolve: { 36 | extensions: ['.js', '.json', '.jsx'], 37 | }, 38 | }; 39 | 40 | module.exports = config; 41 | -------------------------------------------------------------------------------- /engine/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2017"], 3 | "plugins": [ 4 | "transform-class-properties", 5 | "transform-exponentiation-operator", 6 | "transform-object-rest-spread", 7 | "transform-es2015-spread" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /engine/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules -------------------------------------------------------------------------------- /engine/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # misc 10 | .DS_Store 11 | .env 12 | npm-debug.log* 13 | yarn-debug.log* 14 | yarn-error.log* 15 | -------------------------------------------------------------------------------- /engine/.npmignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules 3 | src 4 | webpack 5 | 6 | .babelrc 7 | .eslintignore 8 | .eslintrc.js 9 | .gitignore 10 | webpack.config.js 11 | 12 | .DS_Store 13 | .env 14 | npm-debug.log* 15 | yarn-debug.log* 16 | yarn-error.log* 17 | 18 | .idea 19 | -------------------------------------------------------------------------------- /engine/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@screeps/renderer", 3 | "version": "1.5.19", 4 | "description": "This library contains the renderer engine used in Screeps game.", 5 | "main": "dist/renderer.js", 6 | "types": "./main.d.ts", 7 | "files": [ 8 | "dist" 9 | ], 10 | "author": "Fedor Shubin ", 11 | "license": "ISC", 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/screeps/renderer.git" 15 | }, 16 | "scripts": { 17 | "build": "webpack --progress --colors", 18 | "dev": "webpack --progress --colors --watch", 19 | "dev-no-progress": "webpack --colors --watch", 20 | "prepublish": "npm run build" 21 | }, 22 | "devDependencies": { 23 | "@screeps/common": "^2.15.4", 24 | "babel-core": "^6.26.3", 25 | "babel-eslint": "^7.2.1", 26 | "babel-loader": "^7.1.5", 27 | "babel-plugin-transform-class-properties": "^6.24.1", 28 | "babel-plugin-transform-es2015-spread": "^6.22.0", 29 | "babel-plugin-transform-exponentiation-operator": "^6.24.1", 30 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 31 | "babel-preset-es2017": "^6.24.1", 32 | "bluebird": "^3.5.0", 33 | "eslint": "^4.19.1", 34 | "eslint-config-airbnb-base": "^12.1.0", 35 | "eslint-loader": "^2.1.0", 36 | "eslint-plugin-import": "^2.7.0", 37 | "lodash": "^4.17.4", 38 | "md5": "^2.2.1", 39 | "pixi-filters": "^2.0.2", 40 | "pixi-layers": "github:pixijs/pixi-display#layers", 41 | "pixi.js": "^4.8.1", 42 | "webpack": "^4.17.1", 43 | "webpack-cli": "^3.1.0" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /engine/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 05/04/2017. 3 | */ 4 | 5 | import * as _PIXI from 'pixi.js'; 6 | import _GameRenderer from './lib/GameRenderer'; 7 | 8 | // eslint-disable-next-line no-undef 9 | if (window) { 10 | // eslint-disable-next-line no-undef 11 | window.GameRenderer = _GameRenderer; 12 | } 13 | 14 | export const GameRenderer = _GameRenderer; 15 | 16 | export const PIXI = _PIXI; 17 | 18 | export default GameRenderer; 19 | -------------------------------------------------------------------------------- /engine/src/lib/actions/Action.js: -------------------------------------------------------------------------------- 1 | export default class Action { 2 | reset() { 3 | } 4 | 5 | update() { 6 | throw new Error('Override me!'); 7 | } 8 | 9 | finish() { 10 | this.reset(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /engine/src/lib/actions/ActionHandle.js: -------------------------------------------------------------------------------- 1 | import * as PIXI from 'pixi.js'; 2 | 3 | export default class ActionHandle extends PIXI.utils.EventEmitter { 4 | constructor(container, action) { 5 | super(); 6 | this._id = `_${PIXI.utils.uid()}`; 7 | this.container = container; 8 | this.action = action; 9 | 10 | this._started = false; 11 | this._ended = false; 12 | this._active = false; 13 | } 14 | 15 | update(delta) { 16 | if (!this._started) { 17 | // start event 18 | this.emit('start', delta); 19 | this._started = true; 20 | this._active = true; 21 | } 22 | 23 | // do some update 24 | try { 25 | this._ended = this.action.update(this.container, delta); 26 | } catch (error) { 27 | console.error('Exception while animation:', error); 28 | this._ended = true; 29 | } 30 | 31 | if (this._ended && this._active) { 32 | // end event 33 | this.emit('end', delta); 34 | this._active = false; 35 | } 36 | } 37 | 38 | isEnded() { 39 | return this._ended; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /engine/src/lib/actions/AlphaBy.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class AlphaBy extends TimeableAction { 4 | constructor(alpha, time) { 5 | super(time); 6 | this.alpha = alpha; 7 | this.reset(); 8 | } 9 | 10 | reset() { 11 | super.reset(); 12 | this.talpha = null; 13 | } 14 | 15 | // if end return true, if not end return false 16 | update(container, delta) { 17 | const { alpha } = container; 18 | if (this.talpha === null) { 19 | this.talpha = alpha + this.alpha; 20 | } 21 | container.alpha += ((this.talpha - alpha) / this.restTime) * delta; 22 | return super.update(container, delta); 23 | } 24 | 25 | finish(container) { 26 | container.alpha = this.talpha; 27 | super.finish(container); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /engine/src/lib/actions/AlphaTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class AlphaTo extends TimeableAction { 4 | constructor(alpha, time) { 5 | super(time); 6 | this.alpha = alpha; 7 | this.reset(); 8 | } 9 | 10 | // if end return true, if not end return false 11 | update(container, delta) { 12 | const { alpha } = container; 13 | container.alpha += ((this.alpha - alpha) / this.restTime) * delta; 14 | return super.update(container, delta); 15 | } 16 | 17 | finish(container) { 18 | container.alpha = this.alpha; 19 | super.finish(container); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /engine/src/lib/actions/Blink.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class Blink extends TimeableAction { 4 | constructor(count, time) { 5 | super(time); 6 | this.count = count; 7 | this.reset(); 8 | } 9 | 10 | reset() { 11 | this._count = this.count * 2; 12 | this._gap = this.time / this._count; // 每次的时间 13 | super.reset(); 14 | } 15 | 16 | // if end return true, if not end return false 17 | update(container, delta) { 18 | if (this.restTime <= 0) { 19 | // toggle 20 | container.visible = !container.visible; 21 | this.restTime = this._gap; 22 | this._count -= 1; 23 | } else { 24 | this.restTime -= delta; 25 | } 26 | // return true / false: ended / not end 27 | if (this._count <= 0) { 28 | this.finish(container); 29 | return true; 30 | } 31 | return false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /engine/src/lib/actions/CallFunc.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class CallFunc extends TimeableAction { 4 | constructor(func, time = 0) { 5 | super(time); 6 | this.func = func || (() => { 7 | }); 8 | this.reset(); 9 | } 10 | 11 | update(container, delta) { 12 | this.func(container, this.restTime, delta); 13 | return super.update(container, delta); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /engine/src/lib/actions/DelayTime.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class DelayTime extends TimeableAction { 4 | constructor(time) { 5 | super(time); 6 | this.reset(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /engine/src/lib/actions/Ease.js: -------------------------------------------------------------------------------- 1 | import Action from './Action'; 2 | import { 3 | linear, 4 | easeInQuad, 5 | easeOutQuad, 6 | easeInOutQuad, 7 | easeInCubic, 8 | easeOutCubic, 9 | easeInOutCubic, 10 | easeInQuart, 11 | easeOutQuart, 12 | easeInOutQuart, 13 | easeInQuint, 14 | easeOutQuint, 15 | easeInOutQuint, 16 | } from './easingHelper'; 17 | 18 | class Ease extends Action { 19 | constructor(action, easeType = easeOutQuad) { 20 | super(); 21 | this.time = action.time; 22 | this.action = action; 23 | if (typeof easeType !== 'string') { 24 | this.easeType = easeType; 25 | } else { 26 | this.easeType = Ease.TYPE[easeType]; 27 | if (!this.easeType) { 28 | throw new Error(`Wrong easeType ${easeType}`); 29 | } 30 | } 31 | this.reset(); 32 | } 33 | 34 | reset() { 35 | this.originialTimePassed = 0; 36 | this.timePassed = 0; 37 | this.action.reset(); 38 | super.reset(); 39 | } 40 | 41 | update(container, delta) { 42 | this.originialTimePassed += delta; 43 | const easeDelta = this.originialTimePassed <= this.time ? 44 | Math.max( 45 | (this.time * this.easeType(this.originialTimePassed / this.time)) - this.timePassed, 46 | 0 47 | ) : delta; 48 | this.timePassed += easeDelta; 49 | const result = this.action.update(container, easeDelta); 50 | if (result) { 51 | this.finish(container); 52 | } 53 | return result; 54 | } 55 | 56 | finish(container) { 57 | this.action.finish(container); 58 | super.finish(container); 59 | } 60 | } 61 | 62 | Ease.TYPE = { 63 | LINEAR: linear, 64 | EASE_IN_QUAD: easeInQuad, 65 | EASE_OUT_QUAD: easeOutQuad, 66 | EASE_IN_OUT_QUAD: easeInOutQuad, 67 | EASE_IN_CUBIC: easeInCubic, 68 | EASE_OUT_CUBIC: easeOutCubic, 69 | EASE_IN_OUT_CUBIC: easeInOutCubic, 70 | EASE_IN_QUART: easeInQuart, 71 | EASE_OUT_QUART: easeOutQuart, 72 | EASE_IN_OUT_QUART: easeInOutQuart, 73 | EASE_IN_QUINT: easeInQuint, 74 | EASE_OUT_QUINT: easeOutQuint, 75 | EASE_IN_OUT_QUINT: easeInOutQuint, 76 | }; 77 | 78 | export default Ease; 79 | -------------------------------------------------------------------------------- /engine/src/lib/actions/FadeIn.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class FadeIn extends TimeableAction { 4 | constructor(time) { 5 | super(time); 6 | this.alpha = 1; 7 | this.reset(); 8 | } 9 | 10 | // if end return true, if not end return false 11 | update(container, delta) { 12 | const { alpha } = container; 13 | container.alpha += ((this.alpha - alpha) / this.restTime) * delta; 14 | return super.update(container, delta); 15 | } 16 | 17 | finish(container) { 18 | container.alpha = this.alpha; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /engine/src/lib/actions/FadeOut.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class FadeOut extends TimeableAction { 4 | constructor(time) { 5 | super(time); 6 | this.alpha = 0; 7 | this.reset(); 8 | } 9 | 10 | // if end return true, if not end return false 11 | update(container, delta) { 12 | const { alpha } = container; 13 | container.alpha += ((this.alpha - alpha) / this.restTime) * delta; 14 | return super.update(container, delta); 15 | } 16 | 17 | finish(container) { 18 | container.alpha = this.alpha; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /engine/src/lib/actions/FilterTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class FilterTo extends TimeableAction { 4 | constructor(filterIdx, propName, propValue, time) { 5 | super(time); 6 | this.filterIdx = filterIdx; 7 | this.propName = propName; 8 | this.propValue = propValue; 9 | this.reset(); 10 | } 11 | 12 | // if end return true, if not end return false 13 | update(container, delta) { 14 | const value = container.filters[this.filterIdx][this.propName]; 15 | container.filters[this.filterIdx][this.propName] += 16 | ((this.propValue - value) / this.restTime) * delta; 17 | return super.update(container, delta); 18 | } 19 | 20 | finish(container) { 21 | container.filters[this.filterIdx][this.propName] = this.propValue; 22 | super.finish(container); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /engine/src/lib/actions/MoveBy.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class MoveBy extends TimeableAction { 4 | constructor(x, y, time) { 5 | super(time); 6 | this.x = x; 7 | this.y = y; 8 | this.reset(); 9 | } 10 | 11 | reset() { 12 | super.reset(); 13 | this.tx = null; // target x 14 | this.ty = null; // target y 15 | } 16 | 17 | update(container, delta) { 18 | const pos = container.position; 19 | if (this.tx === null || this.ty === null) { 20 | this.tx = pos.x + this.x; 21 | this.ty = pos.y + this.y; 22 | } 23 | const speedX = ((this.tx - pos.x) / this.restTime) * delta; 24 | const speedY = ((this.ty - pos.y) / this.restTime) * delta; 25 | container.x += speedX; 26 | container.y += speedY; 27 | return super.update(container, delta); 28 | } 29 | 30 | finish(container) { 31 | container.x = this.tx; 32 | container.y = this.ty; 33 | super.finish(container); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /engine/src/lib/actions/MoveTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class MoveTo extends TimeableAction { 4 | constructor(x, y, time) { 5 | super(time); 6 | this.x = x; 7 | this.y = y; 8 | this.reset(); 9 | } 10 | 11 | update(container, delta) { 12 | const pos = container.position; 13 | const speedX = ((this.x - pos.x) / this.restTime) * delta; 14 | const speedY = ((this.y - pos.y) / this.restTime) * delta; 15 | container.x += speedX; 16 | container.y += speedY; 17 | return super.update(container, delta); 18 | } 19 | 20 | finish(container) { 21 | container.x = this.x; 22 | container.y = this.y; 23 | super.finish(container); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /engine/src/lib/actions/PivotBy.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class PivotBy extends TimeableAction { 4 | constructor(x, y, time) { 5 | super(time); 6 | this.x = x; 7 | this.y = y; 8 | this.reset(); 9 | } 10 | 11 | reset() { 12 | super.reset(); 13 | this.tx = null; // target x 14 | this.ty = null; // target y 15 | } 16 | 17 | // if end return true, if not end return false 18 | update(container, delta) { 19 | const { pivot } = container; 20 | if (this.tx === null || this.ty === null) { 21 | this.tx = pivot.x + this.x; 22 | this.ty = pivot.y + this.y; 23 | } 24 | const speedX = ((this.tx - pivot.x) / this.restTime) * delta; 25 | const speedY = ((this.ty - pivot.y) / this.restTime) * delta; 26 | container.pivot.x += speedX; 27 | container.pivot.y += speedY; 28 | return super.update(container, delta); 29 | } 30 | 31 | finish(container) { 32 | container.pivot.x = this.tx; 33 | container.pivot.y = this.ty; 34 | super.finish(container); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /engine/src/lib/actions/PivotTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class PivotTo extends TimeableAction { 4 | constructor(x, y, time) { 5 | super(time); 6 | this.x = x; 7 | this.y = y; 8 | this.reset(); 9 | } 10 | 11 | update(container, delta) { 12 | const { pivot } = container; 13 | const speedX = ((this.x - pivot.x) / this.restTime) * delta; 14 | const speedY = ((this.y - pivot.y) / this.restTime) * delta; 15 | container.pivot.x += speedX; 16 | container.pivot.y += speedY; 17 | return super.update(container, delta); 18 | } 19 | 20 | finish(container) { 21 | container.pivot.x = this.x; 22 | container.pivot.y = this.y; 23 | super.finish(container); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /engine/src/lib/actions/Repeat.js: -------------------------------------------------------------------------------- 1 | import Action from './Action'; 2 | 3 | export default class Repeat extends Action { 4 | constructor(action, count) { 5 | super(); 6 | this.action = action; 7 | this.count = count; 8 | this.reset(); 9 | } 10 | 11 | reset() { 12 | this._count = this.count; 13 | if (!this._count) { 14 | this._count = Infinity; 15 | } 16 | } 17 | 18 | update(container, delta) { 19 | const isEnd = this.action.update(container, delta); 20 | if (isEnd) { 21 | this.action.reset(); 22 | this._count -= 1; 23 | } 24 | if (this._count <= 0) { 25 | this.finish(container); 26 | return true; 27 | } 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /engine/src/lib/actions/RotateBy.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class RotateBy extends TimeableAction { 4 | constructor(rotation, time) { 5 | super(time); 6 | this.rotation = rotation; 7 | this.reset(); 8 | } 9 | 10 | reset() { 11 | super.reset(); 12 | this.trotation = null; // target rotation 13 | } 14 | 15 | update(container, delta) { 16 | const { rotation } = container; 17 | 18 | if (this.trotation === null) { 19 | this.trotation = rotation + this.rotation; 20 | } 21 | container.rotation += ((this.trotation - rotation) / this.restTime) * delta; 22 | return super.update(container, delta); 23 | } 24 | 25 | finish(container) { 26 | container.rotation = this.trotation; 27 | super.finish(container); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /engine/src/lib/actions/RotateTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class RotateTo extends TimeableAction { 4 | constructor(rotation, time) { 5 | super(time); 6 | this.rotation = rotation; 7 | this.reset(); 8 | } 9 | 10 | update(container, delta) { 11 | const { rotation } = container; 12 | while (this.rotation - rotation > Math.PI) { 13 | this.rotation -= Math.PI * 2; 14 | } 15 | while (this.rotation - rotation < -Math.PI) { 16 | this.rotation += Math.PI * 2; 17 | } 18 | container.rotation += ((this.rotation - rotation) / this.restTime) * delta; 19 | return super.update(container, delta); 20 | } 21 | 22 | finish(container) { 23 | container.rotation = this.rotation; 24 | super.finish(container); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /engine/src/lib/actions/ScaleBy.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class ScaleBy extends TimeableAction { 4 | constructor(scaleX, scaleY, time) { 5 | super(time); 6 | this.x = scaleX; 7 | this.y = scaleY; 8 | this.reset(); 9 | } 10 | 11 | reset() { 12 | super.reset(); 13 | this.tx = null; // target scale x 14 | this.ty = null; // target scale y 15 | } 16 | 17 | update(container, delta) { 18 | const { scale } = container; 19 | if (this.tx === null || this.ty === null) { 20 | this.tx = scale.x + this.x; 21 | this.ty = scale.y + this.y; 22 | } 23 | const speedX = ((this.tx - scale.x) / this.restTime) * delta; 24 | const speedY = ((this.ty - scale.y) / this.restTime) * delta; 25 | container.scale.x += speedX; 26 | container.scale.y += speedY; 27 | return super.update(container, delta); 28 | } 29 | 30 | finish(container) { 31 | container.scale.x = this.tx; 32 | container.scale.y = this.ty; 33 | super.finish(container); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /engine/src/lib/actions/ScaleTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class ScaleTo extends TimeableAction { 4 | constructor(scaleX, scaleY, time) { 5 | super(time); 6 | this.x = scaleX; 7 | this.y = scaleY; 8 | this.reset(); 9 | } 10 | 11 | update(container, delta) { 12 | const { scale } = container; 13 | const speedX = ((this.x - scale.x) / this.restTime) * delta; 14 | const speedY = ((this.y - scale.y) / this.restTime) * delta; 15 | container.scale.x += speedX; 16 | container.scale.y += speedY; 17 | return super.update(container, delta); 18 | } 19 | 20 | finish(container) { 21 | container.scale.x = this.x; 22 | container.scale.y = this.y; 23 | super.finish(container); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /engine/src/lib/actions/Sequence.js: -------------------------------------------------------------------------------- 1 | import Action from './Action'; 2 | 3 | export default class Sequence extends Action { 4 | constructor(actions) { 5 | super(); 6 | this.actions = actions; 7 | this.reset(); 8 | } 9 | 10 | reset() { 11 | this._index = 0; 12 | } 13 | 14 | update(container, delta) { 15 | if (this._index >= this.actions.length) { 16 | return true; 17 | } 18 | const action = this.actions[this._index]; 19 | const isEnd = action.update(container, delta); 20 | if (isEnd) { 21 | action.reset(); 22 | this._index += 1; 23 | } 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /engine/src/lib/actions/SkewBy.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class SkewBy extends TimeableAction { 4 | constructor(x, y, time) { 5 | super(time); 6 | this.x = x; 7 | this.y = y; 8 | this.reset(); 9 | } 10 | 11 | reset() { 12 | super.reset(); 13 | this.tx = null; // target x 14 | this.ty = null; // target y 15 | } 16 | 17 | update(container, delta) { 18 | const { skew } = container; 19 | if (this.tx === null || this.ty === null) { 20 | this.tx = skew.x + this.x; 21 | this.ty = skew.y + this.y; 22 | } 23 | const speedX = ((this.tx - skew.x) / this.restTime) * delta; 24 | const speedY = ((this.ty - skew.y) / this.restTime) * delta; 25 | container.skew.x += speedX; 26 | container.skew.y += speedY; 27 | return super.update(container, delta); 28 | } 29 | 30 | finish(container) { 31 | container.skew.x = this.tx; 32 | container.skew.y = this.ty; 33 | super.finish(container); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /engine/src/lib/actions/SkewTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class SkewTo extends TimeableAction { 4 | constructor(x, y, time) { 5 | super(time); 6 | this.x = x; 7 | this.y = y; 8 | this.reset(); 9 | } 10 | 11 | update(container, delta) { 12 | const { skew } = container; 13 | const speedX = ((this.x - skew.x) / this.restTime) * delta; 14 | const speedY = ((this.y - skew.y) / this.restTime) * delta; 15 | container.skew.x += speedX; 16 | container.skew.y += speedY; 17 | return super.update(container, delta); 18 | } 19 | 20 | finish(container) { 21 | container.skew.x = this.x; 22 | container.skew.y = this.y; 23 | super.finish(container); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /engine/src/lib/actions/Spawn.js: -------------------------------------------------------------------------------- 1 | import Action from './Action'; 2 | 3 | /** 4 | * Spawn is very similar to Sequence, except that all actions will run at the same time. 5 | */ 6 | export default class Spawn extends Action { 7 | constructor(actions) { 8 | super(); 9 | this.actions = actions; 10 | this.reset(); 11 | } 12 | 13 | reset() { 14 | this.actionsToRun = [...this.actions]; 15 | } 16 | 17 | update(container, delta) { 18 | this.actionsToRun = this.actionsToRun.filter((action) => { 19 | const isEnd = action.update(container, delta); 20 | if (isEnd) { 21 | action.reset(); 22 | return false; 23 | } else { 24 | return true; 25 | } 26 | }); 27 | if (this.actionsToRun.length === 0) { 28 | this.finish(container); 29 | return true; 30 | } 31 | return false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /engine/src/lib/actions/TimeableAction.js: -------------------------------------------------------------------------------- 1 | import Action from './Action'; 2 | 3 | export default class TimeableAction extends Action { 4 | constructor(time) { 5 | super(); 6 | this.time = time * 1000; 7 | } 8 | 9 | reset() { 10 | this.restTime = this.time; 11 | } 12 | 13 | update(container, delta) { 14 | this.restTime -= delta; 15 | if (this.restTime <= 0) { 16 | this.finish(container); 17 | return true; 18 | } 19 | return false; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /engine/src/lib/actions/TintBy.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class TintBy extends TimeableAction { 4 | constructor(tint, time) { 5 | super(time); 6 | this.tint = tint; 7 | this.reset(); 8 | } 9 | 10 | reset() { 11 | super.reset(); 12 | this.ttint = null; 13 | } 14 | 15 | // if end return true, if not end return false 16 | update(container, delta) { 17 | const { tint } = container; 18 | if (this.ttint === null) { 19 | this.ttint = tint + this.tint; 20 | } 21 | container.tint += ((this.ttint - tint) / this.restTime) * delta; 22 | return super.update(container, delta); 23 | } 24 | 25 | finish(container) { 26 | container.tint = this.ttint; 27 | super.finish(container); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /engine/src/lib/actions/TintTo.js: -------------------------------------------------------------------------------- 1 | import TimeableAction from './TimeableAction'; 2 | 3 | export default class TintTo extends TimeableAction { 4 | constructor(tint, time) { 5 | super(time); 6 | this.tint = tint; 7 | this.reset(); 8 | } 9 | 10 | update(container, delta) { 11 | container.tint = this._interpolateColor(container.tint, this.tint, delta); 12 | return super.update(container, delta); 13 | } 14 | 15 | finish(container) { 16 | container.tint = this.tint; 17 | super.finish(container); 18 | } 19 | 20 | _interpolateColor(fromTint, targetTint, delta) { 21 | const fromRGB = TintTo._getRGB(fromTint); 22 | const toRGB = TintTo._getRGB(targetTint); 23 | 24 | const result = {}; 25 | result.r = fromRGB.r + (((toRGB.r - fromRGB.r) / this.restTime) * delta); 26 | result.g = fromRGB.g + (((toRGB.g - fromRGB.g) / this.restTime) * delta); 27 | result.b = fromRGB.b + (((toRGB.b - fromRGB.b) / this.restTime) * delta); 28 | 29 | return TintTo._packRGB(result); 30 | } 31 | 32 | static _getRGB(color) { 33 | /* eslint-disable no-bitwise */ 34 | return { 35 | r: color >>> 16, 36 | g: (color & 0x00ff00) >>> 8, 37 | b: color & 0x0000ff, 38 | }; 39 | /* eslint-enable no-bitwise */ 40 | } 41 | 42 | static _packRGB({ r, g, b }) { 43 | // eslint-disable-next-line no-bitwise 44 | return (r << 16) | (g << 8) | b; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /engine/src/lib/actions/easingHelper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 22/09/2017. 3 | */ 4 | export const easeIn = power => t => t ** power; 5 | export const easeOut = power => t => 1 - Math.abs((t - 1) ** power); 6 | export const easeInOut = power => t => 7 | (t < 0.5 ? easeIn(power)(t * 2) / 2 : (easeOut(power)((t * 2) - 1) / 2) + 0.5); 8 | 9 | export const linear = easeInOut(1); 10 | export const easeInQuad = easeIn(2); 11 | export const easeOutQuad = easeOut(2); 12 | export const easeInOutQuad = easeInOut(2); 13 | export const easeInCubic = easeIn(3); 14 | export const easeOutCubic = easeOut(3); 15 | export const easeInOutCubic = easeInOut(3); 16 | export const easeInQuart = easeIn(4); 17 | export const easeOutQuart = easeOut(4); 18 | export const easeInOutQuart = easeInOut(4); 19 | export const easeInQuint = easeIn(5); 20 | export const easeOutQuint = easeOut(5); 21 | export const easeInOutQuint = easeInOut(5); 22 | -------------------------------------------------------------------------------- /engine/src/lib/actions/index.js: -------------------------------------------------------------------------------- 1 | import ActionManager from './ActionManager'; 2 | import AlphaBy from './AlphaBy'; 3 | import AlphaTo from './AlphaTo'; 4 | import Blink from './Blink'; 5 | import CallFunc from './CallFunc'; 6 | import DelayTime from './DelayTime'; 7 | import Ease from './Ease'; 8 | import FadeIn from './FadeIn'; 9 | import FadeOut from './FadeOut'; 10 | import FilterTo from './FilterTo'; 11 | import MoveBy from './MoveBy'; 12 | import MoveTo from './MoveTo'; 13 | import PivotBy from './PivotBy'; 14 | import PivotTo from './PivotTo'; 15 | import Repeat from './Repeat'; 16 | import RotateBy from './RotateBy'; 17 | import RotateTo from './RotateTo'; 18 | import ScaleBy from './ScaleBy'; 19 | import ScaleTo from './ScaleTo'; 20 | import Sequence from './Sequence'; 21 | import SkewBy from './SkewBy'; 22 | import SkewTo from './SkewTo'; 23 | import Spawn from './Spawn'; 24 | import TintBy from './TintBy'; 25 | import TintTo from './TintTo'; 26 | 27 | export default { 28 | ActionManager, 29 | AlphaBy, 30 | AlphaTo, 31 | Blink, 32 | CallFunc, 33 | DelayTime, 34 | Ease, 35 | FadeIn, 36 | FadeOut, 37 | FilterTo, 38 | MoveBy, 39 | MoveTo, 40 | PivotBy, 41 | PivotTo, 42 | Repeat, 43 | RotateBy, 44 | RotateTo, 45 | ScaleBy, 46 | ScaleTo, 47 | Sequence, 48 | SkewBy, 49 | SkewTo, 50 | Spawn, 51 | TintBy, 52 | TintTo, 53 | }; 54 | 55 | export { 56 | ActionManager, 57 | AlphaBy, 58 | AlphaTo, 59 | Blink, 60 | CallFunc, 61 | DelayTime, 62 | Ease, 63 | FadeIn, 64 | FadeOut, 65 | FilterTo, 66 | MoveBy, 67 | MoveTo, 68 | PivotBy, 69 | PivotTo, 70 | Repeat, 71 | RotateBy, 72 | RotateTo, 73 | ScaleBy, 74 | ScaleTo, 75 | Sequence, 76 | SkewBy, 77 | SkewTo, 78 | Spawn, 79 | TintBy, 80 | TintTo, 81 | }; 82 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/add.js: -------------------------------------------------------------------------------- 1 | export default (args) => { 2 | let result = 0; 3 | args.forEach((arg) => { 4 | result += arg; 5 | }); 6 | return result; 7 | }; 8 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/and.js: -------------------------------------------------------------------------------- 1 | export default args => args.every(arg => arg); 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/calc.js: -------------------------------------------------------------------------------- 1 | import resolveProp from '../utils/resolveProp'; 2 | 3 | export default (calcName, { default: defaultValue, koef = 1 }, stateParams) => { 4 | let result = resolveProp(stateParams.calcs, calcName); 5 | if (result === undefined) { 6 | result = defaultValue; 7 | } 8 | return typeof result === 'number' ? koef * result : result; 9 | }; 10 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/concat.js: -------------------------------------------------------------------------------- 1 | export default (args) => { 2 | let result = ''; 3 | args.forEach((arg) => { 4 | result += arg; 5 | }); 6 | return result; 7 | }; 8 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/div.js: -------------------------------------------------------------------------------- 1 | export default ([arg1, arg2]) => arg1 / arg2; 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/eq.js: -------------------------------------------------------------------------------- 1 | /* eslint eqeqeq: "off" */ 2 | export default ([arg1, arg2]) => arg1 == arg2; 3 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/gt.js: -------------------------------------------------------------------------------- 1 | export default ([arg1, arg2]) => arg1 > arg2; 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/gte.js: -------------------------------------------------------------------------------- 1 | export default ([arg1, arg2]) => arg1 >= arg2; 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/if.js: -------------------------------------------------------------------------------- 1 | export default (condition, { then = true, else: elseExpr = false }) => 2 | (condition ? then : elseExpr); 3 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/index.js: -------------------------------------------------------------------------------- 1 | export { default as add } from './add'; 2 | export { default as and } from './and'; 3 | export { default as calc } from './calc'; 4 | export { default as div } from './div'; 5 | export { default as eq } from './eq'; 6 | export { default as gt } from './gt'; 7 | export { default as gte } from './gte'; 8 | export { default as if } from './if'; 9 | export { default as lt } from './lt'; 10 | export { default as lte } from './lte'; 11 | export { default as max } from './max'; 12 | export { default as min } from './min'; 13 | export { default as mul } from './mul'; 14 | export { default as not } from './not'; 15 | export { default as or } from './or'; 16 | export { default as processorParam } from './processorParam'; 17 | export { default as random } from './random'; 18 | export { default as rel } from './rel'; 19 | export { default as state } from './state'; 20 | export { default as sub } from './sub'; 21 | export { default as concat } from './concat'; 22 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/lt.js: -------------------------------------------------------------------------------- 1 | export default ([arg1, arg2]) => arg1 < arg2; 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/lte.js: -------------------------------------------------------------------------------- 1 | export default ([arg1, arg2]) => arg1 <= arg2; 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/max.js: -------------------------------------------------------------------------------- 1 | export default args => Math.max(...args); 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/min.js: -------------------------------------------------------------------------------- 1 | export default args => Math.min(...args); 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/mul.js: -------------------------------------------------------------------------------- 1 | export default (args) => { 2 | let result = 1; 3 | args.forEach((arg) => { 4 | result *= arg; 5 | }); 6 | return result; 7 | }; 8 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/not.js: -------------------------------------------------------------------------------- 1 | export default arg => !arg; 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/or.js: -------------------------------------------------------------------------------- 1 | export default args => args.some(arg => arg); 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/processorParam.js: -------------------------------------------------------------------------------- 1 | import resolveProp from '../utils/resolveProp'; 2 | 3 | export default (paramName, { default: defaultValue, koef = 1 }, stateParams) => { 4 | let result = resolveProp(stateParams, paramName); 5 | if (result === undefined) { 6 | result = defaultValue; 7 | } 8 | return typeof result === 'number' ? koef * result : result; 9 | }; 10 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/random.js: -------------------------------------------------------------------------------- 1 | export default range => Math.random() * range; 2 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/rel.js: -------------------------------------------------------------------------------- 1 | import resolveProp from '../utils/resolveProp'; 2 | 3 | export default (fieldName, { default: defaultValue, koef = 1 }, stateParams) => { 4 | let result = resolveProp(stateParams.target || stateParams.renderData, fieldName); 5 | if (result === undefined) { 6 | result = defaultValue; 7 | } 8 | return typeof result === 'number' ? koef * result : result; 9 | }; 10 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/state.js: -------------------------------------------------------------------------------- 1 | import resolveProp from '../utils/resolveProp'; 2 | 3 | export default (fieldName, { default: defaultValue, koef = 1 }, stateParams) => { 4 | let result = resolveProp(stateParams.state, fieldName); 5 | if (result === undefined) { 6 | result = defaultValue; 7 | } 8 | return typeof result === 'number' ? koef * result : result; 9 | }; 10 | -------------------------------------------------------------------------------- /engine/src/lib/expressions/sub.js: -------------------------------------------------------------------------------- 1 | export default ([arg0, ...args]) => { 2 | let result = arg0; 3 | args.forEach((arg) => { 4 | result -= arg; 5 | }); 6 | return result; 7 | }; 8 | -------------------------------------------------------------------------------- /engine/src/lib/processors/circle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | import draw from './draw'; 6 | import actionHelper from '../utils/actionHelper'; 7 | 8 | export default (params) => { 9 | const { 10 | payload: { 11 | color, 12 | radius = 25, 13 | stroke: strokeColor = 0x000000, 14 | strokeWidth, 15 | ...payload 16 | } = {}, 17 | ...otherParams 18 | } = params; 19 | const graphics = draw({ payload, ...otherParams }); 20 | if (graphics) { 21 | if (strokeWidth) { 22 | graphics.lineStyle(strokeWidth, strokeColor, 1); 23 | } 24 | if (color || color === 0) { 25 | graphics.beginFill(color); 26 | } 27 | graphics.drawCircle(0, 0, actionHelper.parseExpression(radius, params)); 28 | if (color || color === 0) { 29 | graphics.endFill(); 30 | } 31 | } 32 | return graphics; 33 | }; 34 | -------------------------------------------------------------------------------- /engine/src/lib/processors/container.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 29/08/2017. 3 | */ 4 | 5 | import { Container } from 'pixi.js'; 6 | 7 | import object from './object'; 8 | 9 | export default params => object(params, Container); 10 | -------------------------------------------------------------------------------- /engine/src/lib/processors/disappear.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | import { CallFunc, FadeOut, Sequence } from '../actions'; 6 | 7 | export default ({ stage, rootContainer, tickDuration, callback }) => { 8 | const { actionManager } = stage; 9 | const action = new Sequence([ 10 | new FadeOut(tickDuration / 2), 11 | new CallFunc(() => { 12 | callback(); 13 | }), 14 | ]); 15 | // TODO: Cancel all previous actions 16 | actionManager.runAction(rootContainer, action); 17 | }; 18 | -------------------------------------------------------------------------------- /engine/src/lib/processors/draw.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 22/08/2017. 3 | */ 4 | 5 | import { Graphics } from 'pixi.js'; 6 | 7 | import object from './object'; 8 | import actionHelper from '../utils/actionHelper'; 9 | 10 | export default (params) => { 11 | const { 12 | logger, 13 | payload: { drawings = [], ...payload } = {}, 14 | ...otherParams 15 | } = params; 16 | const gameObject = object( 17 | Object.assign(params, { logger, payload, ...otherParams }), Graphics); 18 | if (gameObject) { 19 | drawings.forEach(({ method: methodName, params: drawingParams = [] }) => { 20 | const parsedParams = actionHelper.parseExpressions(drawingParams, params); 21 | const method = gameObject[methodName]; 22 | if (!method) { 23 | logger.warn('Cannot resolve drawing method', methodName); 24 | } 25 | method.call(gameObject, ...parsedParams); 26 | }); 27 | } 28 | return gameObject; 29 | }; 30 | -------------------------------------------------------------------------------- /engine/src/lib/processors/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | import circle from './circle'; 6 | import container from './container'; 7 | import creepActions from './creepActions'; 8 | import creepBuildBody from './creepBuildBody'; 9 | import disappear from './disappear'; 10 | import draw from './draw'; 11 | import moveTo from './moveTo'; 12 | import object from './object'; 13 | import powerInfluence from './powerInfluence'; 14 | import resourceCircle from './resourceCircle'; 15 | import road from './road'; 16 | import runAction from './runAction'; 17 | import say from './say'; 18 | import setBadgeUrls from './setBadgeUrls'; 19 | import siteProgress from './siteProgress'; 20 | import sprite from './sprite'; 21 | import terrain from './terrain'; 22 | import text from './text'; 23 | import userBadge from './userBadge'; 24 | import creepDecoration from './creepDecoration'; 25 | import objectDecoration from './objectDecoration'; 26 | 27 | export default { 28 | circle, 29 | container, 30 | creepActions, 31 | creepBuildBody, 32 | disappear, 33 | draw, 34 | moveTo, 35 | object, 36 | powerInfluence, 37 | resourceCircle, 38 | road, 39 | runAction, 40 | say, 41 | setBadgeUrls, 42 | siteProgress, 43 | sprite, 44 | terrain, 45 | text, 46 | userBadge, 47 | creepDecoration, 48 | objectDecoration, 49 | }; 50 | -------------------------------------------------------------------------------- /engine/src/lib/processors/moveTo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | import { calculateAngle, convertGameXYToWorld } from '../../../../helpers/mathHelper'; 6 | import { RotateTo, Spawn } from '../actions'; 7 | 8 | /** 9 | * @param params 10 | */ 11 | export default ({ 12 | firstRun, 13 | state, 14 | payload: { targetKey, shouldRotate = false } = {}, 15 | rootContainer, 16 | stage, 17 | prevState, 18 | scope, 19 | tickDuration, 20 | world: { 21 | options: worldOptions, 22 | }, 23 | }) => { 24 | const { actionManager } = stage; 25 | const { x, y } = convertGameXYToWorld(state, worldOptions); 26 | 27 | const targetObject = targetKey ? scope[targetKey] : rootContainer; 28 | if (!firstRun) { 29 | const actions = []; 30 | 31 | // it's not initial state as we do not want to rotate it at initial phase 32 | if (prevState && shouldRotate) { 33 | actions.push(new RotateTo( 34 | calculateAngle(targetObject.x, targetObject.y, x, y), tickDuration / 5)); 35 | } 36 | 37 | const action = new Spawn(actions); 38 | if (scope.moveToAction) { 39 | actionManager.cancelAction(scope.moveToAction); 40 | } 41 | scope.moveToAction = actionManager.runAction(targetObject, action); 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /engine/src/lib/processors/resourceCircle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | import circle from './circle'; 6 | import actionHelper from '../utils/actionHelper'; 7 | 8 | const METADATA = { 9 | creepEnergy: { 10 | color: 0xffe56d, 11 | radius: 20, 12 | }, 13 | energy: { 14 | color: 0xffe56d, 15 | radius: 30, 16 | }, 17 | power: { 18 | color: 0xf41f33, 19 | radius: 45, 20 | }, 21 | }; 22 | 23 | const DEFAULT_METADATA = { 24 | color: 0xFFFFFF, 25 | radius: 45, 26 | }; 27 | 28 | export default (params) => { 29 | const { 30 | state: { 31 | resourceType: resourceMetaName = 'creepEnergy', 32 | resourceType = 'energy', 33 | [resourceType]: newResource, 34 | [`${resourceType}Capacity`]: capacity = 1250.0, 35 | } = {}, 36 | prevState: { [resourceType]: resource } = {}, 37 | payload: { 38 | radius: payloadRadius, 39 | } = {}, 40 | ...otherParams 41 | } = params; 42 | 43 | if (resource !== newResource) { 44 | const { 45 | [resourceMetaName]: { color, radius: metadataRadius } = DEFAULT_METADATA, 46 | } = METADATA; 47 | const parsedPayloadRadius = actionHelper.parseExpression(payloadRadius, params); 48 | const radius = (parsedPayloadRadius || metadataRadius) * 49 | Math.min(1, (capacity !== 0 ? newResource / capacity : 0)); 50 | return circle({ 51 | payload: { 52 | color, 53 | radius, 54 | }, 55 | ...otherParams, 56 | }); 57 | } 58 | }; 59 | -------------------------------------------------------------------------------- /engine/src/lib/processors/runAction.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 22/08/2017. 3 | */ 4 | 5 | export default { 6 | config: { isOwner: false }, 7 | run: (params) => { 8 | const { 9 | rootContainer, 10 | scope, 11 | payload: { id } = {}, 12 | } = params; 13 | 14 | return id ? scope[id] : rootContainer; 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /engine/src/lib/processors/say.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 22/08/2017. 3 | */ 4 | 5 | import { Container, TextMetrics, TextStyle, Graphics, Point } from 'pixi.js'; 6 | 7 | import object from './object'; 8 | import text from './text'; 9 | import actionHelper from '../utils/actionHelper'; 10 | 11 | const PRIVATE_COLOR = 0xcccccc; 12 | const PUBLIC_COLOR = 0xdd8888; 13 | 14 | export default (params) => { 15 | const { 16 | payload: { say }, 17 | world: { app: { stage } }, 18 | scope, 19 | } = params; 20 | const parsedSay = actionHelper.parseExpression(say, params); 21 | 22 | const backgroundColor = parsedSay.isPublic ? PUBLIC_COLOR : PRIVATE_COLOR; 23 | const style = { 24 | align: 'center', 25 | fill: '#111', 26 | fontFamily: 'Roboto, sans-serif', 27 | fontSize: 60, 28 | }; 29 | const container = object(params, Container); 30 | scope.sayContainer = container; 31 | 32 | const textMetrics = TextMetrics.measureText(parsedSay.message, new TextStyle(style)); 33 | 34 | const bubbleWidth = textMetrics.width + 60; 35 | const bubbleHeight = 100; 36 | const bubbleOffset = -170; 37 | 38 | const graphics = new Graphics(); 39 | graphics.lineStyle(8, 0x000000); 40 | graphics.beginFill(backgroundColor); 41 | graphics.drawRoundedRect(-bubbleWidth / 2, bubbleOffset, bubbleWidth, bubbleHeight, 30); 42 | graphics.drawPolygon([ 43 | new Point(30, -74), 44 | new Point(0, -44), 45 | new Point(-30, -74), 46 | ]); 47 | graphics.endFill(); 48 | container.addChild(graphics); 49 | 50 | const textParams = Object.assign({}, params, { 51 | id: 'sayText', 52 | payload: { 53 | parentId: 'sayContainer', 54 | text: parsedSay.message, 55 | style, 56 | x: 0, 57 | y: bubbleOffset + (bubbleHeight / 2), 58 | anchor: { 59 | x: 0.5, 60 | y: 0.5, 61 | }, 62 | }, 63 | }); 64 | text(textParams); 65 | 66 | actionHelper.addTickerHandler(container, () => 67 | actionHelper.alignPositionToPixels(container, stage)); 68 | 69 | return container; 70 | }; 71 | -------------------------------------------------------------------------------- /engine/src/lib/processors/setBadgeUrls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 13/09/2017. 3 | */ 4 | 5 | export default ({ state, world: { options: { BADGE_URL } } }) => { 6 | const { users } = state; 7 | if (users) { 8 | Object.entries(users).forEach(([, user]) => { 9 | const { username } = user; 10 | user.badgeUrl = BADGE_URL.replace('%1', encodeURIComponent(username)); 11 | }); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /engine/src/lib/processors/siteProgress.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | import draw from './draw'; 6 | import actionHelper from '../utils/actionHelper'; 7 | 8 | function getStartPositionArc(angle, radius) { 9 | return { 10 | x: Math.cos(angle) * radius, 11 | y: Math.sin(angle) * radius, 12 | }; 13 | } 14 | 15 | export default (params) => { 16 | const { 17 | rootContainer, 18 | scope, 19 | payload, 20 | ...otherParams 21 | } = params; 22 | 23 | const progress = actionHelper.parseExpression(payload.progress, params); 24 | 25 | if (progress !== scope.oldProgress) { 26 | scope.oldProgress = progress; 27 | 28 | const graphics = draw({ rootContainer, scope, ...otherParams }); 29 | const progressTotal = actionHelper.parseExpression(payload.progressTotal, params); 30 | const color = actionHelper.parseExpression(payload.color, params); 31 | const radius = actionHelper.parseExpression(payload.radius, params); 32 | const lineWidth = actionHelper.parseExpression(payload.lineWidth, params); 33 | graphics.rotation = -Math.PI / 2; 34 | graphics.beginFill(0x000000, 0.0); 35 | graphics.lineStyle(lineWidth, color, 1); 36 | graphics.drawCircle(0, 0, radius + (lineWidth / 2)); 37 | 38 | if (progress > 0 && progressTotal > 0) { 39 | const angle = 2 * Math.PI * (Math.min(progress, progressTotal) / progressTotal); 40 | graphics.beginFill(color); 41 | graphics.moveTo(0, 0); 42 | graphics.lineStyle(1, color, 1); 43 | const arcStartingPoint = getStartPositionArc(0, radius); 44 | graphics.lineTo(arcStartingPoint.x, arcStartingPoint.y); 45 | graphics.arc(0, 0, radius, 0, angle); 46 | graphics.lineTo(0, 0); 47 | graphics.endFill(); 48 | } 49 | 50 | return graphics; 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /engine/src/lib/processors/text.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 22/08/2017. 3 | */ 4 | 5 | import { Text } from 'pixi.js'; 6 | 7 | import object from './object'; 8 | import actionHelper from '../utils/actionHelper'; 9 | 10 | export default (params) => { 11 | const { 12 | world, 13 | logger, 14 | payload: { text: textPayload = '?', style: stylePayload, ...payload } = {}, 15 | ...otherParams 16 | } = params; 17 | const parsedText = actionHelper.parseExpression(textPayload, params); 18 | const parsedStyle = actionHelper.parseExpression(stylePayload, params); 19 | const { app: { stage } } = world; 20 | 21 | const text = object( 22 | { world, logger, payload, ...otherParams }, 23 | Text, 24 | [parsedText, parsedStyle] 25 | ); 26 | 27 | // disable scaling, render fonts in their original size 28 | actionHelper.addTickerHandler(text, () => { 29 | text.scale.x = 1 / stage.scale.x; 30 | text.scale.y = 1 / stage.scale.y; 31 | text.style.fontSize = parsedStyle.fontSize * stage.scale.x; 32 | text.style.strokeThickness = (parsedStyle.strokeThickness || 0) * stage.scale.x; 33 | }); 34 | 35 | // match position to round number of pixels to prevent blurry text 36 | actionHelper.addTickerHandler(text, () => 37 | actionHelper.alignPositionToPixels(text, stage)); 38 | 39 | return text; 40 | }; 41 | -------------------------------------------------------------------------------- /engine/src/lib/processors/userBadge.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | import circle from './circle'; 6 | import sprite from './sprite'; 7 | 8 | const CIRCLE_PAYLOAD = { 9 | radius: 37, 10 | color: 0x222222, 11 | }; 12 | 13 | const BADGE_PAYLOAD = { 14 | texture: null, 15 | }; 16 | 17 | export default (params) => { 18 | const { 19 | payload: { 20 | parentId, 21 | radius = CIRCLE_PAYLOAD.radius, 22 | color = CIRCLE_PAYLOAD.color, 23 | ...restPayload 24 | } = {}, 25 | scope, 26 | scope: { [parentId]: parent }, 27 | state: { user }, 28 | stateExtra: { users = {} }, 29 | state, 30 | stateExtra, 31 | ...otherParams 32 | } = params; 33 | 34 | const userBadgeUrl = user && users[user] && users[user].badgeUrl; 35 | if (userBadgeUrl) { 36 | const spritePayload = { 37 | ...BADGE_PAYLOAD, 38 | width: 2 * radius, 39 | texture: userBadgeUrl, 40 | parentId, 41 | ...restPayload, 42 | }; 43 | const scope = { [parentId]: parent }; 44 | return sprite({ payload: spritePayload, scope, ...otherParams }); 45 | } else { 46 | return circle({ payload: { radius, color, parentId }, scope, ...otherParams }); 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /engine/src/lib/utils/resolveProp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 21/04/2017. 3 | */ 4 | 5 | export default function (obj, stringPath) { 6 | if (!obj || stringPath === '^') { 7 | return obj; 8 | } 9 | stringPath = stringPath.replace(/\[(\w+)]/g, '.$1'); // convert indexes to properties 10 | stringPath = stringPath.replace(/^\./, ''); // strip a leading dot 11 | const pathArray = stringPath.split('.'); 12 | while (pathArray.length && obj) { 13 | const pathItem = pathArray.shift(); 14 | if (pathItem in obj) { 15 | obj = obj[pathItem]; 16 | } else { 17 | return; 18 | } 19 | } 20 | return obj; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /engine/webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 05/04/2017. 3 | */ 4 | 5 | require('webpack'); 6 | const path = require('path'); 7 | 8 | const libraryName = 'renderer'; 9 | const plugins = []; 10 | 11 | const outputFile = `${libraryName}.js`; 12 | 13 | const config = { 14 | entry: `${__dirname}/src/index.js`, 15 | devtool: 'source-map', 16 | output: { 17 | path: `${__dirname}/dist`, 18 | filename: outputFile, 19 | library: libraryName, 20 | libraryTarget: 'umd', 21 | umdNamedDefine: true, 22 | }, 23 | module: { 24 | rules: [ 25 | { 26 | test: /\.(js|jsx)$/, 27 | enforce: 'pre', 28 | loader: 'eslint-loader', 29 | exclude: /node_modules/, 30 | }, 31 | { 32 | test: /(\.js)$/, 33 | use: [ 34 | { 35 | loader: 'babel-loader', 36 | }, 37 | ], 38 | exclude: /node_modules/, 39 | }, 40 | ], 41 | }, 42 | resolve: { 43 | modules: [ 44 | path.join(__dirname, 'src'), 45 | 'node_modules', 46 | ], 47 | }, 48 | plugins, 49 | }; 50 | 51 | module.exports = config; 52 | -------------------------------------------------------------------------------- /helpers/mathHelper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 07/04/2017. 3 | */ 4 | 5 | export const calculateAngle = (x0, y0, x, y) => { 6 | let angle = Math.atan2(y - y0, x - x0) + (Math.PI / 2); 7 | if (angle > Math.PI) { 8 | angle -= 2 * Math.PI; 9 | } else if (angle < -Math.PI) { 10 | angle += 2 * Math.PI; 11 | } 12 | return angle; 13 | }; 14 | export const convertGameXYToWorld = ({ x, y }, { CELL_SIZE }) => ({ 15 | x: (CELL_SIZE * x), 16 | y: (CELL_SIZE * y), 17 | }); 18 | export const scaleGameToWorld = (value, { CELL_SIZE }) => CELL_SIZE * value; 19 | 20 | export default { 21 | calculateAngle, 22 | convertGameXYToWorld, 23 | scaleGameToWorld, 24 | }; 25 | -------------------------------------------------------------------------------- /metadata/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /metadata/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # misc 10 | .DS_Store 11 | .env 12 | npm-debug.log* 13 | yarn-debug.log* 14 | yarn-error.log* 15 | -------------------------------------------------------------------------------- /metadata/.npmignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules 3 | src 4 | webpack 5 | 6 | .babelrc 7 | .eslintignore 8 | .eslintrc.js 9 | .gitignore 10 | webpack.config.js 11 | 12 | .DS_Store 13 | .env 14 | npm-debug.log* 15 | yarn-debug.log* 16 | yarn-error.log* 17 | 18 | .idea 19 | -------------------------------------------------------------------------------- /metadata/images/berserk.svg: -------------------------------------------------------------------------------- 1 | berserk -------------------------------------------------------------------------------- /metadata/images/controller-level.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 66 | -------------------------------------------------------------------------------- /metadata/images/cover.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 47 | 49 | 50 | 52 | image/svg+xml 53 | 55 | 56 | 57 | 58 | 59 | 64 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /metadata/images/creep-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/creep-mask.png -------------------------------------------------------------------------------- /metadata/images/creep-npc.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /metadata/images/defend.svg: -------------------------------------------------------------------------------- 1 | defend -------------------------------------------------------------------------------- /metadata/images/demolish.svg: -------------------------------------------------------------------------------- 1 | demolish -------------------------------------------------------------------------------- /metadata/images/deposit-biomass-fill.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | biomass 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /metadata/images/deposit-biomass.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | biomass 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /metadata/images/deposit-metal-fill.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 29 | 30 | metal 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /metadata/images/deposit-mist-fill.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | mist 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /metadata/images/deposit-mist.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | mist 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /metadata/images/deposit-silicon-fill.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | silicon 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /metadata/images/deposit-silicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | silicon 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /metadata/images/disable.svg: -------------------------------------------------------------------------------- 1 | disable -------------------------------------------------------------------------------- /metadata/images/disrupt-source.svg: -------------------------------------------------------------------------------- 1 | corrupt-source -------------------------------------------------------------------------------- /metadata/images/disrupt-spawn.svg: -------------------------------------------------------------------------------- 1 | disable-spawn -------------------------------------------------------------------------------- /metadata/images/disrupt-terminal.svg: -------------------------------------------------------------------------------- 1 | disable-terminal -------------------------------------------------------------------------------- /metadata/images/disrupt-tower.svg: -------------------------------------------------------------------------------- 1 | disable-tower -------------------------------------------------------------------------------- /metadata/images/drain-extension.svg: -------------------------------------------------------------------------------- 1 | drain-extension -------------------------------------------------------------------------------- /metadata/images/encourage.svg: -------------------------------------------------------------------------------- 1 | encourage -------------------------------------------------------------------------------- /metadata/images/executor-lvl0.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | executor-lvl1 6 | 7 | 8 | 10 | 11 | 13 | 15 | 17 | 19 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /metadata/images/executor-lvl1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | executor-lvl1 6 | 7 | 8 | 10 | 11 | 13 | 15 | 17 | 19 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /metadata/images/executor-lvl2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | executor-lvl2 6 | 7 | 8 | 10 | 11 | 13 | 15 | 17 | 19 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /metadata/images/executor-lvl4.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | executor-lvl4 6 | 7 | 8 | 10 | 11 | 13 | 15 | 17 | 19 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /metadata/images/executor.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | executor 6 | 7 | 8 | 10 | 11 | 13 | 15 | 17 | 19 | 20 | 22 | 24 | 25 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /metadata/images/exhaust.svg: -------------------------------------------------------------------------------- 1 | exhaust -------------------------------------------------------------------------------- /metadata/images/exit-bottom.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /metadata/images/exit-left.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /metadata/images/exit-right.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /metadata/images/exit-top.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /metadata/images/extension.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 64 | 69 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /metadata/images/factory-border.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /metadata/images/factory-lvl0.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /metadata/images/factory-lvl1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /metadata/images/factory-lvl2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /metadata/images/factory-lvl3.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /metadata/images/factory-lvl4.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /metadata/images/factory-lvl5.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /metadata/images/factory.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /metadata/images/flag-secondary.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 37 | 39 | 41 | 42 | 44 | image/svg+xml 45 | 47 | 48 | 49 | 50 | 51 | 54 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /metadata/images/flag.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 37 | 39 | 41 | 42 | 44 | image/svg+xml 45 | 47 | 48 | 49 | 50 | 51 | 54 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /metadata/images/flare1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/flare1.png -------------------------------------------------------------------------------- /metadata/images/flare2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/flare2.png -------------------------------------------------------------------------------- /metadata/images/flare3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/flare3.png -------------------------------------------------------------------------------- /metadata/images/fortify.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | Fortify 9 | 10 | 11 | 12 | 14 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /metadata/images/generate-ops.svg: -------------------------------------------------------------------------------- 1 | generate-ops -------------------------------------------------------------------------------- /metadata/images/glow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/glow.png -------------------------------------------------------------------------------- /metadata/images/ground-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/ground-mask.png -------------------------------------------------------------------------------- /metadata/images/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/ground.png -------------------------------------------------------------------------------- /metadata/images/harvest-energy.svg: -------------------------------------------------------------------------------- 1 | harvest-energy -------------------------------------------------------------------------------- /metadata/images/harvest-mineral.svg: -------------------------------------------------------------------------------- 1 | harvest-mineral -------------------------------------------------------------------------------- /metadata/images/kill.svg: -------------------------------------------------------------------------------- 1 | kill -------------------------------------------------------------------------------- /metadata/images/lab-highlight.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/lab-mineral.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/lab.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/link-border.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/link-energy.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/mass-repair.svg: -------------------------------------------------------------------------------- 1 | mass-repair -------------------------------------------------------------------------------- /metadata/images/noise1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/noise1.png -------------------------------------------------------------------------------- /metadata/images/noise2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/screeps/renderer/fd67557dd0b9481ff20bdbc81adb637553ba98e5/metadata/images/noise2.png -------------------------------------------------------------------------------- /metadata/images/nuke.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 11 | 12 | -------------------------------------------------------------------------------- /metadata/images/nuker-border.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/operate-controller.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | OPERATE_CONTROLLER 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /metadata/images/operate-extension.svg: -------------------------------------------------------------------------------- 1 | operate-extension -------------------------------------------------------------------------------- /metadata/images/operate-lab.svg: -------------------------------------------------------------------------------- 1 | operate-lab -------------------------------------------------------------------------------- /metadata/images/operate-observer.svg: -------------------------------------------------------------------------------- 1 | operate-observer -------------------------------------------------------------------------------- /metadata/images/operate-power.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | Operate_power_spawn 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /metadata/images/operate-spawn.svg: -------------------------------------------------------------------------------- 1 | operate-spawn -------------------------------------------------------------------------------- /metadata/images/operate-storage.svg: -------------------------------------------------------------------------------- 1 | operate-storage -------------------------------------------------------------------------------- /metadata/images/operate-terminal.svg: -------------------------------------------------------------------------------- 1 | operate-terminal -------------------------------------------------------------------------------- /metadata/images/operate-tower.svg: -------------------------------------------------------------------------------- 1 | operate-tower -------------------------------------------------------------------------------- /metadata/images/operator-lvl0.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | operator-lvl1 6 | 7 | 8 | 9 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /metadata/images/operator-lvl1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | operator-lvl1 6 | 7 | 8 | 9 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /metadata/images/operator-lvl2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | operator-lvl2 6 | 7 | 8 | 9 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /metadata/images/operator-lvl3.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | operator-lvl3 6 | 7 | 8 | 9 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /metadata/images/operator-lvl4.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | operator-lvl4 6 | 7 | 8 | 9 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /metadata/images/operator.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | operator 6 | 7 | 8 | 9 | 11 | 12 | 13 | 15 | 17 | 19 | 21 | 22 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /metadata/images/powerBank.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/punch.svg: -------------------------------------------------------------------------------- 1 | punch -------------------------------------------------------------------------------- /metadata/images/rampart.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /metadata/images/reflect.svg: -------------------------------------------------------------------------------- 1 | reflect -------------------------------------------------------------------------------- /metadata/images/regen-mineral.svg: -------------------------------------------------------------------------------- 1 | extend-mineral -------------------------------------------------------------------------------- /metadata/images/regen-source.svg: -------------------------------------------------------------------------------- 1 | extend-source -------------------------------------------------------------------------------- /metadata/images/reinforce.svg: -------------------------------------------------------------------------------- 1 | reinforce -------------------------------------------------------------------------------- /metadata/images/remote-transfer.svg: -------------------------------------------------------------------------------- 1 | remote-transfer -------------------------------------------------------------------------------- /metadata/images/renew.svg: -------------------------------------------------------------------------------- 1 | renew -------------------------------------------------------------------------------- /metadata/images/ruin.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /metadata/images/shield.svg: -------------------------------------------------------------------------------- 1 | shield -------------------------------------------------------------------------------- /metadata/images/sight.svg: -------------------------------------------------------------------------------- 1 | sight -------------------------------------------------------------------------------- /metadata/images/snipe.svg: -------------------------------------------------------------------------------- 1 | snipe -------------------------------------------------------------------------------- /metadata/images/storage-border.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/storage.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /metadata/images/summon.svg: -------------------------------------------------------------------------------- 1 | summon -------------------------------------------------------------------------------- /metadata/images/terminal-arrows.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/terminal-border.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/images/terminal-highlight.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /metadata/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@screeps/renderer-metadata", 3 | "version": "1.5.18", 4 | "description": "This library contains the renderer engine used in Screeps game.", 5 | "main": "dist/renderer-metadata.js", 6 | "files": [ 7 | "dist", 8 | "images" 9 | ], 10 | "author": "Fedor Shubin ", 11 | "license": "ISC", 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/screeps/renderer.git" 15 | }, 16 | "scripts": { 17 | "build": "webpack --progress --colors", 18 | "dev": "webpack --progress --colors --watch", 19 | "dev-no-progress": "webpack --colors --watch", 20 | "prepublish": "npm run build" 21 | }, 22 | "devDependencies": { 23 | "@screeps/common": "^2.15.4", 24 | "eslint": "^4.9.0", 25 | "eslint-config-airbnb-base": "^12.1.0", 26 | "eslint-loader": "^2.1.0", 27 | "eslint-plugin-import": "^2.14.0", 28 | "webpack": "^4.17.1", 29 | "webpack-cli": "^3.1.0" 30 | }, 31 | "dependencies": {} 32 | } 33 | -------------------------------------------------------------------------------- /metadata/src/action-templates/appear.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | export default (duration = { $processorParam: 'tickDuration' }) => ({ 6 | action: 'FadeIn', 7 | params: [duration], 8 | }); 9 | -------------------------------------------------------------------------------- /metadata/src/action-templates/blinking.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | export default (fromAlpha, toAlpha, toDuration, fromDuration) => ({ 6 | action: 'Sequence', 7 | params: [[ 8 | { 9 | action: 'AlphaTo', 10 | params: [fromAlpha, 0], 11 | }, 12 | { 13 | action: 'Repeat', 14 | params: [{ 15 | action: 'Sequence', 16 | params: [ 17 | [ 18 | { 19 | action: 'AlphaTo', 20 | params: [toAlpha, toDuration], 21 | }, 22 | { 23 | action: 'AlphaTo', 24 | params: [fromAlpha, fromDuration], 25 | }, 26 | ], 27 | ], 28 | }], 29 | }, 30 | ]], 31 | }); 32 | -------------------------------------------------------------------------------- /metadata/src/action-templates/displayName.js: -------------------------------------------------------------------------------- 1 | export default (type, additionalWhen) => ({ 2 | type: 'text', 3 | once: true, 4 | layer: 'effects', 5 | when: (params) => { 6 | const { 7 | calcs: { isOwner }, 8 | stateExtra: { gameData: { showEnemyNames, showMyNames } }, 9 | } = params; 10 | return ((isOwner && showMyNames[type]) || (!isOwner && showEnemyNames[type])) && 11 | (!additionalWhen || additionalWhen(params)); 12 | }, 13 | payload: { 14 | text: { $calc: 'displayName' }, 15 | style: { 16 | align: 'center', 17 | fill: { $calc: 'playerColorHex' }, 18 | fontFamily: 'Roboto, sans-serif', 19 | fontSize: 55, 20 | stroke: '#111', 21 | strokeThickness: 15, 22 | }, 23 | anchor: { 24 | x: 0.5, 25 | y: 1.7, 26 | }, 27 | }, 28 | }); 29 | -------------------------------------------------------------------------------- /metadata/src/action-templates/flickering.js: -------------------------------------------------------------------------------- 1 | export default (alpha1, alpha2, alpha3, alpha4) => ({ 2 | action: 'Spawn', 3 | params: [[ 4 | { 5 | action: 'Repeat', 6 | params: [{ 7 | action: 'Sequence', 8 | params: [[ 9 | { 10 | action: 'ScaleTo', 11 | params: [ 12 | { $rel: 'scale.x', koef: 1.2 }, 13 | { $rel: 'scale.y', koef: 1.2 }, 14 | 1, 15 | ], 16 | }, 17 | { 18 | action: 'ScaleTo', 19 | params: [ 20 | { $rel: 'scale.x' }, 21 | { $rel: 'scale.y' }, 22 | 1, 23 | ], 24 | }, 25 | ]], 26 | }], 27 | }, 28 | { 29 | action: 'Repeat', 30 | params: [{ 31 | action: 'Sequence', 32 | params: [[ 33 | { 34 | action: 'AlphaTo', 35 | params: [alpha1, 0.1], 36 | }, 37 | { 38 | action: 'AlphaTo', 39 | params: [alpha2, 0.2], 40 | }, 41 | { 42 | action: 'DelayTime', 43 | params: [{ $random: 2 }], 44 | }, 45 | { 46 | action: 'AlphaTo', 47 | params: [alpha3, 0.2], 48 | }, 49 | { 50 | action: 'AlphaTo', 51 | params: [alpha4, 2.8], 52 | }, 53 | ]], 54 | }], 55 | }, 56 | ]], 57 | }); 58 | -------------------------------------------------------------------------------- /metadata/src/action-templates/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 23/04/2017. 3 | */ 4 | 5 | import appear from './appear'; 6 | import blinking from './blinking'; 7 | import displayName from './displayName'; 8 | import flickering from './flickering'; 9 | 10 | export default { 11 | appear, 12 | blinking, 13 | displayName, 14 | flickering, 15 | }; 16 | 17 | export { 18 | appear, 19 | blinking, 20 | displayName, 21 | flickering, 22 | }; 23 | -------------------------------------------------------------------------------- /metadata/src/calculation-templates/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 23/04/2017. 3 | */ 4 | 5 | import resourceTotal from './resourceTotal'; 6 | 7 | export default { 8 | resourceTotal, 9 | }; 10 | 11 | export { 12 | resourceTotal, 13 | }; 14 | -------------------------------------------------------------------------------- /metadata/src/calculation-templates/resourceTotal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/03/2017. 3 | */ 4 | 5 | export default () => { 6 | return ({ 7 | id: 'resourcesTotal', 8 | func: ({ state }) => _.reduce(state.store, (sum, cur) => cur + sum, 0) 9 | }); 10 | }; 11 | -------------------------------------------------------------------------------- /metadata/src/objects/constructedWall.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 23/04/2017. 3 | */ 4 | 5 | import { blinking } from '../action-templates'; 6 | 7 | export default { 8 | texture: 'constructedWall', 9 | processors: [ 10 | { 11 | type: 'sprite', 12 | once: true, 13 | payload: { 14 | width: 100, 15 | height: 100, 16 | blendMode: 1, 17 | }, 18 | }, 19 | { 20 | type: 'draw', 21 | once: true, 22 | when: ({ state: { hits, hitsMax } }) => hits === 1 && hitsMax > 1, 23 | layer: 'effects', 24 | payload: { 25 | drawings: [ 26 | { method: 'beginFill', params: [0xFF0000] }, 27 | { 28 | method: 'drawRect', 29 | params: [-50, -50, 100, 100], 30 | }, 31 | { method: 'endFill' }, 32 | ], 33 | blendMode: 1, 34 | }, 35 | actions: [blinking(0, 0.2, 0.3, 1.5)], 36 | }, 37 | ], 38 | zIndex: 0, 39 | }; 40 | -------------------------------------------------------------------------------- /metadata/src/objects/constructionSite.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 23/04/2017. 3 | */ 4 | 5 | import { blinking } from '../action-templates'; 6 | 7 | export default { 8 | texture: 'constructionSite', 9 | processors: [ 10 | { 11 | id: 'siteProgress', 12 | type: 'siteProgress', 13 | layer: 'effects', 14 | props: ['progress', 'progressTotal'], 15 | payload: { 16 | color: { $calc: 'playerColor' }, 17 | radius: 20, 18 | lineWidth: 10, 19 | progress: { $state: 'progress' }, 20 | progressTotal: { $state: 'progressTotal' }, 21 | }, 22 | actions: [blinking(0.8, 0.3, 1, 1)], 23 | }, 24 | ], 25 | disappearProcessor: { type: 'disappear' }, 26 | zIndex: 18, 27 | }; 28 | -------------------------------------------------------------------------------- /metadata/src/objects/energy.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 23/04/2017. 3 | */ 4 | 5 | export default { 6 | processors: [ 7 | { 8 | type: 'resourceCircle', 9 | }, 10 | { 11 | type: 'resourceCircle', 12 | layer: 'lighting', 13 | payload: { 14 | tint: 0xFFFFFF, 15 | }, 16 | }, 17 | ], 18 | zIndex: 1, 19 | }; 20 | -------------------------------------------------------------------------------- /metadata/src/objects/extractor.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 04/09/2017. 3 | */ 4 | export default { 5 | processors: [ 6 | { 7 | id: 'main', 8 | type: 'sprite', 9 | once: 'true', 10 | payload: { 11 | texture: 'extractor', 12 | width: 200, 13 | tint: { $calc: 'playerColor' }, 14 | }, 15 | }, 16 | { 17 | type: 'runAction', 18 | once: true, 19 | when: ({ state: { cooldown } }) => cooldown > 0, 20 | until: ({ state: { cooldown } }) => !cooldown || cooldown <= 0, 21 | payload: { 22 | id: 'main', 23 | }, 24 | actions: [{ 25 | action: 'Repeat', 26 | params: [{ 27 | action: 'RotateBy', 28 | params: [2 * Math.PI, 4], 29 | }], 30 | }], 31 | }, 32 | ], 33 | zIndex: 0, 34 | }; 35 | -------------------------------------------------------------------------------- /metadata/src/objects/rampart.metadata.js: -------------------------------------------------------------------------------- 1 | export default { 2 | calculations: [ 3 | { 4 | id: 'rampartColor', 5 | once: true, 6 | func: ({ state: { user }, stateExtra: { gameData: { player } } }) => 7 | (user === player ? 0x44FF44 : 0xFF4444), 8 | }, 9 | ], 10 | processors: [ 11 | { 12 | type: 'sprite', 13 | layer: 'effects', 14 | props: ['isPublic'], 15 | payload: { 16 | texture: 'rampart', 17 | width: 100, 18 | height: 100, 19 | alpha: 0.5, 20 | tint: { $calc: 'rampartColor' }, 21 | }, 22 | shouldRun: ({ state: { isPublic } }) => !!isPublic, 23 | }, 24 | ], 25 | zIndex: 0, 26 | }; 27 | -------------------------------------------------------------------------------- /metadata/src/objects/road.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 17/08/2017. 3 | */ 4 | 5 | export default { 6 | processors: [ 7 | { 8 | type: 'road', 9 | layer: 'objects', 10 | }, 11 | ], 12 | disappearProcessor: { type: 'disappear' }, 13 | zIndex: -1 14 | }; 15 | -------------------------------------------------------------------------------- /metadata/src/objects/ruin.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 23/04/2017. 3 | */ 4 | 5 | import { resourceTotal } from '../calculation-templates'; 6 | 7 | export default { 8 | calculations: [ 9 | resourceTotal(), 10 | { 11 | id: 'resourceColor', 12 | func: ({ calcs: { resourcesTotal, playerColor } }) => 13 | (resourcesTotal > 0 ? playerColor : 0x000000), 14 | }, 15 | { 16 | id: 'decayAlpha', 17 | func: ({ state: { decayTime, destroyTime }, stateExtra: { gameTime } }) => 18 | 1 - ((gameTime - destroyTime) / (decayTime - destroyTime)), 19 | }, 20 | ], 21 | processors: [ 22 | { 23 | type: 'sprite', 24 | id: 'ruin', 25 | once: true, 26 | payload: { 27 | texture: 'ruin', 28 | width: 100, 29 | height: 100, 30 | blendMode: 1, 31 | alpha: { $calc: 'decayAlpha' }, 32 | }, 33 | }, 34 | { 35 | type: 'sprite', 36 | props: ['resourceColor'], 37 | payload: { 38 | texture: 'tombstone-resource', 39 | tint: { $calc: 'resourceColor' }, 40 | alpha: 0.8, 41 | width: 100, 42 | height: 100, 43 | }, 44 | }, 45 | { 46 | type: 'sprite', 47 | layer: 'lighting', 48 | once: true, 49 | payload: { 50 | texture: 'tombstone-resource', 51 | width: 100, 52 | height: 100, 53 | }, 54 | }, 55 | ], 56 | actions: [ 57 | { 58 | targetId: 'ruin', 59 | actions: [ 60 | { 61 | action: 'AlphaTo', 62 | params: [ 63 | { $calc: 'decayAlpha' }, 64 | 0, 65 | ], 66 | }, 67 | ], 68 | }, 69 | ], 70 | zIndex: 5, 71 | }; 72 | -------------------------------------------------------------------------------- /metadata/src/objects/tbd.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 19/04/2017. 3 | */ 4 | 5 | export default { 6 | texture: 'tbd', 7 | processors: [ 8 | { 9 | type: 'sprite', 10 | once: true, 11 | }, 12 | ], 13 | }; 14 | -------------------------------------------------------------------------------- /metadata/src/objects/tombstone.metadata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 23/04/2017. 3 | */ 4 | 5 | import { resourceTotal } from '../calculation-templates'; 6 | 7 | export default { 8 | calculations: [ 9 | resourceTotal(), 10 | { 11 | id: 'resourceColor', 12 | func: ({ calcs: { resourcesTotal, playerColor } }) => 13 | (resourcesTotal > 0 ? playerColor : 0x000000), 14 | }, 15 | { 16 | id: 'decayAlpha', 17 | func: ({ state: { decayTime, deathTime }, stateExtra: { gameTime } }) => 18 | 1 - ((gameTime - deathTime) / (decayTime - deathTime)), 19 | }, 20 | ], 21 | processors: [ 22 | { 23 | type: 'sprite', 24 | id: 'tombstone-border', 25 | once: true, 26 | payload: { 27 | texture: 'tombstone-border', 28 | width: 100, 29 | height: 100, 30 | blendMode: 1, 31 | alpha: { $calc: 'decayAlpha' }, 32 | }, 33 | }, 34 | { 35 | type: 'sprite', 36 | props: ['resourceColor'], 37 | payload: { 38 | texture: 'tombstone-resource', 39 | tint: { $calc: 'resourceColor' }, 40 | alpha: 0.8, 41 | width: 100, 42 | height: 100, 43 | }, 44 | }, 45 | { 46 | type: 'sprite', 47 | layer: 'lighting', 48 | once: true, 49 | payload: { 50 | texture: 'tombstone-resource', 51 | width: 100, 52 | height: 100, 53 | }, 54 | }, 55 | ], 56 | actions: [ 57 | { 58 | targetId: 'tombstone-border', 59 | actions: [ 60 | { 61 | action: 'AlphaTo', 62 | params: [ 63 | { $calc: 'decayAlpha' }, 64 | 0, 65 | ], 66 | }, 67 | ], 68 | }, 69 | ], 70 | zIndex: 5, 71 | }; 72 | -------------------------------------------------------------------------------- /metadata/webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by vedi on 05/04/2017. 3 | */ 4 | 5 | require('webpack'); 6 | 7 | const config = { 8 | entry: `${__dirname}/src/index.js`, 9 | devtool: 'source-map', 10 | output: { 11 | path: `${__dirname}/dist`, 12 | filename: 'renderer-metadata.js', 13 | library: 'RENDERER_METADATA', 14 | libraryTarget: 'window', 15 | libraryExport: 'default', 16 | }, 17 | }; 18 | 19 | module.exports = config; 20 | --------------------------------------------------------------------------------