From 45bab1516e4d08e3382be80b722f6e173d23f0a5 Mon Sep 17 00:00:00 2001 From: Kevin Attfield Date: Tue, 21 Mar 2023 21:29:50 -0700 Subject: [PATCH 1/5] Add prettier to the project This is the suggested path from the Angular team https://github.com/angular-eslint/angular-eslint/blob/main/docs/FORMATTING_RULES.md This adds prettier with a basic config. No special options and some ignore directories. It adds eslint-config-prettier to disable certain eslint rules that interfere with prettier. --- frontend/.eslintrc.json | 3 ++- frontend/.prettierignore | 5 +++++ frontend/.prettierrc.json | 1 + frontend/package-lock.json | 12 ++++++++++++ frontend/package.json | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 frontend/.prettierignore create mode 100644 frontend/.prettierrc.json diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index 1e4624e6..f0326dbc 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -43,7 +43,8 @@ "*.html" ], "extends": [ - "plugin:@angular-eslint/template/recommended" + "plugin:@angular-eslint/template/recommended", + "prettier" ], "rules": {} } diff --git a/frontend/.prettierignore b/frontend/.prettierignore new file mode 100644 index 00000000..5f67c446 --- /dev/null +++ b/frontend/.prettierignore @@ -0,0 +1,5 @@ +.angular +dist +out-tsc + +assets diff --git a/frontend/.prettierrc.json b/frontend/.prettierrc.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/frontend/.prettierrc.json @@ -0,0 +1 @@ +{} diff --git a/frontend/package-lock.json b/frontend/package-lock.json index a9f35e85..ee12266f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -6117,6 +6117,12 @@ } } }, + "eslint-config-prettier": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz", + "integrity": "sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA==", + "dev": true + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -10683,6 +10689,12 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.6.tgz", + "integrity": "sha512-mtuzdiBbHwPEgl7NxWlqOkithPyp4VN93V7VeHVWBF+ad3I5avc0RVDT4oImXQy9H/AqxA2NSQH8pSxHW6FYbQ==", + "dev": true + }, "pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 2b99cdf0..2fa2b0f4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -63,6 +63,7 @@ "@typescript-eslint/eslint-plugin": "5.27.1", "@typescript-eslint/parser": "5.27.1", "eslint": "^8.17.0", + "eslint-config-prettier": "^8.8.0", "jasmine-core": "^3.10.1", "jasmine-spec-reporter": "^7.0.0", "karma": "^6.3.9", @@ -71,6 +72,7 @@ "karma-jasmine": "^4.0.1", "karma-jasmine-html-reporter": "^1.7.0", "ngx-i18nsupport": "^0.17.1", + "prettier": "^2.8.6", "protractor": "~7.0.0", "ts-node": "^10.4.0", "typescript": "~4.5.4" From 42914822f8f4a480c9e1e36a252fecf5a727667f Mon Sep 17 00:00:00 2001 From: Kevin Attfield Date: Tue, 21 Mar 2023 22:08:17 -0700 Subject: [PATCH 2/5] Add Husky and lint-staged --- frontend/.husky/pre-commit | 3 + frontend/.lintstagedrc | 4 + frontend/package-lock.json | 391 +++++++++++++++++++++++++++++++++++++ frontend/package.json | 4 + 4 files changed, 402 insertions(+) create mode 100755 frontend/.husky/pre-commit create mode 100644 frontend/.lintstagedrc diff --git a/frontend/.husky/pre-commit b/frontend/.husky/pre-commit new file mode 100755 index 00000000..98737d4f --- /dev/null +++ b/frontend/.husky/pre-commit @@ -0,0 +1,3 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" +cd ./frontend && npx lint-staged diff --git a/frontend/.lintstagedrc b/frontend/.lintstagedrc new file mode 100644 index 00000000..45d0535f --- /dev/null +++ b/frontend/.lintstagedrc @@ -0,0 +1,4 @@ +{ + "*.{html,ts}": ["ng-lint-staged lint --fix --"], + "*.{css,html,js,json,ts,yaml,yml}": ["npx prettier --write --"] +} diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ee12266f..54b932d8 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -3987,6 +3987,12 @@ "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", "dev": true }, + "astral-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", + "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", + "dev": true + }, "async": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", @@ -4573,6 +4579,50 @@ "integrity": "sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==", "dev": true }, + "cli-truncate": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-3.1.0.tgz", + "integrity": "sha512-wfOBkjXteqSnI59oPcJkcPl/ZmwvMMOj340qUIY1SKZCv0B9Cf4D4fAucRkIKQmsIuYK3x1rrgU7MeGRruiuiA==", + "dev": true, + "requires": { + "slice-ansi": "^5.0.0", + "string-width": "^5.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true + }, + "emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true + }, + "string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "requires": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + } + }, + "strip-ansi": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.0.1.tgz", + "integrity": "sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==", + "dev": true, + "requires": { + "ansi-regex": "^6.0.1" + } + } + } + }, "cli-width": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-3.0.0.tgz", @@ -5498,6 +5548,12 @@ "resolved": "https://registry.npmjs.org/earcut/-/earcut-2.2.3.tgz", "integrity": "sha512-iRDI1QeCQIhMCZk48DRDMVgQSSBDmbzzNhnxIo+pwx3swkfjMh6vh0nWLq1NdvGHLKH6wIrAM3vQWeTj6qeoug==" }, + "eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -7088,6 +7144,12 @@ "ms": "^2.0.0" } }, + "husky": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", + "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "dev": true + }, "iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -8207,12 +8269,239 @@ "immediate": "~3.0.5" } }, + "lilconfig": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", + "integrity": "sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==", + "dev": true + }, "lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", "dev": true }, + "lint-staged": { + "version": "13.2.0", + "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-13.2.0.tgz", + "integrity": "sha512-GbyK5iWinax5Dfw5obm2g2ccUiZXNGtAS4mCbJ0Lv4rq6iEtfBSjOYdcbOtAIFtM114t0vdpViDDetjVTSd8Vw==", + "dev": true, + "requires": { + "chalk": "5.2.0", + "cli-truncate": "^3.1.0", + "commander": "^10.0.0", + "debug": "^4.3.4", + "execa": "^7.0.0", + "lilconfig": "2.1.0", + "listr2": "^5.0.7", + "micromatch": "^4.0.5", + "normalize-path": "^3.0.0", + "object-inspect": "^1.12.3", + "pidtree": "^0.6.0", + "string-argv": "^0.3.1", + "yaml": "^2.2.1" + }, + "dependencies": { + "chalk": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz", + "integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==", + "dev": true + }, + "commander": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz", + "integrity": "sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA==", + "dev": true + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "execa": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-7.1.1.tgz", + "integrity": "sha512-wH0eMf/UXckdUYnO21+HDztteVv05rq2GXksxT4fCGeHkBhw1DROXh40wcjMcRqDOWE7iPJ4n3M7e2+YFP+76Q==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.1", + "human-signals": "^4.3.0", + "is-stream": "^3.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" + } + }, + "human-signals": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz", + "integrity": "sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==", + "dev": true + }, + "is-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", + "dev": true + }, + "micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "requires": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + } + }, + "mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", + "dev": true + }, + "npm-run-path": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", + "dev": true, + "requires": { + "path-key": "^4.0.0" + } + }, + "object-inspect": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", + "dev": true + }, + "onetime": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", + "dev": true, + "requires": { + "mimic-fn": "^4.0.0" + } + }, + "path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "dev": true + }, + "picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true + }, + "signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true + }, + "strip-final-newline": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", + "dev": true + }, + "yaml": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.1.tgz", + "integrity": "sha512-e0WHiYql7+9wr4cWMx3TVQrNwejKaEe7/rHNmQmqRjazfOP5W8PB6Jpebb5o6fIapbz9o9+2ipcaTM2ZwDI6lw==", + "dev": true + } + } + }, + "listr2": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/listr2/-/listr2-5.0.8.tgz", + "integrity": "sha512-mC73LitKHj9w6v30nLNGPetZIlfpUniNSsxxrbaPcWOjDb92SHPzJPi/t+v1YC/lxKz/AJ9egOjww0qUuFxBpA==", + "dev": true, + "requires": { + "cli-truncate": "^2.1.0", + "colorette": "^2.0.19", + "log-update": "^4.0.0", + "p-map": "^4.0.0", + "rfdc": "^1.3.0", + "rxjs": "^7.8.0", + "through": "^2.3.8", + "wrap-ansi": "^7.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "cli-truncate": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz", + "integrity": "sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==", + "dev": true, + "requires": { + "slice-ansi": "^3.0.0", + "string-width": "^4.2.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "colorette": { + "version": "2.0.19", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.19.tgz", + "integrity": "sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==", + "dev": true + }, + "rxjs": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz", + "integrity": "sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==", + "dev": true, + "requires": { + "tslib": "^2.1.0" + } + }, + "slice-ansi": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz", + "integrity": "sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "astral-regex": "^2.0.0", + "is-fullwidth-code-point": "^3.0.0" + } + } + } + }, "loader-runner": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.2.0.tgz", @@ -8312,6 +8601,66 @@ } } }, + "log-update": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/log-update/-/log-update-4.0.0.tgz", + "integrity": "sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==", + "dev": true, + "requires": { + "ansi-escapes": "^4.3.0", + "cli-cursor": "^3.1.0", + "slice-ansi": "^4.0.0", + "wrap-ansi": "^6.2.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "slice-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", + "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "astral-regex": "^2.0.0", + "is-fullwidth-code-point": "^3.0.0" + } + }, + "wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + } + } + } + }, "log4js": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.3.0.tgz", @@ -8681,6 +9030,12 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "ng-lint-staged": { + "version": "12.0.4", + "resolved": "https://registry.npmjs.org/ng-lint-staged/-/ng-lint-staged-12.0.4.tgz", + "integrity": "sha512-h2XVNEu2fWLSBDEuPB3I2kRd4M85XulRf4Vcei9JQIUe435MwtKJBx+sEJ5IRPhEqb2551yaDCgLhto7bwCejA==", + "dev": true + }, "ng-recaptcha": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/ng-recaptcha/-/ng-recaptcha-9.0.0.tgz", @@ -9359,6 +9714,12 @@ "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", "dev": true }, + "pidtree": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.6.0.tgz", + "integrity": "sha512-eG2dWTVw5bzqGRztnHExczNxt5VGsE6OwTeCG3fdUf9KBsZzO3R5OIIIzWR+iZA0NtZ+RDVdaoE2dK1cn6jH4g==", + "dev": true + }, "pify": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", @@ -11756,6 +12117,30 @@ "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", "dev": true }, + "slice-ansi": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-5.0.0.tgz", + "integrity": "sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==", + "dev": true, + "requires": { + "ansi-styles": "^6.0.0", + "is-fullwidth-code-point": "^4.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-4.0.0.tgz", + "integrity": "sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==", + "dev": true + } + } + }, "smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", @@ -11976,6 +12361,12 @@ } } }, + "string-argv": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", + "integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==", + "dev": true + }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index 2fa2b0f4..d792d815 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -2,6 +2,7 @@ "name": "blueprintnotincluded", "version": "0.0.0", "scripts": { + "prepare": "cd ../ && husky install ./frontend/.husky", "ng": "ng", "start": "ng serve", "start:zh-Hans": "ng serve --configuration=zh-Hans", @@ -64,6 +65,7 @@ "@typescript-eslint/parser": "5.27.1", "eslint": "^8.17.0", "eslint-config-prettier": "^8.8.0", + "husky": "^8.0.3", "jasmine-core": "^3.10.1", "jasmine-spec-reporter": "^7.0.0", "karma": "^6.3.9", @@ -71,6 +73,8 @@ "karma-coverage-istanbul-reporter": "^3.0.3", "karma-jasmine": "^4.0.1", "karma-jasmine-html-reporter": "^1.7.0", + "lint-staged": "^13.2.0", + "ng-lint-staged": "^12.0.4", "ngx-i18nsupport": "^0.17.1", "prettier": "^2.8.6", "protractor": "~7.0.0", From a6769c1c58ce4e58117b6183b7d440e8983f16a1 Mon Sep 17 00:00:00 2001 From: Kevin Attfield Date: Tue, 21 Mar 2023 22:18:36 -0700 Subject: [PATCH 3/5] Prettier --fix . --- frontend/.angulardoc.json | 2 +- frontend/.eslintrc.json | 22 +- frontend/README.md | 2 + frontend/angular.json | 35 +- frontend/e2e/protractor.conf.js | 26 +- frontend/e2e/src/app.e2e-spec.ts | 18 +- frontend/e2e/src/app.po.ts | 6 +- frontend/e2e/tsconfig.json | 6 +- frontend/karma.conf.js | 28 +- frontend/proxy.conf.json | 2 +- frontend/src/app/app-routing.module.ts | 28 +- frontend/src/app/app.component.html | 3 +- frontend/src/app/app.component.spec.ts | 26 +- frontend/src/app/app.component.ts | 10 +- frontend/src/app/app.module.ts | 29 +- .../src/app/module-blueprint/common/params.ts | 7 +- .../app/module-blueprint/common/save-info.ts | 5 +- .../common/tools/build-tool.ts | 186 ++-- .../common/tools/element-report.ts | 38 +- .../common/tools/same-item-collection.ts | 41 +- .../common/tools/select-tool.ts | 179 ++-- .../app/module-blueprint/common/tools/tool.ts | 18 +- .../component-blueprint-parent.component.css | 6 +- .../component-blueprint-parent.component.html | 44 +- ...mponent-blueprint-parent.component.spec.ts | 13 +- .../component-blueprint-parent.component.ts | 381 ++++--- .../component-canvas.component.css | 2 +- .../component-canvas.component.html | 24 +- .../component-canvas.component.spec.ts | 13 +- .../component-canvas.component.ts | 592 ++++++----- .../component-menu.component.css | 2 +- .../component-menu.component.html | 70 +- .../component-menu.component.spec.ts | 13 +- .../component-menu.component.ts | 416 ++++++-- .../component-save-dialog.component.css | 4 +- .../component-save-dialog.component.html | 77 +- .../component-save-dialog.component.spec.ts | 13 +- .../component-save-dialog.component.ts | 100 +- .../dialog-about/dialog-about.component.css | 17 +- .../dialog-about/dialog-about.component.html | 82 +- .../dialog-about.component.spec.ts | 13 +- .../dialog-about/dialog-about.component.ts | 9 +- .../dialog-browse/dialog-browse.component.css | 2 +- .../dialog-browse.component.html | 147 ++- .../dialog-browse.component.spec.ts | 13 +- .../dialog-browse/dialog-browse.component.ts | 135 ++- .../dialog-export-images.component.css | 7 +- .../dialog-export-images.component.html | 68 +- .../dialog-export-images.component.spec.ts | 13 +- .../dialog-export-images.component.ts | 88 +- .../dialog-share-url.component.css | 2 +- .../dialog-share-url.component.html | 55 +- .../dialog-share-url.component.spec.ts | 13 +- .../dialog-share-url.component.ts | 28 +- .../like-widget/like-widget.component.html | 23 +- .../like-widget/like-widget.component.spec.ts | 13 +- .../like-widget/like-widget.component.ts | 20 +- .../build-tool/build-tool.component.html | 111 ++- .../build-tool/build-tool.component.spec.ts | 13 +- .../build-tool/build-tool.component.ts | 108 +- .../buildable-element-picker.component.css | 2 +- .../buildable-element-picker.component.html | 63 +- ...buildable-element-picker.component.spec.ts | 13 +- .../buildable-element-picker.component.ts | 39 +- .../cell-element-picker.component.css | 2 +- .../cell-element-picker.component.html | 52 +- .../cell-element-picker.component.spec.ts | 13 +- .../cell-element-picker.component.ts | 42 +- .../element-icon/element-icon.component.html | 130 ++- .../element-icon.component.spec.ts | 13 +- .../element-icon/element-icon.component.ts | 35 +- .../element-report-tool.component.css | 17 +- .../element-report-tool.component.html | 103 +- .../element-report-tool.component.spec.ts | 13 +- .../element-report-tool.component.ts | 23 +- .../info-input-icon.component.html | 27 +- .../info-input-icon.component.spec.ts | 13 +- .../info-input-icon.component.ts | 9 +- .../info-input/info-input.component.css | 2 +- .../info-input/info-input.component.html | 52 +- .../info-input/info-input.component.spec.ts | 13 +- .../info-input/info-input.component.ts | 55 +- .../item-collection-info.component.css | 6 +- .../item-collection-info.component.html | 89 +- .../item-collection-info.component.spec.ts | 13 +- .../item-collection-info.component.ts | 75 +- .../pipe-content/pipe-content.component.css | 4 +- .../pipe-content/pipe-content.component.html | 29 +- .../pipe-content.component.spec.ts | 13 +- .../pipe-content/pipe-content.component.ts | 25 +- .../selection-tool.component.css | 4 +- .../selection-tool.component.html | 41 +- .../selection-tool.component.spec.ts | 13 +- .../selection-tool.component.ts | 43 +- .../temperature-picker.component.css | 4 +- .../temperature-picker.component.html | 83 +- .../temperature-picker.component.spec.ts | 13 +- .../temperature-picker.component.ts | 48 +- .../temperature-scale.component.css | 17 +- .../temperature-scale.component.html | 18 +- .../temperature-scale.component.spec.ts | 13 +- .../temperature-scale.component.ts | 39 +- .../active-range-screen.component.css | 2 +- .../active-range-screen.component.html | 19 +- .../active-range-screen.component.spec.ts | 13 +- .../active-range-screen.component.ts | 40 +- .../bit-selection-screen.component.css | 2 +- .../bit-selection-screen.component.html | 15 +- .../bit-selection-screen.component.spec.ts | 13 +- .../bit-selection-screen.component.ts | 30 +- .../single-slider-screen.component.css | 2 +- .../single-slider-screen.component.html | 11 +- .../single-slider-screen.component.spec.ts | 13 +- .../single-slider-screen.component.ts | 44 +- .../threshold-switch-screen.component.css | 2 +- .../threshold-switch-screen.component.html | 27 +- .../threshold-switch-screen.component.spec.ts | 13 +- .../threshold-switch-screen.component.ts | 71 +- .../ui-screen-container.component.html | 54 +- .../ui-screen-container.component.spec.ts | 13 +- .../ui-screen-container.component.ts | 19 +- .../login-dialog/login-dialog.component.html | 37 +- .../login-dialog.component.spec.ts | 13 +- .../login-dialog/login-dialog.component.ts | 93 +- .../login-form/login-form.component.css | 4 +- .../login-form/login-form.component.html | 37 +- .../login-form/login-form.component.spec.ts | 13 +- .../login-form/login-form.component.ts | 82 +- .../register-form/register-form.component.css | 4 +- .../register-form.component.html | 81 +- .../register-form.component.spec.ts | 13 +- .../register-form/register-form.component.ts | 104 +- .../blueprint-name-validation.directive.ts | 36 +- .../directives/custom-event-manager.ts | 32 +- .../directives/draganddrop.directive.ts | 63 +- .../directives/keyboard.directive.ts | 7 +- .../directives/mousewheel.directive.ts | 20 +- .../username-validation.directive.ts | 28 +- .../module-blueprint/drawing/draw-mini-ui.ts | 73 +- .../app/module-blueprint/drawing/draw-pixi.ts | 115 ++- .../module-blueprint.module.spec.ts | 6 +- .../module-blueprint.module.ts | 251 +++-- .../pipes/add-mass-unit.pipe.spec.ts | 6 +- .../pipes/add-mass-unit.pipe.ts | 6 +- .../pipes/filter-element-gas.pipe.spec.ts | 6 +- .../pipes/filter-element-gas.pipe.ts | 12 +- .../pipes/filter-element-liquid.pipe.spec.ts | 6 +- .../pipes/filter-element-liquid.pipe.ts | 12 +- .../pipes/filter-element-solid.pipe.spec.ts | 6 +- .../pipes/filter-element-solid.pipe.ts | 12 +- .../services/authentification-service.ts | 38 +- .../services/blueprint-service.ts | 208 ++-- .../services/check-duplicate-service.ts | 51 +- .../services/game-string-service.ts | 99 +- .../module-blueprint/services/tool-service.ts | 68 +- frontend/src/app/primeng-changes/menubar.js | 516 ++++++---- frontend/src/app/primeng-changes/slider.d.ts | 155 +-- frontend/src/app/primeng-changes/slider.js | 926 ++++++++++-------- frontend/src/environments/environment.prod.ts | 2 +- frontend/src/environments/environment.ts | 2 +- frontend/src/index.html | 26 +- frontend/src/main.ts | 18 +- frontend/src/polyfills.ts | 9 +- frontend/src/styles.css | 36 +- frontend/src/test.ts | 10 +- frontend/tsconfig.app.json | 7 +- frontend/tsconfig.base.json | 13 +- frontend/tsconfig.json | 2 +- frontend/tsconfig.spec.json | 15 +- 169 files changed, 5361 insertions(+), 3209 deletions(-) diff --git a/frontend/.angulardoc.json b/frontend/.angulardoc.json index edd6a4cd..33c515c7 100644 --- a/frontend/.angulardoc.json +++ b/frontend/.angulardoc.json @@ -1,4 +1,4 @@ { "repoId": "1e8d74c7-9142-4d19-944c-af5f918e33fa", "lastSync": 0 -} \ No newline at end of file +} diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index f0326dbc..f8bd53e3 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -1,18 +1,11 @@ { "root": true, - "ignorePatterns": [ - "projects/**/*" - ], + "ignorePatterns": ["projects/**/*"], "overrides": [ { - "files": [ - "*.ts" - ], + "files": ["*.ts"], "parserOptions": { - "project": [ - "tsconfig.json", - "e2e/tsconfig.json" - ], + "project": ["tsconfig.json", "e2e/tsconfig.json"], "createDefaultProgram": true }, "extends": [ @@ -39,13 +32,8 @@ } }, { - "files": [ - "*.html" - ], - "extends": [ - "plugin:@angular-eslint/template/recommended", - "prettier" - ], + "files": ["*.html"], + "extends": ["plugin:@angular-eslint/template/recommended", "prettier"], "rules": {} } ] diff --git a/frontend/README.md b/frontend/README.md index a5146bc0..f7fa6f0f 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -23,7 +23,9 @@ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github. Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). ## Localization + If you want to contribute translations to Blueprintnotincluded, you can edit files of your language in [i18n](./src/i18n). You can use Poedit to edit those XLF files. If the file for your language is not there, please create an issus. Alternatively you can add it by yourself in the following steps: + 1. add your language in the `languages` field of [xliffmerge.json](./xliffmerge.json) 2. Run `npm run extract-i18n` 3. Add your language in [angular.json](./angular.json)(`projects.blueprintnotincluded.i18n.locales`) diff --git a/frontend/angular.json b/frontend/angular.json index 358fc4c1..d888c8fa 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -27,10 +27,7 @@ "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", "aot": true, - "assets": [ - "src/favicon_blueprint_oxygen-32x32.png", - "src/assets" - ], + "assets": ["src/favicon_blueprint_oxygen-32x32.png", "src/assets"], "styles": [ "src/styles.css", "node_modules/primeicons/primeicons.css", @@ -39,9 +36,7 @@ "node_modules/primeflex/primeflex.css", "node_modules/@fortawesome/fontawesome-free/css/all.min.css" ], - "scripts": [ - "node_modules/pixi.js-legacy/dist/pixi-legacy.min.js" - ] + "scripts": ["node_modules/pixi.js-legacy/dist/pixi-legacy.min.js"] }, "configurations": { "production": { @@ -77,21 +72,15 @@ "optimization": false }, "zh-Hans": { - "localize": [ - "zh-Hans" - ], + "localize": ["zh-Hans"], "optimization": false }, "ru": { - "localize": [ - "ru" - ], + "localize": ["ru"], "optimization": false }, "ko": { - "localize": [ - "ko" - ], + "localize": ["ko"], "optimization": false } } @@ -130,10 +119,7 @@ "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", - "assets": [ - "src/favicon_blueprint_oxygen.png", - "src/assets" - ], + "assets": ["src/favicon_blueprint_oxygen.png", "src/assets"], "styles": [ "src/styles.css", "node_modules/primeicons/primeicons.css", @@ -142,18 +128,13 @@ "node_modules/primeflex/primeflex.css", "node_modules/@fortawesome/fontawesome-free/css/all.min.css" ], - "scripts": [ - "node_modules/pixi.js-legacy/dist/pixi-legacy.min.js" - ] + "scripts": ["node_modules/pixi.js-legacy/dist/pixi-legacy.min.js"] } }, "lint": { "builder": "@angular-eslint/builder:lint", "options": { - "lintFilePatterns": [ - "src/**/*.ts", - "src/**/*.html" - ] + "lintFilePatterns": ["src/**/*.ts", "src/**/*.html"] } }, "e2e": { diff --git a/frontend/e2e/protractor.conf.js b/frontend/e2e/protractor.conf.js index 73e4e680..fab62960 100644 --- a/frontend/e2e/protractor.conf.js +++ b/frontend/e2e/protractor.conf.js @@ -2,31 +2,31 @@ // Protractor configuration file, see link for more information // https://github.com/angular/protractor/blob/master/lib/config.ts -const { SpecReporter } = require('jasmine-spec-reporter'); +const { SpecReporter } = require("jasmine-spec-reporter"); /** * @type { import("protractor").Config } */ exports.config = { allScriptsTimeout: 11000, - specs: [ - './src/**/*.e2e-spec.ts' - ], + specs: ["./src/**/*.e2e-spec.ts"], capabilities: { - 'browserName': 'chrome' + browserName: "chrome", }, directConnect: true, - baseUrl: 'http://localhost:4200/', - framework: 'jasmine', + baseUrl: "http://localhost:4200/", + framework: "jasmine", jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000, - print: function() {} + print: function () {}, }, onPrepare() { - require('ts-node').register({ - project: require('path').join(__dirname, './tsconfig.json') + require("ts-node").register({ + project: require("path").join(__dirname, "./tsconfig.json"), }); - jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); - } -}; \ No newline at end of file + jasmine + .getEnv() + .addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); + }, +}; diff --git a/frontend/e2e/src/app.e2e-spec.ts b/frontend/e2e/src/app.e2e-spec.ts index b479ad2a..6c296426 100644 --- a/frontend/e2e/src/app.e2e-spec.ts +++ b/frontend/e2e/src/app.e2e-spec.ts @@ -1,23 +1,25 @@ -import { AppPage } from './app.po'; -import { browser, logging } from 'protractor'; +import { AppPage } from "./app.po"; +import { browser, logging } from "protractor"; -describe('workspace-project App', () => { +describe("workspace-project App", () => { let page: AppPage; beforeEach(() => { page = new AppPage(); }); - it('should display welcome message', () => { + it("should display welcome message", () => { page.navigateTo(); - expect(page.getTitleText()).toEqual('blueprintnotincluded app is running!'); + expect(page.getTitleText()).toEqual("blueprintnotincluded app is running!"); }); afterEach(async () => { // Assert that there are no errors emitted from the browser const logs = await browser.manage().logs().get(logging.Type.BROWSER); - expect(logs).not.toContain(jasmine.objectContaining({ - level: logging.Level.SEVERE, - } as logging.Entry)); + expect(logs).not.toContain( + jasmine.objectContaining({ + level: logging.Level.SEVERE, + } as logging.Entry) + ); }); }); diff --git a/frontend/e2e/src/app.po.ts b/frontend/e2e/src/app.po.ts index b8498c26..d62dabbb 100644 --- a/frontend/e2e/src/app.po.ts +++ b/frontend/e2e/src/app.po.ts @@ -1,4 +1,4 @@ -import { browser, by, element } from 'protractor'; +import { browser, by, element } from "protractor"; export class AppPage { navigateTo() { @@ -6,6 +6,8 @@ export class AppPage { } getTitleText() { - return element(by.css('app-root .content span')).getText() as Promise; + return element( + by.css("app-root .content span") + ).getText() as Promise; } } diff --git a/frontend/e2e/tsconfig.json b/frontend/e2e/tsconfig.json index 6b87cc42..a2c29e26 100644 --- a/frontend/e2e/tsconfig.json +++ b/frontend/e2e/tsconfig.json @@ -4,10 +4,6 @@ "outDir": "../out-tsc/e2e", "module": "commonjs", "target": "es2018", - "types": [ - "jasmine", - "jasminewd2", - "node" - ] + "types": ["jasmine", "jasminewd2", "node"] } } diff --git a/frontend/karma.conf.js b/frontend/karma.conf.js index d76f956c..49dbf0f7 100644 --- a/frontend/karma.conf.js +++ b/frontend/karma.conf.js @@ -3,30 +3,30 @@ module.exports = function (config) { config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], + basePath: "", + frameworks: ["jasmine", "@angular-devkit/build-angular"], plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage-istanbul-reporter'), - require('@angular-devkit/build-angular/plugins/karma') + require("karma-jasmine"), + require("karma-chrome-launcher"), + require("karma-jasmine-html-reporter"), + require("karma-coverage-istanbul-reporter"), + require("@angular-devkit/build-angular/plugins/karma"), ], client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser + clearContext: false, // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { - dir: require('path').join(__dirname, './coverage/blueprintnotincluded'), - reports: ['html', 'lcovonly', 'text-summary'], - fixWebpackSourcePaths: true + dir: require("path").join(__dirname, "./coverage/blueprintnotincluded"), + reports: ["html", "lcovonly", "text-summary"], + fixWebpackSourcePaths: true, }, - reporters: ['progress', 'kjhtml'], + reporters: ["progress", "kjhtml"], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, - browsers: ['Chrome'], + browsers: ["Chrome"], singleRun: false, - restartOnFileChange: true + restartOnFileChange: true, }); }; diff --git a/frontend/proxy.conf.json b/frontend/proxy.conf.json index 46c960e1..890ecb35 100644 --- a/frontend/proxy.conf.json +++ b/frontend/proxy.conf.json @@ -5,4 +5,4 @@ "logLevel": "debug", "changeOrigin": true } -} \ No newline at end of file +} diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index db2113f4..2be4aa60 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -1,20 +1,22 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; -import { ComponentBlueprintParentComponent } from './module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component'; - +import { NgModule } from "@angular/core"; +import { Routes, RouterModule } from "@angular/router"; +import { ComponentBlueprintParentComponent } from "./module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component"; const routes: Routes = [ - { path: '', component: ComponentBlueprintParentComponent }, - { path: 'b/:id', component: ComponentBlueprintParentComponent }, - { path: 'b/:id/hideui/:width/:height', component: ComponentBlueprintParentComponent }, - { path: 'openfromurl/:url', component: ComponentBlueprintParentComponent }, - { path: 'browse', component: ComponentBlueprintParentComponent }, - { path: 'about', component: ComponentBlueprintParentComponent }, - { path: '', redirectTo: '/', pathMatch: 'prefix' }, + { path: "", component: ComponentBlueprintParentComponent }, + { path: "b/:id", component: ComponentBlueprintParentComponent }, + { + path: "b/:id/hideui/:width/:height", + component: ComponentBlueprintParentComponent, + }, + { path: "openfromurl/:url", component: ComponentBlueprintParentComponent }, + { path: "browse", component: ComponentBlueprintParentComponent }, + { path: "about", component: ComponentBlueprintParentComponent }, + { path: "", redirectTo: "/", pathMatch: "prefix" }, ]; @NgModule({ imports: [RouterModule.forRoot(routes)], - exports: [RouterModule] + exports: [RouterModule], }) -export class AppRoutingModule { } +export class AppRoutingModule {} diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index b1be8d5f..568e073c 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -1,5 +1,4 @@ - - \ No newline at end of file + diff --git a/frontend/src/app/app.component.spec.ts b/frontend/src/app/app.component.spec.ts index 50446d0b..f62b5952 100644 --- a/frontend/src/app/app.component.spec.ts +++ b/frontend/src/app/app.component.spec.ts @@ -1,20 +1,16 @@ -import { TestBed, async } from '@angular/core/testing'; -import { RouterTestingModule } from '@angular/router/testing'; -import { AppComponent } from './app.component'; +import { TestBed, async } from "@angular/core/testing"; +import { RouterTestingModule } from "@angular/router/testing"; +import { AppComponent } from "./app.component"; -describe('AppComponent', () => { +describe("AppComponent", () => { beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [ - RouterTestingModule - ], - declarations: [ - AppComponent - ], + imports: [RouterTestingModule], + declarations: [AppComponent], }).compileComponents(); })); - it('should create the app', () => { + it("should create the app", () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); @@ -23,13 +19,15 @@ describe('AppComponent', () => { it(`should have as title 'blueprintnotincluded'`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; - expect(app.title).toEqual('blueprintnotincluded'); + expect(app.title).toEqual("blueprintnotincluded"); }); - it('should render title', () => { + it("should render title", () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector('.content span').textContent).toContain('blueprintnotincluded app is running!'); + expect(compiled.querySelector(".content span").textContent).toContain( + "blueprintnotincluded app is running!" + ); }); }); diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 08b66080..0748f556 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,11 +1,11 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnInit, ViewChild } from "@angular/core"; declare var PIXI: any; @Component({ - selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.css'] + selector: "app-root", + templateUrl: "./app.component.html", + styleUrls: ["./app.component.css"], }) export class AppComponent { - title = 'blueprintnotincluded'; + title = "blueprintnotincluded"; } diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 780697ce..b6b840ce 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -1,27 +1,28 @@ -import { BrowserModule, EventManager } from '@angular/platform-browser'; -import { NgModule, ErrorHandler } from '@angular/core'; +import { BrowserModule, EventManager } from "@angular/platform-browser"; +import { NgModule, ErrorHandler } from "@angular/core"; import { Router } from "@angular/router"; -import { HttpClientModule } from '@angular/common/http'; -import { NgxGoogleAnalyticsModule, NgxGoogleAnalyticsRouterModule } from 'ngx-google-analytics'; +import { HttpClientModule } from "@angular/common/http"; +import { + NgxGoogleAnalyticsModule, + NgxGoogleAnalyticsRouterModule, +} from "ngx-google-analytics"; import * as Sentry from "@sentry/angular-ivy"; -import { AppRoutingModule } from './app-routing.module'; -import { AppComponent } from './app.component'; +import { AppRoutingModule } from "./app-routing.module"; +import { AppComponent } from "./app.component"; -import { ModuleBlueprintModule } from './module-blueprint/module-blueprint.module'; -import { CustomEventManager } from './module-blueprint/directives/custom-event-manager'; +import { ModuleBlueprintModule } from "./module-blueprint/module-blueprint.module"; +import { CustomEventManager } from "./module-blueprint/directives/custom-event-manager"; @NgModule({ - declarations: [ - AppComponent - ], + declarations: [AppComponent], imports: [ BrowserModule, NgxGoogleAnalyticsModule.forRoot(process.env.NG_APP_GA_TRACKING_CODE), NgxGoogleAnalyticsRouterModule.forRoot(), ModuleBlueprintModule, HttpClientModule, - AppRoutingModule + AppRoutingModule, ], providers: [ { provide: EventManager, useClass: CustomEventManager }, @@ -36,8 +37,8 @@ import { CustomEventManager } from './module-blueprint/directives/custom-event-m deps: [Router], }, ], - bootstrap: [AppComponent] + bootstrap: [AppComponent], }) export class AppModule { - constructor(trace: Sentry.TraceService) { } + constructor(trace: Sentry.TraceService) {} } diff --git a/frontend/src/app/module-blueprint/common/params.ts b/frontend/src/app/module-blueprint/common/params.ts index d1026c30..b06843b9 100644 --- a/frontend/src/app/module-blueprint/common/params.ts +++ b/frontend/src/app/module-blueprint/common/params.ts @@ -1,5 +1,4 @@ -export class BlueprintParams -{ +export class BlueprintParams { //static apiUrl = 'http://blueprintnotincluded.com/' - static apiUrl = 'http://localhost:3000/' -} \ No newline at end of file + static apiUrl = "http://localhost:3000/"; +} diff --git a/frontend/src/app/module-blueprint/common/save-info.ts b/frontend/src/app/module-blueprint/common/save-info.ts index 1cef8107..4de8cc9c 100644 --- a/frontend/src/app/module-blueprint/common/save-info.ts +++ b/frontend/src/app/module-blueprint/common/save-info.ts @@ -1,7 +1,6 @@ -import { Blueprint } from "../../../../../lib/index" +import { Blueprint } from "../../../../../lib/index"; -export class SaveInfo -{ +export class SaveInfo { username: string; blueprintName: string; blueprint: Blueprint; diff --git a/frontend/src/app/module-blueprint/common/tools/build-tool.ts b/frontend/src/app/module-blueprint/common/tools/build-tool.ts index 192e33b6..d6937455 100644 --- a/frontend/src/app/module-blueprint/common/tools/build-tool.ts +++ b/frontend/src/app/module-blueprint/common/tools/build-tool.ts @@ -1,18 +1,31 @@ -import { BlueprintService } from '../../services/blueprint-service'; -import { BlueprintHelpers, BlueprintItemWire, BlueprintItem, CameraService, DrawHelpers, Vector2, PixiUtil, BuildCandidateResult, BuildLocationRule, ConnectionHelper } from "../../../../../../lib/index"; -import { Injectable, ApplicationRef } from '@angular/core'; -import { ITool, IChangeTool, ToolType } from './tool'; -import { DrawPixi } from '../../drawing/draw-pixi'; +import { BlueprintService } from "../../services/blueprint-service"; +import { + BlueprintHelpers, + BlueprintItemWire, + BlueprintItem, + CameraService, + DrawHelpers, + Vector2, + PixiUtil, + BuildCandidateResult, + BuildLocationRule, + ConnectionHelper, +} from "../../../../../../lib/index"; +import { Injectable, ApplicationRef } from "@angular/core"; +import { ITool, IChangeTool, ToolType } from "./tool"; +import { DrawPixi } from "../../drawing/draw-pixi"; @Injectable() export class BuildTool implements ITool { - templateItemToBuild: BlueprintItem; private observers: IObsBuildItemChanged[]; parent: IChangeTool; - constructor(private blueprintService: BlueprintService, private appRef: ApplicationRef) { + constructor( + private blueprintService: BlueprintService, + private appRef: ApplicationRef + ) { this.observers = []; } @@ -28,50 +41,87 @@ export class BuildTool implements ITool { } private updateBuildCandidateResult() { - let previousCanBuild = this.templateItemToBuild.buildCandidateResult.canBuild.valueOf(); - let previousCantBuildReason = this.templateItemToBuild.buildCandidateResult.cantBuildReason.valueOf(); + let previousCanBuild = + this.templateItemToBuild.buildCandidateResult.canBuild.valueOf(); + let previousCantBuildReason = + this.templateItemToBuild.buildCandidateResult.cantBuildReason.valueOf(); this.templateItemToBuild.buildCandidateResult.canBuild = true; - this.templateItemToBuild.buildCandidateResult.cantBuildReason = ''; + this.templateItemToBuild.buildCandidateResult.cantBuildReason = ""; // First : iterate all the buildings on each tile of this building - let isBridge = this.templateItemToBuild.oniItem.buildLocationRule == BuildLocationRule.Conduit || this.templateItemToBuild.oniItem.buildLocationRule == BuildLocationRule.WireBridge || this.templateItemToBuild.oniItem.buildLocationRule == BuildLocationRule.LogicBridge; + let isBridge = + this.templateItemToBuild.oniItem.buildLocationRule == + BuildLocationRule.Conduit || + this.templateItemToBuild.oniItem.buildLocationRule == + BuildLocationRule.WireBridge || + this.templateItemToBuild.oniItem.buildLocationRule == + BuildLocationRule.LogicBridge; for (let tileIndex of this.templateItemToBuild.tileIndexes) { - for (let templateItem of this.blueprintService.blueprint.getBlueprintItemsAtIndex(tileIndex)) { + for (let templateItem of this.blueprintService.blueprint.getBlueprintItemsAtIndex( + tileIndex + )) { // If at least one of them is in the same object layer, we can't build // We skip this step for bridges, who only care about their utility ports - if (!isBridge && this.templateItemToBuild.oniItem.objectLayer == templateItem.oniItem.objectLayer) { + if ( + !isBridge && + this.templateItemToBuild.oniItem.objectLayer == + templateItem.oniItem.objectLayer + ) { this.templateItemToBuild.buildCandidateResult.canBuild = false; this.templateItemToBuild.buildCandidateResult.cantBuildReason = $localize`Can\'t build here : ${templateItem.oniItem.name} is in the way`; } } } - for (let connectionToBuild of this.templateItemToBuild.oniItem.utilityConnections) { + for (let connectionToBuild of this.templateItemToBuild.oniItem + .utilityConnections) { // We rotate and scale the offset, and add to the position - let connectionToBuildPosition = Vector2.cloneNullToZero(connectionToBuild.offset); - connectionToBuildPosition = DrawHelpers.rotateVector2(connectionToBuildPosition, Vector2.Zero, this.templateItemToBuild.rotation); - connectionToBuildPosition = DrawHelpers.scaleVector2(connectionToBuildPosition, Vector2.Zero, this.templateItemToBuild.scale); + let connectionToBuildPosition = Vector2.cloneNullToZero( + connectionToBuild.offset + ); + connectionToBuildPosition = DrawHelpers.rotateVector2( + connectionToBuildPosition, + Vector2.Zero, + this.templateItemToBuild.rotation + ); + connectionToBuildPosition = DrawHelpers.scaleVector2( + connectionToBuildPosition, + Vector2.Zero, + this.templateItemToBuild.scale + ); connectionToBuildPosition.x += this.templateItemToBuild.position.x; connectionToBuildPosition.y += this.templateItemToBuild.position.y; - let utilitiesAtIndex = this.blueprintService.blueprint.getUtilityConnectionsAtIndex(DrawHelpers.getTileIndex(connectionToBuildPosition)); + let utilitiesAtIndex = + this.blueprintService.blueprint.getUtilityConnectionsAtIndex( + DrawHelpers.getTileIndex(connectionToBuildPosition) + ); for (let trackedUtilities of utilitiesAtIndex) { - - if (ConnectionHelper.getConnectionOverlay(connectionToBuild.type) == ConnectionHelper.getConnectionOverlay(trackedUtilities.utilityConnection.type)) { + if ( + ConnectionHelper.getConnectionOverlay(connectionToBuild.type) == + ConnectionHelper.getConnectionOverlay( + trackedUtilities.utilityConnection.type + ) + ) { this.templateItemToBuild.buildCandidateResult.canBuild = false; - const connection = ConnectionHelper.getConnectionName(trackedUtilities.utilityConnection.type); + const connection = ConnectionHelper.getConnectionName( + trackedUtilities.utilityConnection.type + ); const itemName = trackedUtilities.blueprintItem.oniItem.name; this.templateItemToBuild.buildCandidateResult.cantBuildReason = $localize`Can\'t build here : The ${connection} from ${itemName} is in the way`; } } } - if (previousCanBuild != this.templateItemToBuild.buildCandidateResult.canBuild || - previousCantBuildReason != this.templateItemToBuild.buildCandidateResult.cantBuildReason) { - + if ( + previousCanBuild != + this.templateItemToBuild.buildCandidateResult.canBuild || + previousCantBuildReason != + this.templateItemToBuild.buildCandidateResult.cantBuildReason + ) { // The mousemouse is outside the angular zone, so we have to force a full update here. this.appRef.tick(); } @@ -80,7 +130,11 @@ export class BuildTool implements ITool { build() { if (!this.templateItemToBuild.buildCandidateResult.canBuild) return; - let newItem = BlueprintHelpers.cloneBlueprintItem(this.templateItemToBuild, false, true); + let newItem = BlueprintHelpers.cloneBlueprintItem( + this.templateItemToBuild, + false, + true + ); newItem.prepareBoundingBox(); newItem.updateTileables(this.blueprintService.blueprint); @@ -91,10 +145,14 @@ export class BuildTool implements ITool { private connectAToB(a: BlueprintItemWire, b: BlueprintItemWire) { let bitMask = 0; - if (a.position.x == b.position.x + 1 && a.position.y == b.position.y) bitMask = 1; - else if (a.position.x == b.position.x - 1 && a.position.y == b.position.y) bitMask = 2; - else if (a.position.x == b.position.x && a.position.y == b.position.y - 1) bitMask = 4; - else if (a.position.x == b.position.x && a.position.y == b.position.y + 1) bitMask = 8; + if (a.position.x == b.position.x + 1 && a.position.y == b.position.y) + bitMask = 1; + else if (a.position.x == b.position.x - 1 && a.position.y == b.position.y) + bitMask = 2; + else if (a.position.x == b.position.x && a.position.y == b.position.y - 1) + bitMask = 4; + else if (a.position.x == b.position.x && a.position.y == b.position.y + 1) + bitMask = 8; a.connections = a.connections | bitMask; } @@ -122,10 +180,27 @@ export class BuildTool implements ITool { this.build(); if (this.templateItemToBuild.oniItem.isWire) { - let itemsPrevious = this.blueprintService.blueprint.getBlueprintItemsAt(tileStart).filter(i => i.oniItem.objectLayer == this.templateItemToBuild.oniItem.objectLayer); - let itemsCurrent = this.blueprintService.blueprint.getBlueprintItemsAt(tileStop).filter(i => i.oniItem.objectLayer == this.templateItemToBuild.oniItem.objectLayer); - - if (itemsPrevious != null && itemsPrevious.length > 0 && itemsCurrent != null && itemsCurrent.length > 0) { + let itemsPrevious = this.blueprintService.blueprint + .getBlueprintItemsAt(tileStart) + .filter( + (i) => + i.oniItem.objectLayer == + this.templateItemToBuild.oniItem.objectLayer + ); + let itemsCurrent = this.blueprintService.blueprint + .getBlueprintItemsAt(tileStop) + .filter( + (i) => + i.oniItem.objectLayer == + this.templateItemToBuild.oniItem.objectLayer + ); + + if ( + itemsPrevious != null && + itemsPrevious.length > 0 && + itemsCurrent != null && + itemsCurrent.length > 0 + ) { let itemPrevious = itemsPrevious[0] as BlueprintItemWire; let itemCurrent = itemsCurrent[0] as BlueprintItemWire; @@ -149,7 +224,8 @@ export class BuildTool implements ITool { } mouseOut() { - if (this.templateItemToBuild != null) this.templateItemToBuild.setInvisible(); + if (this.templateItemToBuild != null) + this.templateItemToBuild.setInvisible(); } leftClick(tile: Vector2) { @@ -169,15 +245,14 @@ export class BuildTool implements ITool { } drag(tileStart: Vector2, tileStop: Vector2) { - if (tileStart == null || tileStop == null) return; let tileStartInt = DrawHelpers.getIntegerTile(tileStart); let tileStopInt = DrawHelpers.getIntegerTile(tileStop); // Only drag if we are changing tiles - if (!tileStartInt.equals(tileStopInt)) this.dragStepByStep(tileStart, tileStop); - + if (!tileStartInt.equals(tileStopInt)) + this.dragStepByStep(tileStart, tileStop); } mouseDown(tile: Vector2) { @@ -186,23 +261,22 @@ export class BuildTool implements ITool { } dragStepByStep(tileStart: Vector2, tileStop: Vector2) { - - - //console.log('start') //console.log(tileStart); //console.log(tileStop); // This is the unit taxicab vector representing the general direction of movement let delta = new Vector2( - DrawHelpers.getFloorTile(tileStop).x - DrawHelpers.getFloorTile(tileStart).x, - DrawHelpers.getFloorTile(tileStop).y - DrawHelpers.getFloorTile(tileStart).y + DrawHelpers.getFloorTile(tileStop).x - + DrawHelpers.getFloorTile(tileStart).x, + DrawHelpers.getFloorTile(tileStop).y - + DrawHelpers.getFloorTile(tileStart).y ); delta = new Vector2( delta.x == 0 ? 0 : 1 * (delta.x / Math.abs(delta.x)), delta.y == 0 ? 0 : 1 * (delta.y / Math.abs(delta.y)) - ) + ); // Special cases : if tileStart or tileStop is an integer, we run into problems, so let's change that if (tileStart.x == Math.floor(tileStart.x)) tileStart.x -= delta.x * 0.005; @@ -233,13 +307,15 @@ export class BuildTool implements ITool { // nextTile is currentTile advanced by delta // and then floored of ceilingedto be closest to currentTile - let nextTile = new Vector2(currentTile.x + delta.x, currentTile.y + delta.y); + let nextTile = new Vector2( + currentTile.x + delta.x, + currentTile.y + delta.y + ); if (delta.x > 0) nextTile.x = Math.floor(nextTile.x); else if (delta.x < 0) nextTile.x = Math.ceil(nextTile.x); if (delta.y > 0) nextTile.y = Math.floor(nextTile.y); else if (delta.y < 0) nextTile.y = Math.ceil(nextTile.y); - //console.log('nextTile'); //console.log(nextTile); @@ -263,10 +339,12 @@ export class BuildTool implements ITool { //console.log(dp) let distX: number = 999; - if (delta.x != 0) distX = (new Vector2(dp.x, d.y * (dp.x / d.x))).lengthSquared; + if (delta.x != 0) + distX = new Vector2(dp.x, d.y * (dp.x / d.x)).lengthSquared; let distY: number = 999; - if (delta.y != 0) distY = (new Vector2(d.x * (dp.y / d.y), dp.y)).lengthSquared; + if (delta.y != 0) + distY = new Vector2(d.x * (dp.y / d.y), dp.y).lengthSquared; //console.log('dist') //console.log(new Vector2(distX, distY)) @@ -288,8 +366,7 @@ export class BuildTool implements ITool { currentTile.x += dp.x; currentTile.y += d.y * (dp.x / d.x); - } - else if (distX <= distY && distX < dLengthSquared) { + } else if (distX <= distY && distX < dLengthSquared) { //console.log('build'); currentTile.x += dp.x; currentTile.y += d.y * (dp.x / d.x); @@ -298,8 +375,7 @@ export class BuildTool implements ITool { this.buildAndConnect(startTile, newTile); startTile.x += delta.x; //console.log(startTile); - } - else if (distY < distX && distY < dLengthSquared) { + } else if (distY < distX && distY < dLengthSquared) { //console.log('build'); currentTile.x += d.x * (dp.y / d.y); currentTile.y += dp.y; @@ -308,17 +384,14 @@ export class BuildTool implements ITool { this.buildAndConnect(startTile, newTile); startTile.y += delta.y; //console.log(startTile); - } - else { + } else { //console.log('stop') advance = false; } i++; if (i > 999) throw new Error("The tile dragger was too long"); - } - } dragStop() { @@ -326,7 +399,7 @@ export class BuildTool implements ITool { } keyDown(keyCode: string) { - if (keyCode == 'o') { + if (keyCode == "o") { if (this.templateItemToBuild != null) { this.templateItemToBuild.nextOrientation(); this.updateBuildCandidateResult(); @@ -335,7 +408,6 @@ export class BuildTool implements ITool { } draw(drawPixi: DrawPixi, camera: CameraService) { - // TODO SOLID //if (this.canBuild()) this.templateItemToBuild.drawPart.tint = DrawHelpers.whiteColor; //else this.templateItemToBuild.drawPart.tint = 0xD40000; diff --git a/frontend/src/app/module-blueprint/common/tools/element-report.ts b/frontend/src/app/module-blueprint/common/tools/element-report.ts index 7949c833..606530fb 100644 --- a/frontend/src/app/module-blueprint/common/tools/element-report.ts +++ b/frontend/src/app/module-blueprint/common/tools/element-report.ts @@ -1,32 +1,48 @@ -import { BlueprintService } from '../../services/blueprint-service'; -import { Injectable } from '@angular/core'; -import { BlueprintItemElement, BlueprintItem, IObsBlueprintChange, DrawHelpers, BuildableElement } from '../../../../../../lib/index' +import { BlueprintService } from "../../services/blueprint-service"; +import { Injectable } from "@angular/core"; +import { + BlueprintItemElement, + BlueprintItem, + IObsBlueprintChange, + DrawHelpers, + BuildableElement, +} from "../../../../../../lib/index"; @Injectable() export class ElementReport implements IObsBlueprintChange { - data: ElementReportDataItem[]; constructor(private blueprintService: BlueprintService) { this.data = []; - this.blueprintService.blueprint.subscribeBlueprintChanged(this) + this.blueprintService.blueprint.subscribeBlueprintChanged(this); } updateElementReport() { this.data = []; this.blueprintService.blueprint.blueprintItems.map((item) => { - if (item.oniItem.isElement) - this.addElementToReport(item.buildableElements[0], (item as BlueprintItemElement).mass); + this.addElementToReport( + item.buildableElements[0], + (item as BlueprintItemElement).mass + ); else - for (let elementIndex = 0; elementIndex < item.oniItem.buildableElementsArray.length; elementIndex++) { - this.addElementToReport(item.buildableElements[elementIndex], item.oniItem.materialMass[elementIndex]) + for ( + let elementIndex = 0; + elementIndex < item.oniItem.buildableElementsArray.length; + elementIndex++ + ) { + this.addElementToReport( + item.buildableElements[elementIndex], + item.oniItem.materialMass[elementIndex] + ); } }); - this.data = this.data.sort((i1, i2) => { return i2.totalMass - i1.totalMass; }); + this.data = this.data.sort((i1, i2) => { + return i2.totalMass - i1.totalMass; + }); } private addElementToReport(buildableElement: BuildableElement, mass: number) { @@ -42,7 +58,7 @@ export class ElementReport implements IObsBlueprintChange { this.data.push({ buildableElement: buildableElement, colorString: DrawHelpers.colorToHex(buildableElement.color), - totalMass: mass + totalMass: mass, }); } } diff --git a/frontend/src/app/module-blueprint/common/tools/same-item-collection.ts b/frontend/src/app/module-blueprint/common/tools/same-item-collection.ts index 01e69219..ef259fb2 100644 --- a/frontend/src/app/module-blueprint/common/tools/same-item-collection.ts +++ b/frontend/src/app/module-blueprint/common/tools/same-item-collection.ts @@ -1,17 +1,25 @@ -import { BlueprintService } from '../../services/blueprint-service'; -import { BlueprintItem, CameraService, OniItem, BuildableElement } from '../../../../../../lib/index' - -export class SameItemCollection -{ +import { BlueprintService } from "../../services/blueprint-service"; +import { + BlueprintItem, + CameraService, + OniItem, + BuildableElement, +} from "../../../../../../lib/index"; + +export class SameItemCollection { private selected_: boolean; - get selected() {return this.selected_;} + get selected() { + return this.selected_; + } set selected(value: boolean) { this.selected_ = value; this.setSelection(); if (this.selected_) { CameraService.cameraService.resetSinWave(); CameraService.cameraService.setOverlayForItem(this.oniItem); - this.observersSelected.map((observer) => { observer.selected(); }) + this.observersSelected.map((observer) => { + observer.selected(); + }); } } @@ -24,7 +32,11 @@ export class SameItemCollection this.oniItem = oniItem; this.items = []; this.nbElements = []; - for (let indexElement = 0; indexElement < this.oniItem.buildableElementsArray.length; indexElement++) + for ( + let indexElement = 0; + indexElement < this.oniItem.buildableElementsArray.length; + indexElement++ + ) this.nbElements[indexElement] = 0; this.temperatureWarning = false; @@ -32,7 +44,9 @@ export class SameItemCollection this.observersSelected = []; } - get header() { return this.items[0].header; } + get header() { + return this.items[0].header; + } addItem(blueprintItem: BlueprintItem) { // We need to test if the item was already added to this collection, (some items are bigger than one tile) @@ -45,7 +59,11 @@ export class SameItemCollection } updateNbElements() { - for (let indexElement = 0; indexElement < this.oniItem.buildableElementsArray.length; indexElement++) { + for ( + let indexElement = 0; + indexElement < this.oniItem.buildableElementsArray.length; + indexElement++ + ) { let elements: BuildableElement[] = []; for (let item of this.items) @@ -62,7 +80,8 @@ export class SameItemCollection for (let item of this.items) if (firstTemperature == null) firstTemperature = item.temperature; - else if (item.temperature != firstTemperature) this.temperatureWarning = true; + else if (item.temperature != firstTemperature) + this.temperatureWarning = true; } setSelection() { diff --git a/frontend/src/app/module-blueprint/common/tools/select-tool.ts b/frontend/src/app/module-blueprint/common/tools/select-tool.ts index 8950eb9c..d9640513 100644 --- a/frontend/src/app/module-blueprint/common/tools/select-tool.ts +++ b/frontend/src/app/module-blueprint/common/tools/select-tool.ts @@ -1,20 +1,25 @@ -import { BlueprintService } from '../../services/blueprint-service'; -import { BlueprintItem, CameraService, DrawHelpers, OniItem, Vector2, BuildableElement } from "../../../../../../lib/index"; -import { Injectable } from '@angular/core'; -import { ITool, ToolType } from './tool'; -import { DrawPixi } from '../../drawing/draw-pixi'; -import { SameItemCollection } from './same-item-collection'; +import { BlueprintService } from "../../services/blueprint-service"; +import { + BlueprintItem, + CameraService, + DrawHelpers, + OniItem, + Vector2, + BuildableElement, +} from "../../../../../../lib/index"; +import { Injectable } from "@angular/core"; +import { ITool, ToolType } from "./tool"; +import { DrawPixi } from "../../drawing/draw-pixi"; +import { SameItemCollection } from "./same-item-collection"; @Injectable() -export class SelectTool implements ITool -{ +export class SelectTool implements ITool { public sameItemCollections: SameItemCollection[]; public observersSelectionChanged: IObsSelectionChanged[] = []; - private cameraService: CameraService + private cameraService: CameraService; constructor(private blueprintService: BlueprintService) { - this.cameraService = CameraService.cameraService; // TODO also do this on blueprint loading this.reset(); @@ -24,8 +29,7 @@ export class SelectTool implements ITool return this.sameItemCollections.length > 0; } - reset() - { + reset() { this.deselectAll(); this.sameItemCollections = []; } @@ -35,7 +39,9 @@ export class SelectTool implements ITool } private emitSelectionChanged() { - this.observersSelectionChanged.map((observer) => { observer.selectionChanged(); }); + this.observersSelectionChanged.map((observer) => { + observer.selectionChanged(); + }); } private lastSelected: BlueprintItem; @@ -51,26 +57,36 @@ export class SelectTool implements ITool tileSelected.push(new Vector2(x, y)); if (tileSelected.length > 0) { - for (let tile of tileSelected) { - let itemsInTile = this.blueprintService.blueprint.getBlueprintItemsAt(tile); + let itemsInTile = + this.blueprintService.blueprint.getBlueprintItemsAt(tile); for (let item of itemsInTile) this.addToCollection(item); } - this.sameItemCollections = this.sameItemCollections.sort((i1, i2) => { return i2.items[0].depth - i1.items[0].depth; }); + this.sameItemCollections = this.sameItemCollections.sort((i1, i2) => { + return i2.items[0].depth - i1.items[0].depth; + }); let firstSelected: BlueprintItem = null; let selectedOne = false; this.sameItemCollections.map((itemCollection) => { - if (!selectedOne && itemCollection.items != null && itemCollection.items.length > 0) { + if ( + !selectedOne && + itemCollection.items != null && + itemCollection.items.length > 0 + ) { selectedOne = true; firstSelected = itemCollection.items[0]; let newDate = new Date(); - if (firstSelected == this.lastSelected && this.lastSelectedDate != null && newDate.getTime() - this.lastSelectedDate.getTime() < 500) this.selectAllLike(firstSelected); + if ( + firstSelected == this.lastSelected && + this.lastSelectedDate != null && + newDate.getTime() - this.lastSelectedDate.getTime() < 500 + ) + this.selectAllLike(firstSelected); else { itemCollection.selected = true; - } this.lastSelected = firstSelected; @@ -87,9 +103,13 @@ export class SelectTool implements ITool selectAll(oniItem: OniItem) { this.deselectAll(); - this.blueprintService.blueprint.blueprintItems.filter((item) => { return item.oniItem == oniItem; }).map((item) => { - this.addToCollection(item); - }); + this.blueprintService.blueprint.blueprintItems + .filter((item) => { + return item.oniItem == oniItem; + }) + .map((item) => { + this.addToCollection(item); + }); this.currentMultipleSelectionIndex = 0; @@ -99,12 +119,18 @@ export class SelectTool implements ITool selectAllLike(original: BlueprintItem) { this.deselectAll(); - this.blueprintService.blueprint.blueprintItems.filter((item) => { - if (original.oniItem.isElement) return original.oniItem == item.oniItem && original.buildableElements[0] == item.buildableElements[0]; - else return original.oniItem == item.oniItem; - }).map((item) => { - this.addToCollection(item); - }); + this.blueprintService.blueprint.blueprintItems + .filter((item) => { + if (original.oniItem.isElement) + return ( + original.oniItem == item.oniItem && + original.buildableElements[0] == item.buildableElements[0] + ); + else return original.oniItem == item.oniItem; + }) + .map((item) => { + this.addToCollection(item); + }); this.currentMultipleSelectionIndex = 0; @@ -114,9 +140,13 @@ export class SelectTool implements ITool selectEveryInfo() { this.deselectAll(); - this.blueprintService.blueprint.blueprintItems.filter((item) => { return item.oniItem.isInfo; }).map((item) => { - this.addToCollection(item); - }); + this.blueprintService.blueprint.blueprintItems + .filter((item) => { + return item.oniItem.isInfo; + }) + .map((item) => { + this.addToCollection(item); + }); this.currentMultipleSelectionIndex = 0; @@ -126,9 +156,13 @@ export class SelectTool implements ITool selectThis(original: BlueprintItem) { this.deselectAll(); - this.blueprintService.blueprint.blueprintItems.filter((item) => { return item == original; }).map((item) => { - this.addToCollection(item); - }); + this.blueprintService.blueprint.blueprintItems + .filter((item) => { + return item == original; + }) + .map((item) => { + this.addToCollection(item); + }); this.currentMultipleSelectionIndex = 0; @@ -143,7 +177,9 @@ export class SelectTool implements ITool this.addToCollection(blueprintItem); // TODO this does not seem to sort - this.sameItemCollections = this.sameItemCollections.sort((i1, i2) => { return i2.oniItem.zIndex - i1.oniItem.zIndex; }); + this.sameItemCollections = this.sameItemCollections.sort((i1, i2) => { + return i2.oniItem.zIndex - i1.oniItem.zIndex; + }); this.currentMultipleSelectionIndex = 0; @@ -151,11 +187,14 @@ export class SelectTool implements ITool } addToCollection(blueprintItem: BlueprintItem) { - // Find if there is already an item collection for this oniItem let itemCollectionArray = this.sameItemCollections.filter((sameItem) => { if (blueprintItem.oniItem.isElement) - return blueprintItem.oniItem.id == sameItem.oniItem.id && blueprintItem.buildableElements[0].id == sameItem.items[0].buildableElements[0].id + return ( + blueprintItem.oniItem.id == sameItem.oniItem.id && + blueprintItem.buildableElements[0].id == + sameItem.items[0].buildableElements[0].id + ); else return blueprintItem.oniItem.id == sameItem.oniItem.id; }); if (itemCollectionArray.length == 0) { @@ -163,25 +202,29 @@ export class SelectTool implements ITool newItemCollection.addItem(blueprintItem); this.sameItemCollections.push(newItemCollection); - } - else itemCollectionArray[0].addItem(blueprintItem); + } else itemCollectionArray[0].addItem(blueprintItem); } deselectAll() { - if (this.sameItemCollections != null) this.sameItemCollections.map((itemCollection) => { itemCollection.selected = false; }); - this.sameItemCollections= []; + if (this.sameItemCollections != null) + this.sameItemCollections.map((itemCollection) => { + itemCollection.selected = false; + }); + this.sameItemCollections = []; this.emitSelectionChanged(); } buildingsDestroy(itemCollection: SameItemCollection) { - this.blueprintService.blueprint.pauseChangeEvents(); for (let item of itemCollection.items) this.blueprintService.blueprint.destroyBlueprintItem(item); this.blueprintService.blueprint.resumeChangeEvents(); - this.sameItemCollections.splice(this.sameItemCollections.indexOf(itemCollection), 1); + this.sameItemCollections.splice( + this.sameItemCollections.indexOf(itemCollection), + 1 + ); this.emitSelectionChanged(); } @@ -189,7 +232,11 @@ export class SelectTool implements ITool get currentMultipleSelectionIndex() { let activeIndex = -1; - for (let indexSelected = 0; indexSelected < this.sameItemCollections.length; indexSelected++) + for ( + let indexSelected = 0; + indexSelected < this.sameItemCollections.length; + indexSelected++ + ) if (this.sameItemCollections[indexSelected].selected) activeIndex = indexSelected; @@ -197,8 +244,12 @@ export class SelectTool implements ITool } set currentMultipleSelectionIndex(value: number) { - for (let indexSelected = 0; indexSelected < this.sameItemCollections.length; indexSelected++) - this.sameItemCollections[indexSelected].selected = (value == indexSelected); + for ( + let indexSelected = 0; + indexSelected < this.sameItemCollections.length; + indexSelected++ + ) + this.sameItemCollections[indexSelected].selected = value == indexSelected; } itemGroupeNext() { @@ -252,23 +303,20 @@ export class SelectTool implements ITool this.selectFromBox(tile, tile); } - rightClick(tile: Vector2) { - } + rightClick(tile: Vector2) {} - hover(tile: Vector2) { - } + hover(tile: Vector2) {} beginSelection: Vector2 = null; endSelection: Vector2; drag(tileStart: Vector2, tileStop: Vector2) { - if (this.beginSelection == null) this.beginSelection = Vector2.clone(tileStart); + if (this.beginSelection == null) + this.beginSelection = Vector2.clone(tileStart); this.endSelection = Vector2.clone(tileStop); } dragStop() { - - if (this.beginSelection != null && this.endSelection != null) - { + if (this.beginSelection != null && this.endSelection != null) { let beginTile = DrawHelpers.getIntegerTile(this.beginSelection); let endTile = DrawHelpers.getIntegerTile(this.endSelection); @@ -289,14 +337,16 @@ export class SelectTool implements ITool } keyDown(keyCode: string) { - if (keyCode == 'Delete') { + if (keyCode == "Delete") { let itemGroupToDestroyIndex = this.currentMultipleSelectionIndex; - if (itemGroupToDestroyIndex != -1) this.buildingsDestroy(this.sameItemCollections[itemGroupToDestroyIndex]); + if (itemGroupToDestroyIndex != -1) + this.buildingsDestroy( + this.sameItemCollections[itemGroupToDestroyIndex] + ); } } draw(drawPixi: DrawPixi, camera: CameraService) { - // Return if (this.beginSelection == null) return; @@ -310,7 +360,17 @@ export class SelectTool implements ITool Math.min(this.beginSelection.y, this.endSelection.y) ); - drawPixi.drawTileRectangle(camera, topLeft, bottomRight, true, 2, 0x4CFF00, 0x2D9600, 0.25, 0.8); + drawPixi.drawTileRectangle( + camera, + topLeft, + bottomRight, + true, + 2, + 0x4cff00, + 0x2d9600, + 0.25, + 0.8 + ); } toggleable: boolean = false; @@ -320,7 +380,6 @@ export class SelectTool implements ITool toolGroup: number = 1; } -export interface IObsSelectionChanged -{ +export interface IObsSelectionChanged { selectionChanged(); } diff --git a/frontend/src/app/module-blueprint/common/tools/tool.ts b/frontend/src/app/module-blueprint/common/tools/tool.ts index b62715a1..dcd66379 100644 --- a/frontend/src/app/module-blueprint/common/tools/tool.ts +++ b/frontend/src/app/module-blueprint/common/tools/tool.ts @@ -1,15 +1,13 @@ import { CameraService, Vector2 } from "../../../../../../lib/index"; -import { DrawPixi } from '../../drawing/draw-pixi'; +import { DrawPixi } from "../../drawing/draw-pixi"; -export enum ToolType -{ - select, - build, - elementReport +export enum ToolType { + select, + build, + elementReport, } -export interface ITool -{ +export interface ITool { switchFrom(); switchTo(); @@ -30,10 +28,8 @@ export interface ITool captureInput: boolean; // Can this tool capture canvas mouse and keyboard input toolType: ToolType; // Each tool is aware of its nature toolGroup: number; // All tools with the same number are exclusive - } -export interface IChangeTool -{ +export interface IChangeTool { changeTool(toolType: ToolType); } diff --git a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.css b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.css index 2589f2a9..72635859 100644 --- a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.css +++ b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.css @@ -6,12 +6,12 @@ .side-panel-right { position: absolute; - right:0; + right: 0; padding: 10px; } .side-panel-about { position: absolute; - right:0; + right: 0; padding: 10px; height: 90vh; } @@ -19,4 +19,4 @@ .outer { display: flex; flex-flow: column; -} \ No newline at end of file +} diff --git a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.html b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.html index e19243c6..d2bdcbe1 100644 --- a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.html +++ b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.html @@ -1,21 +1,40 @@ - +
- +
- +
- + - +
@@ -25,11 +44,16 @@
- - + - + diff --git a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.spec.ts b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.spec.ts index 3021e811..bd7389d1 100644 --- a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.spec.ts +++ b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.spec.ts @@ -1,16 +1,15 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { async, ComponentFixture, TestBed } from "@angular/core/testing"; -import { ComponentBlueprintParentComponent } from './component-blueprint-parent.component'; +import { ComponentBlueprintParentComponent } from "./component-blueprint-parent.component"; -describe('ComponentBlueprintParentComponent', () => { +describe("ComponentBlueprintParentComponent", () => { let component: ComponentBlueprintParentComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ ComponentBlueprintParentComponent ] - }) - .compileComponents(); + declarations: [ComponentBlueprintParentComponent], + }).compileComponents(); })); beforeEach(() => { @@ -19,7 +18,7 @@ describe('ComponentBlueprintParentComponent', () => { fixture.detectChanges(); }); - it('should create', () => { + it("should create", () => { expect(component).toBeTruthy(); }); }); diff --git a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.ts b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.ts index 09ea4f09..d0279764 100644 --- a/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.ts +++ b/frontend/src/app/module-blueprint/components/component-blueprint-parent/component-blueprint-parent.component.ts @@ -1,26 +1,55 @@ -import { HttpClient } from '@angular/common/http'; -import { Component, ElementRef, OnInit, Renderer2, ViewChild } from '@angular/core'; +import { HttpClient } from "@angular/common/http"; +import { + Component, + ElementRef, + OnInit, + Renderer2, + ViewChild, +} from "@angular/core"; // Library imports -import { ActivatedRoute, Params, UrlSegment } from '@angular/router'; -import * as JSZip from 'jszip'; -import { MessageService } from 'primeng/api'; -import { } from 'sanitize-filename'; -import { BBuilding, Blueprint, BSpriteInfo, BSpriteModifier, BuildableElement, BuildMenuCategory, BuildMenuItem, CameraService, ImageSource, OniItem, Overlay, SpriteInfo, SpriteModifier, Vector2 } from '../../../../../../lib/index'; -import { ToolType } from '../../common/tools/tool'; -import { AuthenticationService } from '../../services/authentification-service'; -import { BlueprintService, ExportImageOptions, IObsBlueprintChanged } from '../../services/blueprint-service'; -import { GameStringService } from '../../services/game-string-service'; -import { ToolService } from '../../services/tool-service'; -import { ComponentCanvasComponent } from '../component-canvas/component-canvas.component'; -import { BrowseData, MenuCommand, MenuCommandType } from '../component-menu/component-menu.component'; -import { ComponentSaveDialogComponent } from '../dialogs/component-save-dialog/component-save-dialog.component'; -import { DialogAboutComponent } from '../dialogs/dialog-about/dialog-about.component'; -import { DialogBrowseComponent } from '../dialogs/dialog-browse/dialog-browse.component'; -import { DialogExportImagesComponent } from '../dialogs/dialog-export-images/dialog-export-images.component'; -import { DialogShareUrlComponent } from '../dialogs/dialog-share-url/dialog-share-url.component'; -import { ComponentSideBuildToolComponent } from '../side-bar/build-tool/build-tool.component'; -import { ComponentSideSelectionToolComponent } from '../side-bar/selection-tool/selection-tool.component'; -import { ComponentLoginDialogComponent } from '../user-auth/login-dialog/login-dialog.component'; +import { ActivatedRoute, Params, UrlSegment } from "@angular/router"; +import * as JSZip from "jszip"; +import { MessageService } from "primeng/api"; +import {} from "sanitize-filename"; +import { + BBuilding, + Blueprint, + BSpriteInfo, + BSpriteModifier, + BuildableElement, + BuildMenuCategory, + BuildMenuItem, + CameraService, + ImageSource, + OniItem, + Overlay, + SpriteInfo, + SpriteModifier, + Vector2, +} from "../../../../../../lib/index"; +import { ToolType } from "../../common/tools/tool"; +import { AuthenticationService } from "../../services/authentification-service"; +import { + BlueprintService, + ExportImageOptions, + IObsBlueprintChanged, +} from "../../services/blueprint-service"; +import { GameStringService } from "../../services/game-string-service"; +import { ToolService } from "../../services/tool-service"; +import { ComponentCanvasComponent } from "../component-canvas/component-canvas.component"; +import { + BrowseData, + MenuCommand, + MenuCommandType, +} from "../component-menu/component-menu.component"; +import { ComponentSaveDialogComponent } from "../dialogs/component-save-dialog/component-save-dialog.component"; +import { DialogAboutComponent } from "../dialogs/dialog-about/dialog-about.component"; +import { DialogBrowseComponent } from "../dialogs/dialog-browse/dialog-browse.component"; +import { DialogExportImagesComponent } from "../dialogs/dialog-export-images/dialog-export-images.component"; +import { DialogShareUrlComponent } from "../dialogs/dialog-share-url/dialog-share-url.component"; +import { ComponentSideBuildToolComponent } from "../side-bar/build-tool/build-tool.component"; +import { ComponentSideSelectionToolComponent } from "../side-bar/selection-tool/selection-tool.component"; +import { ComponentLoginDialogComponent } from "../user-auth/login-dialog/login-dialog.component"; var sanitize = require("sanitize-filename"); /* @@ -40,44 +69,44 @@ TODO Feature List before release : */ - @Component({ - selector: 'app-component-blueprint-parent', - templateUrl: './component-blueprint-parent.component.html', - styleUrls: ['./component-blueprint-parent.component.css'], - providers: [MessageService] + selector: "app-component-blueprint-parent", + templateUrl: "./component-blueprint-parent.component.html", + styleUrls: ["./component-blueprint-parent.component.css"], + providers: [MessageService], }) -export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintChanged { - - @ViewChild('canvas', { static: true }) +export class ComponentBlueprintParentComponent + implements OnInit, IObsBlueprintChanged +{ + @ViewChild("canvas", { static: true }) canvas: ComponentCanvasComponent; - @ViewChild('buildTool', { static: false }) + @ViewChild("buildTool", { static: false }) buildTool: ComponentSideBuildToolComponent; - @ViewChild('saveDialog', { static: false }) + @ViewChild("saveDialog", { static: false }) saveDialog: ComponentSaveDialogComponent; - @ViewChild('browseDialog', { static: false }) + @ViewChild("browseDialog", { static: false }) browseDialog: DialogBrowseComponent; - @ViewChild('loginDialog', { static: false }) + @ViewChild("loginDialog", { static: false }) loginDialog: ComponentLoginDialogComponent; - @ViewChild('exportImagesDialog', { static: false }) + @ViewChild("exportImagesDialog", { static: false }) exportImagesDialog: DialogExportImagesComponent; - @ViewChild('shareUrlDialog', { static: false }) + @ViewChild("shareUrlDialog", { static: false }) shareUrlDialog: DialogShareUrlComponent; - @ViewChild('aboutDialog') + @ViewChild("aboutDialog") aboutDialog: DialogAboutComponent; // The left ui panel is not static, because when in a iframe we don't load it - @ViewChild('sidePanelLeft', { static: false }) + @ViewChild("sidePanelLeft", { static: false }) sidePanelLeft: ElementRef; - @ViewChild('selectionTool', { static: false }) + @ViewChild("selectionTool", { static: false }) selectionTool: ComponentSideSelectionToolComponent; constructor( @@ -89,32 +118,29 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC private renderer: Renderer2, private http: HttpClient, public gameStringService: GameStringService - ) { - } + ) {} get showElementReport() { if (CameraService.cameraService == null) return false; - else return CameraService.cameraService.showElementReport + else return CameraService.cameraService.showElementReport; } get showTemperatureScale() { if (CameraService.cameraService == null) return false; - else return CameraService.cameraService.showTemperatureScale + else return CameraService.cameraService.showTemperatureScale; } forceSize: boolean = false; forcedSize: Vector2 = Vector2.zero(); ngOnInit() { - this.route.params.subscribe((params: Params): void => { let width = Number(params.width); let height = Number(params.height); if (Number.isInteger(width) && Number.isInteger(height)) { this.forceSize = true; this.forcedSize = new Vector2(width, height); - } - else this.forceSize = false; + } else this.forceSize = false; }); SpriteModifier.init(); @@ -128,27 +154,29 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC this.blueprintService.subscribeBlueprintChanged(this); this.fetchDatabase().then(() => { - if (!this.forceSize) { this.buildTool.oniItemsLoaded(); } this.route.url.subscribe((url: UrlSegment[]) => { - if (url != null && url.length > 0 && url[0].path == 'browse') { + if (url != null && url.length > 0 && url[0].path == "browse") { this.browseDialog.showDialog(); - } - else if (url != null && url.length > 0 && url[0].path == 'about') { + } else if (url != null && url.length > 0 && url[0].path == "about") { this.aboutDialog.visible = true; + } else if ( + url != null && + url.length > 1 && + url[0].path == "openfromurl" + ) { + this.blueprintService.loadUrlBlueprint(url[1].path); } - else if (url != null && url.length > 1 && url[0].path == 'openfromurl') { - this.blueprintService.loadUrlBlueprint(url[1].path) - } - }) + }); this.route.params.subscribe((params: Params): void => { - if (params.id != null) this.blueprintService.openBlueprintFromId(params.id); + if (params.id != null) + this.blueprintService.openBlueprintFromId(params.id); }); - })/* + }); /* .catch((error) => { this.messageService.add({ severity: 'error', @@ -158,17 +186,18 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC }); }); */ - this.renderer.listen('window', 'load', () => { + this.renderer.listen("window", "load", () => { this.resizeTools(); }); - this.renderer.listen('window', 'resize', () => { + this.renderer.listen("window", "resize", () => { this.resizeTools(); }); } resizeTools() { if (!this.forceSize) { - let sidePanelPosition: number = this.sidePanelLeft.nativeElement.getBoundingClientRect().y; + let sidePanelPosition: number = + this.sidePanelLeft.nativeElement.getBoundingClientRect().y; this.selectionTool.setMaxHeight(sidePanelPosition); } } @@ -180,60 +209,69 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC database: any; fetchDatabase(): Promise { let promise = new Promise((resolve, reject) => { - - // Start comment here - this.http.get("assets/database/database.zip", { responseType: "arraybuffer" }).subscribe(data => { - JSZip.loadAsync(data).then((zipped) => { - zipped.files['database.json'].async('text').then(async (text) => { - let json = JSON.parse(text); - - this.database = json; - - let elements: BuildableElement[] = json.elements; - for (const e of elements) { - const localizedName = await this.gameStringService.getStr(`STRINGS.ELEMENTS.${e.id.toUpperCase()}.NAME`); - if (!localizedName) console.warn(`Missing element translation`, e); - e.name = localizedName || e.name - } - BuildableElement.load(elements); - - let buildMenuCategories: BuildMenuCategory[] = json.buildMenuCategories; - for (const bm of buildMenuCategories) { - const localizedName = await this.gameStringService.getStr(`STRINGS.UI.BUILDCATEGORIES.${bm.categoryName.toUpperCase()}.NAME`); - if (!localizedName) console.warn(`Missing buildMenuCategory translation`, bm); - bm.categoryShowName = localizedName || bm.categoryName - } - BuildMenuCategory.load(buildMenuCategories); - - let buildMenuItems: BuildMenuItem[] = json.buildMenuItems; - BuildMenuItem.load(buildMenuItems); - - let uiSprites: BSpriteInfo[] = json.uiSprites; - SpriteInfo.load(uiSprites) - - let spriteModifiers: BSpriteModifier[] = json.spriteModifiers; - SpriteModifier.load(spriteModifiers); - - let buildings: BBuilding[] = json.buildings; - for (const b of buildings) { - const localizedName = await this.gameStringService.getStr(`STRINGS.BUILDINGS.PREFABS.${b.prefabId.toUpperCase()}.NAME`); - if (!localizedName) console.warn(`Missing building translation`, b); - b.name = localizedName - } - OniItem.load(buildings); - - resolve(0); - }) - - }) - .catch((error) => { - reject(error); - }); - }) + this.http + .get("assets/database/database.zip", { responseType: "arraybuffer" }) + .subscribe((data) => { + JSZip.loadAsync(data) + .then((zipped) => { + zipped.files["database.json"].async("text").then(async (text) => { + let json = JSON.parse(text); + + this.database = json; + + let elements: BuildableElement[] = json.elements; + for (const e of elements) { + const localizedName = await this.gameStringService.getStr( + `STRINGS.ELEMENTS.${e.id.toUpperCase()}.NAME` + ); + if (!localizedName) + console.warn(`Missing element translation`, e); + e.name = localizedName || e.name; + } + BuildableElement.load(elements); + + let buildMenuCategories: BuildMenuCategory[] = + json.buildMenuCategories; + for (const bm of buildMenuCategories) { + const localizedName = await this.gameStringService.getStr( + `STRINGS.UI.BUILDCATEGORIES.${bm.categoryName.toUpperCase()}.NAME` + ); + if (!localizedName) + console.warn(`Missing buildMenuCategory translation`, bm); + bm.categoryShowName = localizedName || bm.categoryName; + } + BuildMenuCategory.load(buildMenuCategories); + + let buildMenuItems: BuildMenuItem[] = json.buildMenuItems; + BuildMenuItem.load(buildMenuItems); + + let uiSprites: BSpriteInfo[] = json.uiSprites; + SpriteInfo.load(uiSprites); + + let spriteModifiers: BSpriteModifier[] = json.spriteModifiers; + SpriteModifier.load(spriteModifiers); + + let buildings: BBuilding[] = json.buildings; + for (const b of buildings) { + const localizedName = await this.gameStringService.getStr( + `STRINGS.BUILDINGS.PREFABS.${b.prefabId.toUpperCase()}.NAME` + ); + if (!localizedName) + console.warn(`Missing building translation`, b); + b.name = localizedName; + } + OniItem.load(buildings); + + resolve(0); + }); + }) + .catch((error) => { + reject(error); + }); + }); // End comment here - /* // Start comment here fetch("/assets/database/database.json") @@ -267,30 +305,41 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC }); // End comment here */ - }); return promise; } menuCommand(menuCommand: MenuCommand) { - if (menuCommand.type == MenuCommandType.newBlueprint) this.blueprintService.newBlueprint(); - else if (menuCommand.type == MenuCommandType.showLoginDialog) this.loginDialog.showDialog(); - else if (menuCommand.type == MenuCommandType.browseBlueprints) this.browseBlueprints(menuCommand.data); - else if (menuCommand.type == MenuCommandType.about) this.aboutDialog.toggleDialog(); - else if (menuCommand.type == MenuCommandType.getShareableUrl) this.shareUrl(); - else if (menuCommand.type == MenuCommandType.exportImages) this.exportImages(); - else if (menuCommand.type == MenuCommandType.saveBlueprint) this.saveBlueprint(); - else if (menuCommand.type == MenuCommandType.exportBlueprint) this.exportBlueprint(); - + if (menuCommand.type == MenuCommandType.newBlueprint) + this.blueprintService.newBlueprint(); + else if (menuCommand.type == MenuCommandType.showLoginDialog) + this.loginDialog.showDialog(); + else if (menuCommand.type == MenuCommandType.browseBlueprints) + this.browseBlueprints(menuCommand.data); + else if (menuCommand.type == MenuCommandType.about) + this.aboutDialog.toggleDialog(); + else if (menuCommand.type == MenuCommandType.getShareableUrl) + this.shareUrl(); + else if (menuCommand.type == MenuCommandType.exportImages) + this.exportImages(); + else if (menuCommand.type == MenuCommandType.saveBlueprint) + this.saveBlueprint(); + else if (menuCommand.type == MenuCommandType.exportBlueprint) + this.exportBlueprint(); // Technical (repack, generate solid sprites, etc) - else if (menuCommand.type == MenuCommandType.fetchIcons) this.canvas.fetchIcons(); - else if (menuCommand.type == MenuCommandType.downloadIcons) this.canvas.downloadIcons(); - else if (menuCommand.type == MenuCommandType.downloadGroups) this.canvas.downloadGroups(this.database); - else if (menuCommand.type == MenuCommandType.downloadUtility) this.canvas.downloadUtility(this.database); - else if (menuCommand.type == MenuCommandType.repackTextures) this.canvas.repackTextures(this.database); - else if (menuCommand.type == MenuCommandType.addElementsTiles) this.addElementsTiles(); - + else if (menuCommand.type == MenuCommandType.fetchIcons) + this.canvas.fetchIcons(); + else if (menuCommand.type == MenuCommandType.downloadIcons) + this.canvas.downloadIcons(); + else if (menuCommand.type == MenuCommandType.downloadGroups) + this.canvas.downloadGroups(this.database); + else if (menuCommand.type == MenuCommandType.downloadUtility) + this.canvas.downloadUtility(this.database); + else if (menuCommand.type == MenuCommandType.repackTextures) + this.canvas.repackTextures(this.database); + else if (menuCommand.type == MenuCommandType.addElementsTiles) + this.addElementsTiles(); } saveImages(exportOptions: ExportImageOptions) { @@ -304,23 +353,25 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC // TODO error handling this.messageService.add({ - severity: 'success', + severity: "success", summary: $localize`Loaded blueprint: ${this.blueprintService.name}`, detail: $localize`${template.blueprintItems.length} items loaded`, }); } saveBlueprint() { - if (!this.authService.isLoggedIn()) this.messageService.add({ - severity: 'error', - summary: $localize`Not logged in`, - detail: $localize`You must be logged in to be able to save blueprints`, - }); - else if (this.blueprintService.blueprint.blueprintItems.length == 0) this.messageService.add({ - severity: 'error', - summary: $localize`Empty blueprint`, - detail: $localize`Add some buildings before trying to save`, - }); + if (!this.authService.isLoggedIn()) + this.messageService.add({ + severity: "error", + summary: $localize`Not logged in`, + detail: $localize`You must be logged in to be able to save blueprints`, + }); + else if (this.blueprintService.blueprint.blueprintItems.length == 0) + this.messageService.add({ + severity: "error", + summary: $localize`Empty blueprint`, + detail: $localize`Add some buildings before trying to save`, + }); else { this.updateThumbnail(); this.saveDialog.showDialog(); @@ -328,21 +379,26 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC } exportBlueprint() { - if (this.blueprintService.blueprint.blueprintItems.length == 0) this.messageService.add({ - severity: 'error', - summary: $localize`Empty blueprint`, - detail: $localize`Add some buildings before trying to save`, - }); + if (this.blueprintService.blueprint.blueprintItems.length == 0) + this.messageService.add({ + severity: "error", + summary: $localize`Empty blueprint`, + detail: $localize`Add some buildings before trying to save`, + }); else { let friendlyname = "new blueprint"; - if (this.blueprintService.name != undefined) friendlyname = this.blueprintService.name; + if (this.blueprintService.name != undefined) + friendlyname = this.blueprintService.name; - let bniBlueprint = this.blueprintService.blueprint.toBniBlueprint(friendlyname); + let bniBlueprint = + this.blueprintService.blueprint.toBniBlueprint(friendlyname); - let a = document.createElement('a'); + let a = document.createElement("a"); document.body.append(a); - a.download = sanitize(friendlyname) + '.blueprint'; - a.href = URL.createObjectURL(new Blob([JSON.stringify(bniBlueprint)], {})); + a.download = sanitize(friendlyname) + ".blueprint"; + a.href = URL.createObjectURL( + new Blob([JSON.stringify(bniBlueprint)], {}) + ); a.click(); a.remove(); } @@ -353,27 +409,34 @@ export class ComponentBlueprintParentComponent implements OnInit, IObsBlueprintC } shareUrl() { - if (this.blueprintService.id == null) this.messageService.add({ - severity: 'error', - summary: $localize`Blueprint not saved`, - detail: $localize`Save this blueprint to share it with others` - }); + if (this.blueprintService.id == null) + this.messageService.add({ + severity: "error", + summary: $localize`Blueprint not saved`, + detail: $localize`Save this blueprint to share it with others`, + }); else this.shareUrlDialog.showDialog(); } browseBlueprints(data: any) { let browseData = data as BrowseData; - if (browseData != null) this.browseDialog.showDialog(browseData.filterUserId, browseData.filterUserName, browseData.getDuplicates); + if (browseData != null) + this.browseDialog.showDialog( + browseData.filterUserId, + browseData.filterUserName, + browseData.getDuplicates + ); else this.browseDialog.showDialog(); } // TODO toast on save and generate url also exportImages() { - if (this.blueprintService.blueprint.blueprintItems.length == 0) this.messageService.add({ - severity: 'error', - summary: $localize`Empty blueprint`, - detail: $localize`Add some buildings before trying to export images` - }); + if (this.blueprintService.blueprint.blueprintItems.length == 0) + this.messageService.add({ + severity: "error", + summary: $localize`Empty blueprint`, + detail: $localize`Add some buildings before trying to export images`, + }); else this.exportImagesDialog.showDialog(); } diff --git a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.css b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.css index 045ed02c..a643c9d8 100644 --- a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.css +++ b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.css @@ -2,4 +2,4 @@ background-color: black; position: absolute; z-index: -1; -} \ No newline at end of file +} diff --git a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.html b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.html index 84c4dd47..d51e7fb1 100644 --- a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.html +++ b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.html @@ -1,8 +1,20 @@ - - + Your browser does not support canvas. - diff --git a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.spec.ts b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.spec.ts index 2f374abe..2464f646 100644 --- a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.spec.ts +++ b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.spec.ts @@ -1,16 +1,15 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { async, ComponentFixture, TestBed } from "@angular/core/testing"; -import { ComponentCanvasComponent } from './component-canvas.component'; +import { ComponentCanvasComponent } from "./component-canvas.component"; -describe('ComponentCanvasComponent', () => { +describe("ComponentCanvasComponent", () => { let component: ComponentCanvasComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ ComponentCanvasComponent ] - }) - .compileComponents(); + declarations: [ComponentCanvasComponent], + }).compileComponents(); })); beforeEach(() => { @@ -19,7 +18,7 @@ describe('ComponentCanvasComponent', () => { fixture.detectChanges(); }); - it('should create', () => { + it("should create", () => { expect(component).toBeTruthy(); }); }); diff --git a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.ts b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.ts index 8b61f4ed..5d63b0c4 100644 --- a/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.ts +++ b/frontend/src/app/module-blueprint/components/component-canvas/component-canvas.component.ts @@ -1,41 +1,72 @@ // Angular imports -import { Component, OnInit, OnDestroy, ViewChild, ElementRef, NgZone, Output, EventEmitter, HostListener, Pipe, Input } from '@angular/core'; +import { + Component, + OnInit, + OnDestroy, + ViewChild, + ElementRef, + NgZone, + Output, + EventEmitter, + HostListener, + Pipe, + Input, +} from "@angular/core"; //import { Http, Response } from "@angular/http" -import { HttpClientModule, HttpClient } from '@angular/common/http'; +import { HttpClientModule, HttpClient } from "@angular/common/http"; // Engine imports -import { Blueprint, IObsBlueprintChange, CameraService, IObsCameraChanged, SpriteInfo, DrawHelpers, ImageSource, OniItem, SpriteModifier, Overlay, Display, BExport, BSpriteInfo, BSpriteModifier, Vector2, SpriteTag } from '../../../../../../lib/index' +import { + Blueprint, + IObsBlueprintChange, + CameraService, + IObsCameraChanged, + SpriteInfo, + DrawHelpers, + ImageSource, + OniItem, + SpriteModifier, + Overlay, + Display, + BExport, + BSpriteInfo, + BSpriteModifier, + Vector2, + SpriteTag, +} from "../../../../../../lib/index"; // PrimeNg imports -import { ComponentSideSelectionToolComponent } from '../side-bar/selection-tool/selection-tool.component'; -import { DrawPixi } from '../../drawing/draw-pixi'; -import { DrawMiniUi } from '../../drawing/draw-mini-ui'; -import * as JSZip from 'jszip'; -import { BlueprintService, ExportImageOptions } from '../../services/blueprint-service'; -import { ToolService } from '../../services/tool-service'; -import { read } from 'fs'; - -import { } from 'pixi.js-legacy'; -declare var PIXI: any; - +import { ComponentSideSelectionToolComponent } from "../side-bar/selection-tool/selection-tool.component"; +import { DrawPixi } from "../../drawing/draw-pixi"; +import { DrawMiniUi } from "../../drawing/draw-mini-ui"; +import * as JSZip from "jszip"; +import { + BlueprintService, + ExportImageOptions, +} from "../../services/blueprint-service"; +import { ToolService } from "../../services/tool-service"; +import { read } from "fs"; + +import {} from "pixi.js-legacy"; +declare var PIXI: any; @Component({ - selector: 'app-component-canvas', - templateUrl: './component-canvas.component.html', - styleUrls: ['./component-canvas.component.css'] + selector: "app-component-canvas", + templateUrl: "./component-canvas.component.html", + styleUrls: ["./component-canvas.component.css"], }) -export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraChanged { - +export class ComponentCanvasComponent + implements OnInit, OnDestroy, IObsCameraChanged +{ width: number; height: number; debug: any; - - @ViewChild('blueprintCanvas', {static: true}) + @ViewChild("blueprintCanvas", { static: true }) canvasRef: ElementRef; - @ViewChild('divCalcHeight', {static: true}) + @ViewChild("divCalcHeight", { static: true }) divCalcHeight: ElementRef; @Input() @@ -43,17 +74,18 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh @Input() forcedSize: Vector2; - drawPixi: DrawPixi; - private cameraService: CameraService + private cameraService: CameraService; - public get blueprint() { return this.blueprintService.blueprint; } + public get blueprint() { + return this.blueprintService.blueprint; + } constructor( private ngZone: NgZone, private blueprintService: BlueprintService, - private toolService: ToolService) { - + private toolService: ToolService + ) { this.drawPixi = new DrawPixi(); this.cameraService = new CameraService(this.drawPixi.getNewContainer()); this.cameraService.subscribeCameraChange(this); @@ -75,7 +107,6 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh miniUi.init(this.drawPixi.pixiApp.stage); this.cameraService.subscribeCameraChange(miniUi); } - }); //this.drawAbstraction.Init(this.canvasRef, this) @@ -85,8 +116,7 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh this.running = false; } - public loadNewBlueprint(source: Blueprint) - { + public loadNewBlueprint(source: Blueprint) { // TODO make sure nothing creates a "real blueprint" before this // TODO fixme this.blueprint.destroyAndCopyItems(source); @@ -95,26 +125,35 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh //let cameraOffset = new Vector2(-topLeft.x + 1, bottomRight.y + 1); let rect = this.canvasRef.nativeElement.getBoundingClientRect(); - this.cameraService.resetZoom(new Vector2( - rect.width - rect.left, - rect.height - rect.top - )); + this.cameraService.resetZoom( + new Vector2(rect.width - rect.left, rect.height - rect.top) + ); if (source.blueprintItems.length > 0) { let boundingBox = this.blueprint.getBoundingBox(); let topLeft = boundingBox[0]; let bottomRight = boundingBox[1]; - let totalTileSize = new Vector2(bottomRight.x - topLeft.x + 3, bottomRight.y - topLeft.y + 3); + let totalTileSize = new Vector2( + bottomRight.x - topLeft.x + 3, + bottomRight.y - topLeft.y + 3 + ); let maxTotalSize = Math.max(totalTileSize.x, totalTileSize.y); - let minCanvasSize = Math.min(this.canvasRef.nativeElement.width, this.canvasRef.nativeElement.height); + let minCanvasSize = Math.min( + this.canvasRef.nativeElement.width, + this.canvasRef.nativeElement.height + ); let thumbnailTileSize = minCanvasSize / maxTotalSize; this.cameraService.cameraOffset.x = -topLeft.x + 1; this.cameraService.cameraOffset.y = bottomRight.y + 1; // (add 2 instead of 1, one tile will probably be hidden by the menu) - if (totalTileSize.x > totalTileSize.y) this.cameraService.cameraOffset.y += totalTileSize.x / 2 - totalTileSize.y / 2; - if (totalTileSize.y > totalTileSize.x) this.cameraService.cameraOffset.x += totalTileSize.y / 2 - totalTileSize.x / 2; + if (totalTileSize.x > totalTileSize.y) + this.cameraService.cameraOffset.y += + totalTileSize.x / 2 - totalTileSize.y / 2; + if (totalTileSize.y > totalTileSize.x) + this.cameraService.cameraOffset.x += + totalTileSize.y / 2 - totalTileSize.x / 2; this.cameraService.setHardZoom(thumbnailTileSize); } @@ -125,9 +164,10 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh return new Vector2(event.clientX - rect.left, event.clientY - rect.top); } - getCurrentTile(event): Vector2 - { - let returnValue = this.cameraService.getTileCoords(this.getCursorPosition(event)); + getCurrentTile(event): Vector2 { + let returnValue = this.cameraService.getTileCoords( + this.getCursorPosition(event) + ); returnValue.x = Math.floor(returnValue.x); returnValue.y = Math.ceil(returnValue.y); @@ -135,21 +175,17 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh return returnValue; } - mouseWheel(event: any) - { + mouseWheel(event: any) { this.cameraService.zoom(event.delta, this.getCursorPosition(event)); } - mouseUp(event: any) - { - if (event.button == 0) - { + mouseUp(event: any) { + if (event.button == 0) { this.storePreviousTileFloat = null; } } - mouseDown(event: any) - { + mouseDown(event: any) { if (event.button == 0) { this.toolService.mouseDown(this.getCurrentTile(event)); } @@ -159,38 +195,39 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh this.toolService.mouseOut(); } - mouseClick(event: any) - { + mouseClick(event: any) { // Don't send the clicks to the tools if we are in an iframe if (!this.forceSize) { - if (event.button == 0) this.toolService.leftClick(this.getCurrentTile(event)); - else if (event.button == 2) this.toolService.rightClick(this.getCurrentTile(event)); + if (event.button == 0) + this.toolService.leftClick(this.getCurrentTile(event)); + else if (event.button == 2) + this.toolService.rightClick(this.getCurrentTile(event)); } } storePreviousTileFloat: Vector2; - mouseDrag(event: any) - { + mouseDrag(event: any) { let previousTileFloat = Vector2.clone(this.storePreviousTileFloat); - let currentTileFloat = this.cameraService.getTileCoords(this.getCursorPosition(event)); + let currentTileFloat = this.cameraService.getTileCoords( + this.getCursorPosition(event) + ); - if (event.dragButton[2]) - { + if (event.dragButton[2]) { //console.log('camera drag'); - this.cameraService.cameraOffset.x += event.dragX / this.cameraService.currentZoom; - this.cameraService.cameraOffset.y += event.dragY / this.cameraService.currentZoom; - } - else if (event.dragButton[0]) - { + this.cameraService.cameraOffset.x += + event.dragX / this.cameraService.currentZoom; + this.cameraService.cameraOffset.y += + event.dragY / this.cameraService.currentZoom; + } else if (event.dragButton[0]) { // Don't send the clicks to the tools if we are in an iframe - if (!this.forceSize) this.toolService.drag(previousTileFloat, currentTileFloat); + if (!this.forceSize) + this.toolService.drag(previousTileFloat, currentTileFloat); } this.storePreviousTileFloat = Vector2.clone(currentTileFloat); } - mouseStopDrag(event: any) - { + mouseStopDrag(event: any) { this.storePreviousTileFloat = null; this.toolService.dragStop(); } @@ -198,57 +235,56 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh // previousMouse is used by the keyboard zoom previousMouse: Vector2 = new Vector2(); previousTileUnderMouse: Vector2; - mouseMove(event: any) - { - this.previousMouse = this.getCursorPosition(event) + mouseMove(event: any) { + this.previousMouse = this.getCursorPosition(event); let currentTileUnderMouse = this.getCurrentTile(event); - if (this.previousTileUnderMouse == null || !this.previousTileUnderMouse.equals(currentTileUnderMouse)) + if ( + this.previousTileUnderMouse == null || + !this.previousTileUnderMouse.equals(currentTileUnderMouse) + ) this.toolService.hover(currentTileUnderMouse); this.previousTileUnderMouse = currentTileUnderMouse; - } - - keyPress(event: any) - { + keyPress(event: any) { //console.log(event.key) this.toolService.keyDown(event.key); if (document.body == document.activeElement) { - if (event.key == 'ArrowLeft') this.cameraService.cameraOffset.x += 1; - if (event.key == 'ArrowRight') this.cameraService.cameraOffset.x -= 1; - if (event.key == 'ArrowUp') this.cameraService.cameraOffset.y += 1; - if (event.key == 'ArrowDown') this.cameraService.cameraOffset.y -= 1; - if (event.key == '+') this.cameraService.zoom(1, this.previousMouse); - if (event.key == '-') this.cameraService.zoom(-1, this.previousMouse); + if (event.key == "ArrowLeft") this.cameraService.cameraOffset.x += 1; + if (event.key == "ArrowRight") this.cameraService.cameraOffset.x -= 1; + if (event.key == "ArrowUp") this.cameraService.cameraOffset.y += 1; + if (event.key == "ArrowDown") this.cameraService.cameraOffset.y -= 1; + if (event.key == "+") this.cameraService.zoom(1, this.previousMouse); + if (event.key == "-") this.cameraService.zoom(-1, this.previousMouse); } - if (event.key == 'z' && event.ctrlKey) this.blueprintService.undo(); - if (event.key == 'y' && event.ctrlKey) this.blueprintService.redo(); + if (event.key == "z" && event.ctrlKey) this.blueprintService.undo(); + if (event.key == "y" && event.ctrlKey) this.blueprintService.redo(); //this.canvasRef.nativeElement.click(); } - prepareOverlayInfo() - { - if (this.blueprint != null) this.blueprint.prepareOverlayInfo(this.cameraService.overlay); + prepareOverlayInfo() { + if (this.blueprint != null) + this.blueprint.prepareOverlayInfo(this.cameraService.overlay); } /* * * Sprite repackaging * - */ - fetchIcons() - { - for (let k of ImageSource.keys) ImageSource.getBaseTexture(k, this.drawPixi); - for (let k of SpriteInfo.keys) SpriteInfo.getSpriteInfo(k).getTexture(this.drawPixi); + */ + fetchIcons() { + for (let k of ImageSource.keys) + ImageSource.getBaseTexture(k, this.drawPixi); + for (let k of SpriteInfo.keys) + SpriteInfo.getSpriteInfo(k).getTexture(this.drawPixi); } - downloadUtility(database: BExport) - { + downloadUtility(database: BExport) { let allWhiteFilter = new PIXI.filters.ColorMatrixFilter(); // 1 1 1 0 1 // 1 1 1 0 1 @@ -267,18 +303,24 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh allWhiteFilter.matrix[12] = 1; allWhiteFilter.matrix[14] = 1; - let sourceSpriteModifiers = database.spriteModifiers.filter((s) => { return s.tags.indexOf(SpriteTag.solid) != -1; }) + let sourceSpriteModifiers = database.spriteModifiers.filter((s) => { + return s.tags.indexOf(SpriteTag.solid) != -1; + }); let sourceTextures: string[] = []; for (let sourceSpriteModifier of sourceSpriteModifiers) { - let sourceSpriteInfo = database.uiSprites.find((s) => { return s.name == sourceSpriteModifier.spriteInfoName; }) + let sourceSpriteInfo = database.uiSprites.find((s) => { + return s.name == sourceSpriteModifier.spriteInfoName; + }); - if (sourceTextures.indexOf(sourceSpriteInfo.textureName) == -1) sourceTextures.push(sourceSpriteInfo.textureName); + if (sourceTextures.indexOf(sourceSpriteInfo.textureName) == -1) + sourceTextures.push(sourceSpriteInfo.textureName); let spriteModifierWhite = BSpriteModifier.clone(sourceSpriteModifier); - spriteModifierWhite.name = spriteModifierWhite.name + '_white'; - spriteModifierWhite.spriteInfoName = spriteModifierWhite.spriteInfoName + '_white'; + spriteModifierWhite.name = spriteModifierWhite.name + "_white"; + spriteModifierWhite.spriteInfoName = + spriteModifierWhite.spriteInfoName + "_white"; spriteModifierWhite.tags.push(SpriteTag.white); database.spriteModifiers.push(spriteModifierWhite); @@ -289,29 +331,39 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh if (spriteInfoWhite != null) { spriteInfoWhite.name = spriteModifierWhite.spriteInfoName; - spriteInfoWhite.textureName = spriteInfoWhite.textureName + '_white'; - database.uiSprites.push(spriteInfoWhite) + spriteInfoWhite.textureName = spriteInfoWhite.textureName + "_white"; + database.uiSprites.push(spriteInfoWhite); } for (let building of database.buildings) - if (building.sprites.spriteNames.indexOf(sourceSpriteModifier.name) != -1) + if ( + building.sprites.spriteNames.indexOf(sourceSpriteModifier.name) != -1 + ) building.sprites.spriteNames.push(spriteModifierWhite.name); } ComponentCanvasComponent.zip = new JSZip(); ComponentCanvasComponent.nbBlob = 0; - ComponentCanvasComponent.downloadFile = 'solidSprites.zip'; + ComponentCanvasComponent.downloadFile = "solidSprites.zip"; ComponentCanvasComponent.nbBlobMax = sourceTextures.length; - ComponentCanvasComponent.zip.file('database_white.json', JSON.stringify(database, null, 2)); + ComponentCanvasComponent.zip.file( + "database_white.json", + JSON.stringify(database, null, 2) + ); - for (let sourceTexture of sourceTextures) - { - let baseTexture = ImageSource.getBaseTexture(sourceTexture, this.drawPixi); + for (let sourceTexture of sourceTextures) { + let baseTexture = ImageSource.getBaseTexture( + sourceTexture, + this.drawPixi + ); let texture = new PIXI.Texture(baseTexture); - let brt = new PIXI.BaseRenderTexture({width: texture.width, height: texture.height}); + let brt = new PIXI.BaseRenderTexture({ + width: texture.width, + height: texture.height, + }); let rt = new PIXI.RenderTexture(brt); let sprite = PIXI.Sprite.from(texture); @@ -319,31 +371,32 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh this.drawPixi.pixiApp.renderer.render(sprite, rt); - this.drawPixi.pixiApp.renderer.extract.canvas(rt).toBlob((b) => - { - this.addBlob(b, sourceTexture + '_white.png'); - }, 'image/png'); + this.drawPixi.pixiApp.renderer.extract.canvas(rt).toBlob((b) => { + this.addBlob(b, sourceTexture + "_white.png"); + }, "image/png"); } } downloadGroups(database: BExport) { - console.log('downloadGroups') + console.log("downloadGroups"); let renderTextures: PIXI.RenderTexture[] = []; let textureNames: string[] = []; for (let oniItem of OniItem.oniItems) { - - let buildingInDatabase = database.buildings.find((building) => { return building.prefabId == oniItem.id }); + let buildingInDatabase = database.buildings.find((building) => { + return building.prefabId == oniItem.id; + }); let spritesToGroup: SpriteModifier[] = []; for (let spriteModifier of oniItem.spriteGroup.spriteModifiers) { - if (spriteModifier == undefined) console.log(oniItem); - if (spriteModifier.tags.indexOf(SpriteTag.solid) != -1 && - spriteModifier.tags.indexOf(SpriteTag.tileable) == -1 && - spriteModifier.tags.indexOf(SpriteTag.connection) == -1) + if ( + spriteModifier.tags.indexOf(SpriteTag.solid) != -1 && + spriteModifier.tags.indexOf(SpriteTag.tileable) == -1 && + spriteModifier.tags.indexOf(SpriteTag.connection) == -1 + ) spritesToGroup.push(spriteModifier); } @@ -351,46 +404,58 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh let container: PIXI.Container = new PIXI.Container(); container.sortableChildren = true; - let modifierId = oniItem.id + '_group_modifier'; - let spriteInfoId = oniItem.id + '_group_sprite'; - let textureName = oniItem.id + '_group_sprite' + let modifierId = oniItem.id + "_group_modifier"; + let spriteInfoId = oniItem.id + "_group_sprite"; + let textureName = oniItem.id + "_group_sprite"; let indexDrawPart = 0; for (let spriteModifier of oniItem.spriteGroup.spriteModifiers) { - - if (spriteModifier.tags.indexOf(SpriteTag.solid) == -1 || + if ( + spriteModifier.tags.indexOf(SpriteTag.solid) == -1 || spriteModifier.tags.indexOf(SpriteTag.tileable) != -1 || - spriteModifier.tags.indexOf(SpriteTag.connection) != -1) continue; + spriteModifier.tags.indexOf(SpriteTag.connection) != -1 + ) + continue; // Remove from the database building sprite list - let indexToRemove = buildingInDatabase.sprites.spriteNames.indexOf(spriteModifier.spriteModifierId); + let indexToRemove = buildingInDatabase.sprites.spriteNames.indexOf( + spriteModifier.spriteModifierId + ); buildingInDatabase.sprites.spriteNames.splice(indexToRemove, 1); // Then from the sprite modifiers - let spriteModifierToRemove = database.spriteModifiers.find((s) => { return s.name == spriteModifier.spriteModifierId; }) + let spriteModifierToRemove = database.spriteModifiers.find((s) => { + return s.name == spriteModifier.spriteModifierId; + }); if (spriteModifierToRemove != null) { - indexToRemove = database.spriteModifiers.indexOf(spriteModifierToRemove); + indexToRemove = database.spriteModifiers.indexOf( + spriteModifierToRemove + ); database.spriteModifiers.splice(indexToRemove, 1); } - let spriteInfoToRemove = database.uiSprites.find((s) => { return s.name == spriteModifier.spriteInfoName }); + let spriteInfoToRemove = database.uiSprites.find((s) => { + return s.name == spriteModifier.spriteInfoName; + }); if (spriteInfoToRemove != null) { indexToRemove = database.uiSprites.indexOf(spriteInfoToRemove); database.uiSprites.splice(indexToRemove, 1); } - let spriteInfo = SpriteInfo.getSpriteInfo(spriteModifier.spriteInfoName); + let spriteInfo = SpriteInfo.getSpriteInfo( + spriteModifier.spriteInfoName + ); let texture = spriteInfo.getTexture(this.drawPixi); let sprite = PIXI.Sprite.from(texture); - sprite.anchor.set(spriteInfo.pivot.x, 1-spriteInfo.pivot.y); - sprite.x = 0 + (spriteModifier.translation.x); - sprite.y = 0 - (spriteModifier.translation.y); + sprite.anchor.set(spriteInfo.pivot.x, 1 - spriteInfo.pivot.y); + sprite.x = 0 + spriteModifier.translation.x; + sprite.y = 0 - spriteModifier.translation.y; sprite.width = spriteInfo.realSize.x; sprite.height = spriteInfo.realSize.y; sprite.scale.x = spriteModifier.scale.x; sprite.scale.y = spriteModifier.scale.y; sprite.angle = -spriteModifier.rotation; - sprite.zIndex -= (indexDrawPart / 50) + sprite.zIndex -= indexDrawPart / 50; container.addChild(sprite); @@ -399,8 +464,6 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh buildingInDatabase.sprites.spriteNames.push(modifierId); - - container.calculateBounds(); let bounds = container.getBounds(); bounds.x = Math.floor(bounds.x); @@ -411,19 +474,26 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh let diff = new Vector2(bounds.x, bounds.y); for (let child of container.children) { child.x -= diff.x; - child.y -= diff.y + child.y -= diff.y; } - let pivot = new Vector2(1 - ((bounds.width + bounds.x) / bounds.width), ((bounds.height + bounds.y) / bounds.height)); + let pivot = new Vector2( + 1 - (bounds.width + bounds.x) / bounds.width, + (bounds.height + bounds.y) / bounds.height + ); //console.log(pivot); - let brt = new PIXI.BaseRenderTexture({width: bounds.width, height: bounds.height, scaleMode: PIXI.SCALE_MODES.NEAREST}); + let brt = new PIXI.BaseRenderTexture({ + width: bounds.width, + height: bounds.height, + scaleMode: PIXI.SCALE_MODES.NEAREST, + }); let rt = new PIXI.RenderTexture(brt); this.drawPixi.pixiApp.renderer.render(container, rt); renderTextures.push(rt); - textureNames.push(textureName) + textureNames.push(textureName); // Create and add the new sprite modifier to replace the group let newSpriteModifier = new BSpriteModifier(); @@ -444,26 +514,28 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh newSpriteInfo.realSize = new Vector2(bounds.width, bounds.height); newSpriteInfo.uvSize = new Vector2(bounds.width, bounds.height); database.uiSprites.push(newSpriteInfo); - } - else console.log(oniItem.id + ' should not be grouped') - + } else console.log(oniItem.id + " should not be grouped"); } ComponentCanvasComponent.zip = new JSZip(); ComponentCanvasComponent.nbBlob = 0; - ComponentCanvasComponent.downloadFile = 'solidGroups.zip'; + ComponentCanvasComponent.downloadFile = "solidGroups.zip"; ComponentCanvasComponent.nbBlobMax = renderTextures.length; - ComponentCanvasComponent.zip.file('database_groups.json', JSON.stringify(database, null, 2)); - - for (let indexRt = 0; indexRt < renderTextures.length; indexRt++) this.drawPixi.pixiApp.renderer.extract.canvas(renderTextures[indexRt]).toBlob((b) => - { - this.addBlob(b, textureNames[indexRt] + '.png'); - }, 'image/png'); + ComponentCanvasComponent.zip.file( + "database_groups.json", + JSON.stringify(database, null, 2) + ); + + for (let indexRt = 0; indexRt < renderTextures.length; indexRt++) + this.drawPixi.pixiApp.renderer.extract + .canvas(renderTextures[indexRt]) + .toBlob((b) => { + this.addBlob(b, textureNames[indexRt] + ".png"); + }, "image/png"); } - repackTextures(database: any) - { + repackTextures(database: any) { /* // Tests bintrays let traySize = 1024; @@ -478,7 +550,7 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh binController.addItem('test_2', new Vector2(10, 50), bleed); binController.addItem('test_3', new Vector2(10, 50), bleed); */ -/* + /* // First, we clone the existing spriteInfos into a new array : let newSpriteInfos: BSpriteInfo[] = []; @@ -550,21 +622,22 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh */ } - downloadIcons() - { - + downloadIcons() { ComponentCanvasComponent.zip = new JSZip(); ComponentCanvasComponent.nbBlob = 0; - ComponentCanvasComponent.downloadFile = 'icons.zip'; - ComponentCanvasComponent.nbBlobMax = SpriteInfo.keys.filter(s => SpriteInfo.getSpriteInfo(s).isIcon).length; - - for (let k of SpriteInfo.keys.filter(s => SpriteInfo.getSpriteInfo(s).isIcon)) - { + ComponentCanvasComponent.downloadFile = "icons.zip"; + ComponentCanvasComponent.nbBlobMax = SpriteInfo.keys.filter( + (s) => SpriteInfo.getSpriteInfo(s).isIcon + ).length; + + for (let k of SpriteInfo.keys.filter( + (s) => SpriteInfo.getSpriteInfo(s).isIcon + )) { let uiSpriteInfo = SpriteInfo.getSpriteInfo(k); let texture = uiSpriteInfo.getTexture(this.drawPixi); - let uiSprite =  PIXI.Sprite.from(texture); + let uiSprite = PIXI.Sprite.from(texture); - let size = Math.max(texture.width, texture.height) + let size = Math.max(texture.width, texture.height); let container = new PIXI.Container(); container.addChild(uiSprite); @@ -572,16 +645,22 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh uiSprite.x = 0; uiSprite.y = 0; - if (texture.width > texture.height) uiSprite.y += (texture.width / 2 - texture.height / 2); - if (texture.height > texture.width) uiSprite.x += (texture.height / 2 - texture.width / 2); + if (texture.width > texture.height) + uiSprite.y += texture.width / 2 - texture.height / 2; + if (texture.height > texture.width) + uiSprite.x += texture.height / 2 - texture.width / 2; - let brt = new PIXI.BaseRenderTexture({width: size, height: size, scaleMode: PIXI.SCALE_MODES.LINEAR}); + let brt = new PIXI.BaseRenderTexture({ + width: size, + height: size, + scaleMode: PIXI.SCALE_MODES.LINEAR, + }); let rt = new PIXI.RenderTexture(brt); this.drawPixi.pixiApp.renderer.render(container, rt, true); this.drawPixi.pixiApp.renderer.extract.canvas(rt).toBlob((blob) => { - this.addBlob(blob, k + '.png'); - }, 'image/png'); + this.addBlob(blob, k + ".png"); + }, "image/png"); } } @@ -589,47 +668,50 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh private static nbBlobMax: number; private static nbBlob: number; private static zip: JSZip; - addBlob(blob: Blob, filename: string) - { - + addBlob(blob: Blob, filename: string) { ComponentCanvasComponent.nbBlob++; ComponentCanvasComponent.zip.file(filename, blob); - if (ComponentCanvasComponent.nbBlob == ComponentCanvasComponent.nbBlobMax) - { - console.log('last blob arrived!'); - ComponentCanvasComponent.zip.generateAsync({type:"blob"}).then(function (blob) { - let a = document.createElement('a'); - document.body.append(a); - a.download = ComponentCanvasComponent.downloadFile; - a.href = URL.createObjectURL(blob); - a.click(); - a.remove(); - }); + if (ComponentCanvasComponent.nbBlob == ComponentCanvasComponent.nbBlobMax) { + console.log("last blob arrived!"); + ComponentCanvasComponent.zip + .generateAsync({ type: "blob" }) + .then(function (blob) { + let a = document.createElement("a"); + document.body.append(a); + a.download = ComponentCanvasComponent.downloadFile; + a.href = URL.createObjectURL(blob); + a.click(); + a.remove(); + }); } } updateThumbnail() { - //console.log('updateThumbnail') this.blueprintService.thumbnail = null; - let clone = this.blueprint.clone(); - if (clone.blueprintItems.length == 0) throw new Error('No buildings to export') + if (clone.blueprintItems.length == 0) + throw new Error("No buildings to export"); let boundingBox = clone.getBoundingBox(); let topLeft = boundingBox[0]; let bottomRight = boundingBox[1]; - let totalTileSize = new Vector2(bottomRight.x - topLeft.x + 3, bottomRight.y - topLeft.y + 3); + let totalTileSize = new Vector2( + bottomRight.x - topLeft.x + 3, + bottomRight.y - topLeft.y + 3 + ); let thumbnailSize = 200; let maxTotalSize = Math.max(totalTileSize.x, totalTileSize.y); let thumbnailTileSize = thumbnailSize / maxTotalSize; let cameraOffset = new Vector2(-topLeft.x + 1, bottomRight.y + 1); - if (totalTileSize.x > totalTileSize.y) cameraOffset.y += totalTileSize.x / 2 - totalTileSize.y / 2; - if (totalTileSize.y > totalTileSize.x) cameraOffset.x += totalTileSize.y / 2 - totalTileSize.x / 2; + if (totalTileSize.x > totalTileSize.y) + cameraOffset.y += totalTileSize.x / 2 - totalTileSize.y / 2; + if (totalTileSize.y > totalTileSize.x) + cameraOffset.x += totalTileSize.y / 2 - totalTileSize.x / 2; let exportCamera = new CameraService(this.drawPixi.getNewContainer()); exportCamera.setHardZoom(thumbnailTileSize); @@ -651,13 +733,19 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh item.drawPixi(exportCamera, this.drawPixi); }); - let brt = new PIXI.BaseRenderTexture({width: thumbnailSize, height: thumbnailSize, scaleMode: PIXI.SCALE_MODES.LINEAR}); + let brt = new PIXI.BaseRenderTexture({ + width: thumbnailSize, + height: thumbnailSize, + scaleMode: PIXI.SCALE_MODES.LINEAR, + }); let rt = new PIXI.RenderTexture(brt); this.drawPixi.pixiApp.renderer.render(exportCamera.container, rt, false); this.drawPixi.pixiApp.renderer.extract.canvas(rt).toBlob((blob) => { let reader = new FileReader(); - reader.onload = () => { this.blueprintService.thumbnail = reader.result as string; }; + reader.onload = () => { + this.blueprintService.thumbnail = reader.result as string; + }; reader.readAsDataURL(blob); /* @@ -674,16 +762,23 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh saveImages(exportOptions: ExportImageOptions) { let clone = this.blueprint.clone(); - if (clone.blueprintItems.length == 0) throw new Error('No buildings to export') + if (clone.blueprintItems.length == 0) + throw new Error("No buildings to export"); let boundingBox = clone.getBoundingBox(); let topLeft = boundingBox[0]; let bottomRight = boundingBox[1]; let tileSize = exportOptions.pixelsPerTile; - let totalTileSize = new Vector2(bottomRight.x - topLeft.x + 3, bottomRight.y - topLeft.y + 3); - console.log(totalTileSize) - let sizeInPixels = new Vector2(totalTileSize.x * tileSize, totalTileSize.y * tileSize) + let totalTileSize = new Vector2( + bottomRight.x - topLeft.x + 3, + bottomRight.y - topLeft.y + 3 + ); + console.log(totalTileSize); + let sizeInPixels = new Vector2( + totalTileSize.x * tileSize, + totalTileSize.y * tileSize + ); let exportCamera = new CameraService(this.drawPixi.getNewContainer()); exportCamera.setHardZoom(tileSize); @@ -695,17 +790,16 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh exportCamera.container.addChild(graphics); // TODO color in parameter - graphics.beginFill(0x007AD9); + graphics.beginFill(0x007ad9); graphics.drawRect(0, 0, sizeInPixels.x, sizeInPixels.y); graphics.endFill(); ComponentCanvasComponent.zip = new JSZip(); ComponentCanvasComponent.nbBlob = 0; - ComponentCanvasComponent.downloadFile = 'export.zip'; + ComponentCanvasComponent.downloadFile = "export.zip"; ComponentCanvasComponent.nbBlobMax = exportOptions.selectedOverlays.length; exportOptions.selectedOverlays.map((overlay) => { - exportCamera.overlay = overlay; clone.blueprintItems.map((item) => { @@ -713,21 +807,25 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh item.drawPixi(exportCamera, this.drawPixi); }); - let brt = new PIXI.BaseRenderTexture({width: sizeInPixels.x, height: sizeInPixels.y, scaleMode: PIXI.SCALE_MODES.LINEAR}); + let brt = new PIXI.BaseRenderTexture({ + width: sizeInPixels.x, + height: sizeInPixels.y, + scaleMode: PIXI.SCALE_MODES.LINEAR, + }); let rt = new PIXI.RenderTexture(brt); this.drawPixi.pixiApp.renderer.render(exportCamera.container, rt, false); this.drawPixi.pixiApp.renderer.extract.canvas(rt).toBlob((blob) => { - this.addBlob(blob, 'export_' + DrawHelpers.overlayString[overlay] + '.png'); + this.addBlob( + blob, + "export_" + DrawHelpers.overlayString[overlay] + ".png" + ); }); }); - - } - drawAll() - { + drawAll() { //console.log(this.running); //console.log('tick'); // Check that we're still running. @@ -735,7 +833,6 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh return; } - // Whole page dimensions this.width = window.innerWidth; this.height = window.innerHeight; @@ -753,13 +850,11 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh if (this.forceSize) { this.canvasRef.nativeElement.width = this.forcedSize.x; this.canvasRef.nativeElement.height = this.forcedSize.y; - } - else { + } else { this.canvasRef.nativeElement.width = window.innerWidth; this.canvasRef.nativeElement.height = window.innerHeight; } - this.cameraService.updateZoom(); //console.log('tick'); @@ -770,7 +865,8 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh this.drawPixi.clearGraphics(); //if (this.cameraService.visualization == Visualization.temperature) this.drawPixi.FillRect(0x909090, 0, 0, this.width, this.height); - if (this.cameraService.display == Display.blueprint) this.drawPixi.FillRect(0x007AD9, 0, 0, this.width, this.height); + if (this.cameraService.display == Display.blueprint) + this.drawPixi.FillRect(0x007ad9, 0, 0, this.width, this.height); else this.drawPixi.FillRect(0x909090, 0, 0, this.width, this.height); let alphaOrig: number = 0.4; @@ -780,38 +876,62 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh let zoomFadeMax: number = 35; let zoomFadeMin: number = 25; if (this.cameraService.currentZoom < zoomFadeMax) - alpha *= (this.cameraService.currentZoom - zoomFadeMin) / (zoomFadeMax - zoomFadeMin); - if (this.cameraService.currentZoom < zoomFadeMin) - alpha = 0; - + alpha *= + (this.cameraService.currentZoom - zoomFadeMin) / + (zoomFadeMax - zoomFadeMin); + if (this.cameraService.currentZoom < zoomFadeMin) alpha = 0; //while (realLineSpacing < 30) // realLineSpacing *= 5; - let colOrig: number = this.cameraService.cameraOffset.x * this.cameraService.currentZoom % (realLineSpacing * 5) - realLineSpacing * 4; + let colOrig: number = + ((this.cameraService.cameraOffset.x * this.cameraService.currentZoom) % + (realLineSpacing * 5)) - + realLineSpacing * 4; let mod = 0; - for (let col = colOrig; col < this.width + realLineSpacing * 4; col += realLineSpacing) - { - let realAlpha = (mod % 5) == 0 ? alphaOrig + 0.3 : alpha; - let color = 'rgba(255,255,255, '+realAlpha+')'; - if (realAlpha > 0) this.drawPixi.drawBlueprintLine(color, realAlpha, new Vector2(col, 0), new Vector2(col, this.height), 1); + for ( + let col = colOrig; + col < this.width + realLineSpacing * 4; + col += realLineSpacing + ) { + let realAlpha = mod % 5 == 0 ? alphaOrig + 0.3 : alpha; + let color = "rgba(255,255,255, " + realAlpha + ")"; + if (realAlpha > 0) + this.drawPixi.drawBlueprintLine( + color, + realAlpha, + new Vector2(col, 0), + new Vector2(col, this.height), + 1 + ); mod++; } - let lineOrig = this.cameraService.cameraOffset.y * this.cameraService.currentZoom % (realLineSpacing * 5) - realLineSpacing * 4 + let lineOrig = + ((this.cameraService.cameraOffset.y * this.cameraService.currentZoom) % + (realLineSpacing * 5)) - + realLineSpacing * 4; mod = 0; - for (let line = lineOrig; line < this.height + realLineSpacing * 4; line += realLineSpacing) - { - let realAlpha = (mod % 5) == 0 ? alphaOrig + 0.3 : alpha; - let color = 'rgba(255,255,255, '+realAlpha+')'; - if (realAlpha > 0) this.drawPixi.drawBlueprintLine(color, realAlpha, new Vector2(0, line), new Vector2(this.width, line), 1); + for ( + let line = lineOrig; + line < this.height + realLineSpacing * 4; + line += realLineSpacing + ) { + let realAlpha = mod % 5 == 0 ? alphaOrig + 0.3 : alpha; + let color = "rgba(255,255,255, " + realAlpha + ")"; + if (realAlpha > 0) + this.drawPixi.drawBlueprintLine( + color, + realAlpha, + new Vector2(0, line), + new Vector2(this.width, line), + 1 + ); mod++; } - if (this.blueprint != null) - { - for (var templateItem of this.blueprint.blueprintItems) - { + if (this.blueprint != null) { + for (var templateItem of this.blueprint.blueprintItems) { //templateItem.updateTileables(this.blueprint); this.drawPixi.drawTemplateItem(templateItem, this.cameraService); //templateItem.draw(ctx, this.camera); @@ -834,13 +954,20 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh this.cameraService.updateAnimations(this.drawPixi.pixiApp.ticker.elapsedMS); } - drawBlueprintLine(ctx: CanvasRenderingContext2D, xStart: number, yStart: number, xEnd: number, yEnd: number, lineWidth: number, alpha: number) - { + drawBlueprintLine( + ctx: CanvasRenderingContext2D, + xStart: number, + yStart: number, + xEnd: number, + yEnd: number, + lineWidth: number, + alpha: number + ) { let offset: number = (lineWidth % 2) / 2; ctx.beginPath(); ctx.moveTo(Math.floor(xStart) + offset, Math.floor(yStart) + offset); - ctx.strokeStyle = "rgba(255,255,255, "+alpha+")"; + ctx.strokeStyle = "rgba(255,255,255, " + alpha + ")"; ctx.lineWidth = lineWidth; ctx.lineTo(Math.floor(xEnd) + offset, Math.floor(yEnd) + offset); ctx.stroke(); @@ -851,8 +978,11 @@ export class ComponentCanvasComponent implements OnInit, OnDestroy, IObsCameraCh for (let blueprintItem of this.blueprint.blueprintItems) blueprintItem.cameraChanged(camera); - if (this.toolService != null && this.toolService.buildTool != null && this.toolService.buildTool.templateItemToBuild != null) + if ( + this.toolService != null && + this.toolService.buildTool != null && + this.toolService.buildTool.templateItemToBuild != null + ) this.toolService.buildTool.templateItemToBuild.cameraChanged(camera); } - } diff --git a/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.css b/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.css index 9d97bd3a..10b917a1 100644 --- a/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.css +++ b/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.css @@ -5,4 +5,4 @@ .like-bloc { margin-right: 1em; -} \ No newline at end of file +} diff --git a/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.html b/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.html index 38392d89..b3a85f86 100644 --- a/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.html +++ b/frontend/src/app/module-blueprint/components/component-menu/component-menu.component.html @@ -1,21 +1,61 @@ - - -