├── .gitignore ├── .vscode └── settings.json ├── Hello World.json ├── README.md ├── config ├── env.js ├── jest │ ├── cssTransform.js │ ├── fileTransform.js │ └── typescriptTransform.js ├── paths.js ├── polyfills.js ├── webpack.config.dev.js ├── webpack.config.prod.js └── webpackDevServer.config.js ├── images.d.ts ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json ├── react-desktop.d.ts ├── react-desktop └── macOs.d.ts ├── redux-persist-immutable.d.ts ├── redux-undo.d.ts ├── scripts ├── build.js ├── start.js └── test.js ├── src ├── App.test.tsx ├── App.tsx ├── constants │ ├── block.tsx │ ├── grid.tsx │ ├── index.tsx │ └── layer.tsx ├── container │ ├── block.tsx │ ├── grid.tsx │ ├── layer.tsx │ └── utils.tsx ├── index.tsx ├── logo.svg ├── mixins │ └── templates.tsx ├── present │ └── gridModel.tsx ├── redux │ ├── actions │ │ ├── block.tsx │ │ ├── index.tsx │ │ └── layer.tsx │ ├── reducers │ │ ├── block.tsx │ │ ├── index.tsx │ │ └── layer.tsx │ └── store │ │ └── index.tsx ├── registerServiceWorker.ts ├── style │ ├── App.less │ ├── block.less │ ├── canvas.less │ ├── font.less │ ├── index.css │ ├── layer.less │ └── util.less ├── types │ ├── block.tsx │ ├── grid.tsx │ ├── index.tsx │ └── layer.tsx └── utils │ ├── createMatrix.ts │ └── saveFile.ts ├── tsconfig.json ├── tsconfig.prod.json ├── tsconfig.test.json └── tslint.json /.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 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.tabSize": 2, 3 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 2d游戏地图编辑器 2 | 3 | 去年(2018)在和小伙伴们开发一款横版滚轴平台游戏,用到了 `Tiled Map` 编辑器,但在使用的过程中遇到了很多坑,用过它的人都知道。 4 | 5 | Tiled 功能很强大,但我需要的功能好像不是很多,是否能造个轮子?来简单快速的进行地图编辑 6 | 7 | ## 导入demo 8 | 9 | 在左上角的导入按钮中,导入根目录中的 `Hello World.json` 地图资源文件,得益于 图片被转成了 `base 64` 字符串,你可以快捷的预览到地图效果,而不需要下载图片原资源 10 | ## 导出demo 11 | 12 | 现可以导出两种类型,一种编辑器可以解析的地图文件,一种游戏引擎解析的地图文件,点击左上角导出,可选择导出类型 13 | 14 | ## 游戏内应用 15 | 我写了一个简单的基于白鹭引擎的地图解析demo,你可以去这看它 [egret Map](https://github.com/checkmind/Map-editer-parse) 16 | 地图json格式为: 17 | ``` typescript 18 | 19 | export interface matrixItem { 20 | src: string | undefined; 21 | width: number; 22 | row: number; 23 | col: number; 24 | height: number; 25 | name: string; 26 | extra?: Array 27 | } 28 | 29 | export interface LayerItem { 30 | // 图层id 31 | id: number, 32 | // 图层名称 33 | name: string, 34 | // 是否显示 35 | show: boolean, 36 | matrix: Array> 37 | } 38 | export interface layer { 39 | layers: Array; 40 | // 表格横轴个数 41 | tableRow: number; 42 | // 表格纵轴个数 43 | tableCol: number; 44 | // 单元格宽度和高度 45 | boxWidth: number; 46 | boxHeight: number; 47 | name: string 48 | } 49 | ``` 50 | 51 | ## 编辑器 52 | 53 | ### 新建项目 54 | 55 | ![新建项目](https://i.loli.net/2019/04/21/5cbc45122f27d.png) 56 | 57 | ### 功能简介 58 | 59 | ![新建项目](https://i.loli.net/2019/04/21/5cbc45125c508.png) 60 | 61 | ### 制作地图 62 | 63 | ![新建项目](https://i.loli.net/2019/04/21/5cbc4512df1eb.png) 64 | 65 | ### 改变图块属性 66 | 67 | 每当图块改变时,之前已画在地图的图块不会随之改变,考虑到图块在使用时会有不同属性的需求,图块每次改变都是新的! 68 | 69 | ![新建项目](https://i.loli.net/2019/04/21/5cbc4512e7cbe.png) 70 | 71 | ### 关闭辅助线 72 | 73 | ![新建项目](https://i.loli.net/2019/04/21/5cbc45130c064.png) 74 | 75 | ## 现有功能 76 | 77 | - 图层:新建、上移、下移、重命名、删除 78 | - 图块:新建、删除、编辑大小、添加额外属性 79 | - 工具:橡皮擦、导入、导出、撤销、取消撤销、全局属性 80 | - 网格:是否显示网格 81 | 82 | ## TODO 83 | 没啥TODO了 84 | -------------------------------------------------------------------------------- /config/env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const paths = require('./paths'); 6 | 7 | // Make sure that including paths.js after env.js will read .env variables. 8 | delete require.cache[require.resolve('./paths')]; 9 | 10 | const NODE_ENV = process.env.NODE_ENV; 11 | if (!NODE_ENV) { 12 | throw new Error( 13 | 'The NODE_ENV environment variable is required but was not specified.' 14 | ); 15 | } 16 | 17 | // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use 18 | var dotenvFiles = [ 19 | `${paths.dotenv}.${NODE_ENV}.local`, 20 | `${paths.dotenv}.${NODE_ENV}`, 21 | // Don't include `.env.local` for `test` environment 22 | // since normally you expect tests to produce the same 23 | // results for everyone 24 | NODE_ENV !== 'test' && `${paths.dotenv}.local`, 25 | paths.dotenv, 26 | ].filter(Boolean); 27 | 28 | // Load environment variables from .env* files. Suppress warnings using silent 29 | // if this file is missing. dotenv will never modify any environment variables 30 | // that have already been set. Variable expansion is supported in .env files. 31 | // https://github.com/motdotla/dotenv 32 | // https://github.com/motdotla/dotenv-expand 33 | dotenvFiles.forEach(dotenvFile => { 34 | if (fs.existsSync(dotenvFile)) { 35 | require('dotenv-expand')( 36 | require('dotenv').config({ 37 | path: dotenvFile, 38 | }) 39 | ); 40 | } 41 | }); 42 | 43 | // We support resolving modules according to `NODE_PATH`. 44 | // This lets you use absolute paths in imports inside large monorepos: 45 | // https://github.com/facebookincubator/create-react-app/issues/253. 46 | // It works similar to `NODE_PATH` in Node itself: 47 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders 48 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. 49 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. 50 | // https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 51 | // We also resolve them to make sure all tools using them work consistently. 52 | const appDirectory = fs.realpathSync(process.cwd()); 53 | process.env.NODE_PATH = (process.env.NODE_PATH || '') 54 | .split(path.delimiter) 55 | .filter(folder => folder && !path.isAbsolute(folder)) 56 | .map(folder => path.resolve(appDirectory, folder)) 57 | .join(path.delimiter); 58 | 59 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be 60 | // injected into the application via DefinePlugin in Webpack configuration. 61 | const REACT_APP = /^REACT_APP_/i; 62 | 63 | function getClientEnvironment(publicUrl) { 64 | const raw = Object.keys(process.env) 65 | .filter(key => REACT_APP.test(key)) 66 | .reduce( 67 | (env, key) => { 68 | env[key] = process.env[key]; 69 | return env; 70 | }, 71 | { 72 | // Useful for determining whether we’re running in production mode. 73 | // Most importantly, it switches React into the correct mode. 74 | NODE_ENV: process.env.NODE_ENV || 'development', 75 | // Useful for resolving the correct path to static assets in `public`. 76 | // For example, . 77 | // This should only be used as an escape hatch. Normally you would put 78 | // images into the `src` and `import` them in code to get their paths. 79 | PUBLIC_URL: publicUrl, 80 | } 81 | ); 82 | // Stringify all values so we can feed into Webpack DefinePlugin 83 | const stringified = { 84 | 'process.env': Object.keys(raw).reduce( 85 | (env, key) => { 86 | env[key] = JSON.stringify(raw[key]); 87 | return env; 88 | }, 89 | {} 90 | ), 91 | }; 92 | 93 | return { raw, stringified }; 94 | } 95 | 96 | module.exports = getClientEnvironment; 97 | -------------------------------------------------------------------------------- /config/jest/cssTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // This is a custom Jest transformer turning style imports into empty objects. 4 | // http://facebook.github.io/jest/docs/en/webpack.html 5 | 6 | module.exports = { 7 | process() { 8 | return 'module.exports = {};'; 9 | }, 10 | getCacheKey() { 11 | // The output is always the same. 12 | return 'cssTransform'; 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /config/jest/fileTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | // This is a custom Jest transformer turning file imports into filenames. 6 | // http://facebook.github.io/jest/docs/en/webpack.html 7 | 8 | module.exports = { 9 | process(src, filename) { 10 | return `module.exports = ${JSON.stringify(path.basename(filename))};`; 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /config/jest/typescriptTransform.js: -------------------------------------------------------------------------------- 1 | // Copyright 2004-present Facebook. All Rights Reserved. 2 | 3 | 'use strict'; 4 | 5 | const tsJestPreprocessor = require('ts-jest/preprocessor'); 6 | 7 | module.exports = tsJestPreprocessor; 8 | -------------------------------------------------------------------------------- /config/paths.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const fs = require('fs'); 5 | const url = require('url'); 6 | 7 | // Make sure any symlinks in the project folder are resolved: 8 | // https://github.com/facebookincubator/create-react-app/issues/637 9 | const appDirectory = fs.realpathSync(process.cwd()); 10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath); 11 | 12 | const envPublicUrl = process.env.PUBLIC_URL; 13 | 14 | function ensureSlash(path, needsSlash) { 15 | const hasSlash = path.endsWith('/'); 16 | if (hasSlash && !needsSlash) { 17 | return path.substr(path, path.length - 1); 18 | } else if (!hasSlash && needsSlash) { 19 | return `${path}/`; 20 | } else { 21 | return path; 22 | } 23 | } 24 | 25 | const getPublicUrl = appPackageJson => 26 | envPublicUrl || require(appPackageJson).homepage; 27 | 28 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer 29 | // "public path" at which the app is served. 30 | // Webpack needs to know it to put the right