From 5dd2f5b0fe305e0b1b6b31f4e35ac0e137f2de0e Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Fri, 25 Jun 2021 17:41:39 -0400 Subject: [PATCH 01/10] Inital Update --- .gitignore | 1 + gulp/contributors.js | 156 ++++++++++++++++++++++++++++++++++++ gulp/gulpfile.js | 23 +++++- gulp/package.json | 3 +- gulp/yarn.lock | 12 ++- src/css/main.scss | 1 + src/css/states/credits.scss | 40 +++++++++ src/js/application.js | 2 + src/js/states/about.js | 8 ++ src/js/states/credits.js | 92 +++++++++++++++++++++ translations/base-en.yaml | 2 + 11 files changed, 334 insertions(+), 6 deletions(-) create mode 100644 gulp/contributors.js create mode 100644 src/css/states/credits.scss create mode 100644 src/js/states/credits.js diff --git a/.gitignore b/.gitignore index cdade93f..2cf3b9f2 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ gulp/runnable-texturepacker.jar tmp_standalone_files tmp_standalone_files_china tmp_standalone_files_wegame +contributors.json # Local config config.local.js diff --git a/gulp/contributors.js b/gulp/contributors.js new file mode 100644 index 00000000..0fc30897 --- /dev/null +++ b/gulp/contributors.js @@ -0,0 +1,156 @@ +const fs = require("fs"); +const fsp = require("fs/promises"); +const path = require("path"); +const fetch = require("node-fetch"); + +const APILink = "https://api.github.com/repos/tobspr/shapez.io"; +const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long + +const JSONFileLocation = path.join(__dirname, "..", "contributors.json"); + +function JSONFileExists() { + return fs.existsSync(JSONFileLocation); +} + +function readJSONFile() { + return fsp.readFile(JSONFileLocation, { encoding: "utf-8" }).then(res => JSON.parse(res)); +} + +function writeJSONFile(translators, contributors) { + return fsp.writeFile( + JSONFileLocation, + JSON.stringify({ + lastUpdatedAt: Date.now(), + //@ts-ignore + translators: Array.from(translators, ([username, value]) => ({ username, value })), + //@ts-ignore + contributors: Array.from(contributors, ([username, value]) => ({ username, value })), + }) + ); +} + +function getTotalNumOfPRs() { + return fetch(APILink + "/pulls?state=closed&per_page=1&page=0").then(res => { + // This part is very messy + let link = res.headers.get("Link"); + link = link.slice(link.indexOf(",") + 1); // Gets rid of the first "next" link + return parseInt(link.slice(link.indexOf("&page=") + 6, link.indexOf(">"))); + }); +} + +function shouldDownloadPRs() { + if (!JSONFileExists()) return Promise.resolve(true); + else { + return readJSONFile().then(res => Date.now() - res.lastUpdatedAt > 1000 * 60 * 30); // once every 30 min + } +} + +function PRIsTranslation(link) { + // return true; + // We just say that if a PR only edits translation files, its a translation, all others are something else + return fetch(link + "/files") + .then(res => res.json()) + .then(res => { + if (res.message) { + console.log("GITHUB HAS RATE-LIMITED THIS MACHINE, PLEASE WAIT ABOUT AN HOUR"); + throw new Error("rate-limit reached"); + } + for (let file of res) { + if (!file.filename.startsWith("translations/")) return false; + } + return true; + }); +} + +async function sortPRs(prs) { + const contributors = new Map(); + const translators = new Map(); + + for (let i = 0; i < prs.length; i++) { + let map; + + if (await PRIsTranslation(prs[i].url)) map = translators; + else map = contributors; + + if (!map.has(prs[i].username)) map.set(prs[i].username, []); + + map.get(prs[i].username).push(prs[i]); + } + + return { + contributors, + translators, + }; +} + +function reqPage(page) { + return fetch(APILink + `/pulls?state=closed&per_page=${numOfReqPerPage}&page=${page}`) + .then(res => res.json()) + .then(async res => { + const prs = []; + + for (let i = 0; i < res.length - 1; i++) { + if (!res[i].merged_at) continue; // Skip files that were never merged + + const prInfo = { + username: res[i].user.login, + html_url: res[i].html_url, + url: res[i].url, + user_avatar: res[i].user.avatar_url, + title: res[i].title, + time: res[i].createdAt, + }; + + prs.push(prInfo); + // if (await PRIsTranslation(res[i].url)) { + // translations.push(prInfo); + // } else { + // others.push(prInfo); + // } + } + + return prs; + }); +} + +async function downloadAllPrs() { + const totalNumOfPrs = await getTotalNumOfPRs(); + const numOfPageReqs = Math.ceil(totalNumOfPrs / numOfReqPerPage); + + const prs = []; + + for (let i = 0; i < numOfPageReqs; i++) { + prs.push(...(await reqPage(i))); // Yes promise.all would be good, but I wanna keep them in order (at least for now) + } + + return prs; +} + +async function tryToUpdateContributors() { + if (!(await shouldDownloadPRs())) { + console.log("Not updating contributors to prevent github API from rate-limiting this computer"); + console.log("If you wish to force a contributors update, use contributors.build.force"); + return; + } + + await updateContributors(); +} + +async function updateContributors() { + const allPrs = await downloadAllPrs(); + console.log(`Received ${allPrs.length} PRs`); + + const sorted = await sortPRs(allPrs); + + await writeJSONFile(sorted.translators, sorted.contributors); + console.log("Wrote JSON File"); +} + +function gulpTaskContributors($, gulp) { + gulp.task("contributors.build", cb => tryToUpdateContributors().then(() => cb)); + gulp.task("contributors.build.force", cb => updateContributors().then(() => cb)); +} + +module.exports = { + gulpTaskContributors, +}; diff --git a/gulp/gulpfile.js b/gulp/gulpfile.js index 0f4f4185..5aecbbcc 100644 --- a/gulp/gulpfile.js +++ b/gulp/gulpfile.js @@ -74,6 +74,8 @@ releaseUploader.gulptasksReleaseUploader($, gulp, buildFolder); const translations = require("./translations"); translations.gulptasksTranslations($, gulp, buildFolder); +const contributors = require("./contributors"); +contributors.gulpTaskContributors($, gulp, buildFolder); ///////////////////// BUILD TASKS ///////////////////// // Cleans up everything @@ -252,6 +254,7 @@ gulp.task( "imgres.copyImageResources", "imgres.copyNonImageResources", "translations.fullBuild", + "contributors.build", "css.dev", "html.dev" ) @@ -270,13 +273,17 @@ gulp.task( "imgres.copyImageResources", "imgres.copyNonImageResources", "translations.fullBuild", + "contributors.build", "css.dev", "html.standalone-dev" ) ); // Builds everything (staging) -gulp.task("step.staging.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.staging")); +gulp.task( + "step.staging.code", + gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.staging") +); gulp.task( "step.staging.mainbuild", gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.staging.code") @@ -285,7 +292,10 @@ gulp.task("step.staging.all", gulp.series("step.staging.mainbuild", "css.prod", gulp.task("build.staging", gulp.series("utils.cleanup", "step.staging.all", "step.postbuild")); // Builds everything (prod) -gulp.task("step.prod.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.prod")); +gulp.task( + "step.prod.code", + gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.prod") +); gulp.task( "step.prod.mainbuild", gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.prod.code") @@ -296,7 +306,7 @@ gulp.task("build.prod", gulp.series("utils.cleanup", "step.prod.all", "step.post // Builds everything (standalone-beta) gulp.task( "step.standalone-beta.code", - gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "js.standalone-beta") + gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "contributors.build", "js.standalone-beta") ); gulp.task("step.standalone-beta.mainbuild", gulp.parallel("step.baseResources", "step.standalone-beta.code")); gulp.task( @@ -313,7 +323,12 @@ gulp.task( for (const prefix of ["", "china.", "wegame."]) { gulp.task( prefix + "step.standalone-prod.code", - gulp.series("sounds.fullbuildHQ", "translations.fullBuild", prefix + "js.standalone-prod") + gulp.series( + "sounds.fullbuildHQ", + "translations.fullBuild", + "contributors.build", + prefix + "js.standalone-prod" + ) ); gulp.task( diff --git a/gulp/package.json b/gulp/package.json index 2a17b4fd..59148d73 100644 --- a/gulp/package.json +++ b/gulp/package.json @@ -15,7 +15,7 @@ "@babel/preset-env": "^7.5.4", "@types/cordova": "^0.0.34", "@types/filesystem": "^0.0.29", - "@types/node": "^12.7.5", + "@types/node": "^15.12.4", "ajv": "^6.10.2", "audiosprite": "^0.7.2", "babel-core": "^6.26.3", @@ -41,6 +41,7 @@ "ignore-loader": "^0.1.2", "lz-string": "^1.4.4", "markdown-loader": "^5.1.0", + "node-fetch": "^2.6.1", "node-sri": "^1.1.1", "phonegap-plugin-mobile-accessibility": "^1.0.5", "postcss": ">=5.0.0", diff --git a/gulp/yarn.lock b/gulp/yarn.lock index f4f3ba7f..3bf19500 100644 --- a/gulp/yarn.lock +++ b/gulp/yarn.lock @@ -994,11 +994,16 @@ resolved "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz" integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== -"@types/node@*", "@types/node@^12.7.5": +"@types/node@*": version "12.7.5" resolved "https://registry.npmjs.org/@types/node/-/node-12.7.5.tgz" integrity sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w== +"@types/node@^15.12.4": + version "15.12.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-15.12.4.tgz#e1cf817d70a1e118e81922c4ff6683ce9d422e26" + integrity sha512-zrNj1+yqYF4WskCMOHwN+w9iuD12+dGm0rQ35HLl9/Ouuq52cEtd0CH9qMgrdNmi5ejC1/V7vKEXYubB+65DkA== + "@types/q@^1.5.1": version "1.5.2" resolved "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz" @@ -8318,6 +8323,11 @@ no-case@^2.2.0: dependencies: lower-case "^1.1.1" +node-fetch@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" + integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== + node-libs-browser@^2.2.1: version "2.2.1" resolved "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.1.tgz" diff --git a/src/css/main.scss b/src/css/main.scss index 1bd82828..7aae2c3f 100644 --- a/src/css/main.scss +++ b/src/css/main.scss @@ -30,6 +30,7 @@ @import "states/mobile_warning"; @import "states/changelog"; @import "states/puzzle_menu"; +@import "states/credits.scss"; @import "ingame_hud/buildings_toolbar"; @import "ingame_hud/building_placer"; diff --git a/src/css/states/credits.scss b/src/css/states/credits.scss new file mode 100644 index 00000000..6cf967b8 --- /dev/null +++ b/src/css/states/credits.scss @@ -0,0 +1,40 @@ +#state_CreditsState { + .container .content { + text-align: center; + + .section { + @include S(margin-top, 10px); + @include S(padding, 5px); + background-color: #f8f8f8; + @include DarkThemeOverride { + background: rgba(0, 10, 20, 0.1); + } + + .title { + @include Heading; + } + + .people { + .entry { + } + + .flex-entry { + display: flex; + + .entry { + display: inline-block; + width: min-content; + } + } + } + + .people-flex { + display: flex; + + .entry { + display: flex; + } + } + } + } +} diff --git a/src/js/application.js b/src/js/application.js index 4e74b014..42755f8d 100644 --- a/src/js/application.js +++ b/src/js/application.js @@ -34,6 +34,7 @@ import { RestrictionManager } from "./core/restriction_manager"; import { PuzzleMenuState } from "./states/puzzle_menu"; import { ClientAPI } from "./platform/api"; import { LoginState } from "./states/login"; +import { CreditsState } from "./states/credits"; /** * @typedef {import("./platform/achievement_provider").AchievementProviderInterface} AchievementProviderInterface @@ -165,6 +166,7 @@ export class Application { ChangelogState, PuzzleMenuState, LoginState, + CreditsState, ]; for (let i = 0; i < states.length; ++i) { diff --git a/src/js/states/about.js b/src/js/states/about.js index 4380b02c..5739fcac 100644 --- a/src/js/states/about.js +++ b/src/js/states/about.js @@ -35,6 +35,14 @@ export class AboutState extends TextualGameState { { preventClick: true } ); }); + + const stateChangers = this.htmlElement.querySelectorAll("a[state]"); + console.log(stateChangers); + stateChangers.forEach(element => { + this.trackClicks(element, () => this.moveToState(element.getAttribute("state")), { + preventClick: true, + }); + }); } getDefaultPreviousState() { diff --git a/src/js/states/credits.js b/src/js/states/credits.js new file mode 100644 index 00000000..b3de92d3 --- /dev/null +++ b/src/js/states/credits.js @@ -0,0 +1,92 @@ +import { TextualGameState } from "../core/textual_game_state"; +import { contributors, translators } from "../../../contributors.json"; +const APILink = "https://api.github.com/repos/tobspr/shapez.io"; // Should use THRIDPARY_URLS, but it is really hard to read. +const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long + +export class CreditsState extends TextualGameState { + constructor() { + super("CreditsState"); + this.state = "Credits"; + } + + getStateHeaderTitle() { + return this.state; + } + + getMainContentHTML() { + return ` +
Tobias Springer - Main Programer and Artist
+
+
A Special Thanks To:
+
+
Pepsin - Created the soundtrack
+
Sense 101 - Designed the Puzzle DLC's official puzzles
+
SargeanTravis - Created an achievement by whining a lot
+
Bagel03 - Was an absolute CHAD
+
Dengr - Wouldn't tell me what to put here
+
Block of Emerald - Also wouldn't tell me what to put here
+
+
+
+
Translators:
+
+ ${this.getTranslatorsHTML()} +
+
+
+
Contributors:
+
Loading...
+
+ `; + } + + getTranslatorsHTML() { + let html = ""; + for (let i = 0; i < translators.length; i++) { + html += ` +
+
+ ${ + translators[i].username + }:
${translators[i].value + .map(pr => { + return `${this.getGoodTitle(pr.title)}, `; + }) + .reduce((p, c) => p + c) + .slice(0, -2)} +
+ `; + } + return html; + } + + getContributorsHTML() { + let html = ""; + for (let i = 0; i < contributors.length; i++) { + html += ` +
+
+ ${ + contributors[i].username + }:
${contributors[i].value + .map(pr => { + return `${this.getGoodTitle(pr.title)}, `; + }) + .reduce((p, c) => p + c) + .slice(0, -2)} +
+ `; + } + return html; + } + + getGoodTitle(title) { + if (title.endsWith(".")) return title.slice(0, -1); + + return title; + } + + onEnter() { + // this.setPRInnerHTML(); + } +} diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 02d8e948..69ad421c 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -1368,6 +1368,8 @@ about: body: >- This game is open source and developed by Tobias Springer (this is me).

+ Have a look at the Credits to see every who has helped out by translating or contributing.

+ If you want to contribute, check out shapez.io on GitHub.

This game wouldn't have been possible without the great Discord community around my games - You should really join the Discord server!

From cdd205f3e60c17e7028a167fa065fc20e385cbb2 Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Sun, 27 Jun 2021 01:16:40 -0400 Subject: [PATCH 02/10] Github API fixes --- gulp/contributors.js | 27 ++++++++++++++++++++------- gulp/gulpfile.js | 21 ++++----------------- src/js/states/credits.js | 4 +++- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/gulp/contributors.js b/gulp/contributors.js index 0fc30897..3d5b5d7c 100644 --- a/gulp/contributors.js +++ b/gulp/contributors.js @@ -1,13 +1,20 @@ const fs = require("fs"); const fsp = require("fs/promises"); const path = require("path"); -const fetch = require("node-fetch"); +const nodeFetch = require("node-fetch"); const APILink = "https://api.github.com/repos/tobspr/shapez.io"; const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long +const personalAccessToken = " res.json()) @@ -55,6 +61,7 @@ function PRIsTranslation(link) { console.log("GITHUB HAS RATE-LIMITED THIS MACHINE, PLEASE WAIT ABOUT AN HOUR"); throw new Error("rate-limit reached"); } + console.log(res); for (let file of res) { if (!file.filename.startsWith("translations/")) return false; } @@ -89,16 +96,16 @@ function reqPage(page) { .then(async res => { const prs = []; - for (let i = 0; i < res.length - 1; i++) { - if (!res[i].merged_at) continue; // Skip files that were never merged + for (let i = 0; i < res.length; i++) { + if (!res[i].merged_at) { + continue; + } // Skip files that were never merged const prInfo = { username: res[i].user.login, html_url: res[i].html_url, url: res[i].url, - user_avatar: res[i].user.avatar_url, title: res[i].title, - time: res[i].createdAt, }; prs.push(prInfo); @@ -119,7 +126,7 @@ async function downloadAllPrs() { const prs = []; - for (let i = 0; i < numOfPageReqs; i++) { + for (let i = 1; i < numOfPageReqs + 1; i++) { prs.push(...(await reqPage(i))); // Yes promise.all would be good, but I wanna keep them in order (at least for now) } @@ -149,6 +156,12 @@ async function updateContributors() { function gulpTaskContributors($, gulp) { gulp.task("contributors.build", cb => tryToUpdateContributors().then(() => cb)); gulp.task("contributors.build.force", cb => updateContributors().then(() => cb)); + + gulp.task("fetch.test", cb => { + fetch(APILink) + .then(res => console.log(res.headers.get("x-ratelimit-remaining"))) + .then(cb); + }); } module.exports = { diff --git a/gulp/gulpfile.js b/gulp/gulpfile.js index 5aecbbcc..63ff23ea 100644 --- a/gulp/gulpfile.js +++ b/gulp/gulpfile.js @@ -254,7 +254,6 @@ gulp.task( "imgres.copyImageResources", "imgres.copyNonImageResources", "translations.fullBuild", - "contributors.build", "css.dev", "html.dev" ) @@ -273,17 +272,13 @@ gulp.task( "imgres.copyImageResources", "imgres.copyNonImageResources", "translations.fullBuild", - "contributors.build", "css.dev", "html.standalone-dev" ) ); // Builds everything (staging) -gulp.task( - "step.staging.code", - gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.staging") -); +gulp.task("step.staging.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.staging")); gulp.task( "step.staging.mainbuild", gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.staging.code") @@ -292,10 +287,7 @@ gulp.task("step.staging.all", gulp.series("step.staging.mainbuild", "css.prod", gulp.task("build.staging", gulp.series("utils.cleanup", "step.staging.all", "step.postbuild")); // Builds everything (prod) -gulp.task( - "step.prod.code", - gulp.series("sounds.fullbuild", "translations.fullBuild", "contributors.build", "js.prod") -); +gulp.task("step.prod.code", gulp.series("sounds.fullbuild", "translations.fullBuild", "js.prod")); gulp.task( "step.prod.mainbuild", gulp.parallel("utils.copyAdditionalBuildFiles", "step.baseResources", "step.prod.code") @@ -306,7 +298,7 @@ gulp.task("build.prod", gulp.series("utils.cleanup", "step.prod.all", "step.post // Builds everything (standalone-beta) gulp.task( "step.standalone-beta.code", - gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "contributors.build", "js.standalone-beta") + gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "js.standalone-beta") ); gulp.task("step.standalone-beta.mainbuild", gulp.parallel("step.baseResources", "step.standalone-beta.code")); gulp.task( @@ -323,12 +315,7 @@ gulp.task( for (const prefix of ["", "china.", "wegame."]) { gulp.task( prefix + "step.standalone-prod.code", - gulp.series( - "sounds.fullbuildHQ", - "translations.fullBuild", - "contributors.build", - prefix + "js.standalone-prod" - ) + gulp.series("sounds.fullbuildHQ", "translations.fullBuild", prefix + "js.standalone-prod") ); gulp.task( diff --git a/src/js/states/credits.js b/src/js/states/credits.js index b3de92d3..be577fe1 100644 --- a/src/js/states/credits.js +++ b/src/js/states/credits.js @@ -35,7 +35,9 @@ export class CreditsState extends TextualGameState {
Contributors:
-
Loading...
+
+ ${this.getContributorsHTML()} +
`; } From ca8920977ecb0f012486404dd93efe60ddd94d53 Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Sun, 27 Jun 2021 01:27:51 -0400 Subject: [PATCH 03/10] Removed Console Logs --- gulp/contributors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulp/contributors.js b/gulp/contributors.js index 3d5b5d7c..396b364c 100644 --- a/gulp/contributors.js +++ b/gulp/contributors.js @@ -61,7 +61,7 @@ function PRIsTranslation(link) { console.log("GITHUB HAS RATE-LIMITED THIS MACHINE, PLEASE WAIT ABOUT AN HOUR"); throw new Error("rate-limit reached"); } - console.log(res); + for (let file of res) { if (!file.filename.startsWith("translations/")) return false; } From d5de568f9ea6ce8f09f5e6bbd441be0b7479653c Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Sun, 27 Jun 2021 21:43:50 -0400 Subject: [PATCH 04/10] Small Improvements --- gulp/contributors.js | 8 +-- src/css/states/credits.scss | 32 +++++------- src/js/states/credits.js | 98 +++++++++++++++++++++---------------- translations/base-en.yaml | 12 +++++ 4 files changed, 81 insertions(+), 69 deletions(-) diff --git a/gulp/contributors.js b/gulp/contributors.js index 396b364c..8bf71c83 100644 --- a/gulp/contributors.js +++ b/gulp/contributors.js @@ -5,7 +5,7 @@ const nodeFetch = require("node-fetch"); const APILink = "https://api.github.com/repos/tobspr/shapez.io"; const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long -const personalAccessToken = " tryToUpdateContributors().then(() => cb)); gulp.task("contributors.build.force", cb => updateContributors().then(() => cb)); - - gulp.task("fetch.test", cb => { - fetch(APILink) - .then(res => console.log(res.headers.get("x-ratelimit-remaining"))) - .then(cb); - }); } module.exports = { diff --git a/src/css/states/credits.scss b/src/css/states/credits.scss index 6cf967b8..da619a26 100644 --- a/src/css/states/credits.scss +++ b/src/css/states/credits.scss @@ -2,6 +2,10 @@ .container .content { text-align: center; + .tobspr .title { + @include S(margin-top, 10px); + } + .section { @include S(margin-top, 10px); @include S(padding, 5px); @@ -12,28 +16,18 @@ .title { @include Heading; + @include S(margin-bottom, 8px); + + color: #555; + @include DarkThemeOverride { + color: #eee; + } } .people { - .entry { - } - - .flex-entry { - display: flex; - - .entry { - display: inline-block; - width: min-content; - } - } - } - - .people-flex { - display: flex; - - .entry { - display: flex; - } + max-height: 0; + overflow: hidden; + transition: max-height 0.5s ease-out; } } } diff --git a/src/js/states/credits.js b/src/js/states/credits.js index be577fe1..f302553e 100644 --- a/src/js/states/credits.js +++ b/src/js/states/credits.js @@ -1,76 +1,61 @@ import { TextualGameState } from "../core/textual_game_state"; import { contributors, translators } from "../../../contributors.json"; -const APILink = "https://api.github.com/repos/tobspr/shapez.io"; // Should use THRIDPARY_URLS, but it is really hard to read. -const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long +import { T } from "../translations"; export class CreditsState extends TextualGameState { constructor() { super("CreditsState"); - this.state = "Credits"; } getStateHeaderTitle() { - return this.state; + return T.credits.title; } getMainContentHTML() { return ` -
Tobias Springer - Main Programer and Artist
+
${this.linkify( + "https://github.com/tobspr", + "Tobias Springer" + )} - ${T.credits.tobspr}
-
A Special Thanks To:
+
-
Pepsin - Created the soundtrack
-
Sense 101 - Designed the Puzzle DLC's official puzzles
-
SargeanTravis - Created an achievement by whining a lot
-
Bagel03 - Was an absolute CHAD
-
Dengr - Wouldn't tell me what to put here
-
Block of Emerald - Also wouldn't tell me what to put here
+
${this.linkify( + "https://soundcloud.com/pettersumelius", + "Peppsen" + )} - ${T.credits.specialThanks.descriptions.peppsen}
+
Add some other people here (Whoever you think deserves it)
+
-
Translators:
-
- ${this.getTranslatorsHTML()} + +
+ ${this.getGithubHTML(translators)}
-
Contributors:
-
- ${this.getContributorsHTML()} + +
+ ${this.getGithubHTML(contributors)}
`; } - getTranslatorsHTML() { - let html = ""; - for (let i = 0; i < translators.length; i++) { - html += ` -
-
- ${ - translators[i].username - }:
${translators[i].value - .map(pr => { - return `${this.getGoodTitle(pr.title)}, `; - }) - .reduce((p, c) => p + c) - .slice(0, -2)} -
- `; - } - return html; + linkify(href, text) { + return `${text}`; } - getContributorsHTML() { + getGithubHTML(list) { let html = ""; - for (let i = 0; i < contributors.length; i++) { + for (let i = 0; i < list.length; i++) { html += ` -
+ ${i === 0 ? "" : "
"}
- ${ - contributors[i].username - }:
${contributors[i].value + ${this.linkify(`https://github.com/${list[i].username}`, list[i].username)}:
${list[ + i + ].value .map(pr => { return `${this.getGoodTitle(pr.title)}, `; }) @@ -89,6 +74,33 @@ export class CreditsState extends TextualGameState { } onEnter() { - // this.setPRInnerHTML(); + // Allow the user to close any section by clicking on the title + const buttons = this.htmlElement.querySelectorAll("button.title"); + buttons.forEach(button => { + /** @type {HTMLElement} */ + //@ts-ignore + const people = button.nextElementSibling; + + button.addEventListener("click", e => { + if (people.style.maxHeight) { + people.style.maxHeight = null; + } else { + people.style.maxHeight = people.scrollHeight + "px"; + } + }); + + // Set them to open at the start + people.style.maxHeight = people.scrollHeight + "px"; + }); + + // Link stuff + const links = this.htmlElement.querySelectorAll("a[href]"); + links.forEach(link => { + this.trackClicks( + link, + () => this.app.platformWrapper.openExternalLink(link.getAttribute("href")), + { preventClick: true } + ); + }); } } diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 69ad421c..ab621f12 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -1381,6 +1381,18 @@ about: changelog: title: Changelog +credits: + title: Credits + tobspr: Main Programer and Artist + specialThanks: + title: Special Thanks To + descriptions: + peppsen: Created the awesome soundtrack + translators: + title: Translators + contributors: + title: Contributors + demo: features: restoringGames: Restoring savegames From 04f12a22e0c4cfbdb60b268d8db499aa0444cfe1 Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Sun, 27 Jun 2021 21:44:58 -0400 Subject: [PATCH 05/10] Updated to use translations --- src/js/states/credits.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/states/credits.js b/src/js/states/credits.js index f302553e..99e4b0a1 100644 --- a/src/js/states/credits.js +++ b/src/js/states/credits.js @@ -29,13 +29,13 @@ export class CreditsState extends TextualGameState {
- +
${this.getGithubHTML(translators)}
- +
${this.getGithubHTML(contributors)}
From 00bed92452ab987671c826dd9954d6f3c886444f Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Sun, 27 Jun 2021 22:56:55 -0400 Subject: [PATCH 06/10] Added default contributors --- gulp/contributors.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gulp/contributors.js b/gulp/contributors.js index 8bf71c83..6bd22308 100644 --- a/gulp/contributors.js +++ b/gulp/contributors.js @@ -134,6 +134,12 @@ async function downloadAllPrs() { } async function tryToUpdateContributors() { + if (personalAccessToken === "PUT TOKEN HERE") { + console.log("A github token was not provided, writing default contributors.json"); + await writeJSONFile([], []); + return; + } + if (!(await shouldDownloadPRs())) { console.log("Not updating contributors to prevent github API from rate-limiting this computer"); console.log("If you wish to force a contributors update, use contributors.build.force"); From 374839ae37bfa3921012d65f5c73cfdfcc1fb57a Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Sun, 27 Jun 2021 23:02:54 -0400 Subject: [PATCH 07/10] Fixed typo --- src/js/states/credits.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/states/credits.js b/src/js/states/credits.js index 99e4b0a1..e4e8c185 100644 --- a/src/js/states/credits.js +++ b/src/js/states/credits.js @@ -35,7 +35,7 @@ export class CreditsState extends TextualGameState {
- +
${this.getGithubHTML(contributors)}
From f99984c672b3aba3139e009076bb506d8ff8b37f Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Sun, 27 Jun 2021 23:04:27 -0400 Subject: [PATCH 08/10] Added orevious state --- src/js/states/credits.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/js/states/credits.js b/src/js/states/credits.js index e4e8c185..9adffeeb 100644 --- a/src/js/states/credits.js +++ b/src/js/states/credits.js @@ -103,4 +103,8 @@ export class CreditsState extends TextualGameState { ); }); } + + getDefaultPreviousState() { + return "AboutState"; + } } From bee69802b859f3823c28d347030408a621cb4c3b Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Mon, 28 Jun 2021 12:00:49 -0400 Subject: [PATCH 09/10] Added some logs to show how much time was left --- gulp/contributors.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gulp/contributors.js b/gulp/contributors.js index 6bd22308..0def5031 100644 --- a/gulp/contributors.js +++ b/gulp/contributors.js @@ -5,7 +5,7 @@ const nodeFetch = require("node-fetch"); const APILink = "https://api.github.com/repos/tobspr/shapez.io"; const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long -const personalAccessToken = "PUT TOKEN HERE"; +const personalAccessToken = "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"; const JSONFileLocation = path.join(__dirname, "..", "contributors.json"); @@ -73,6 +73,11 @@ async function sortPRs(prs) { const contributors = new Map(); const translators = new Map(); + const clearLine = () => { + process.stdout.moveCursor(0, -1); // up one line + process.stdout.clearLine(1); + }; + for (let i = 0; i < prs.length; i++) { let map; @@ -82,7 +87,13 @@ async function sortPRs(prs) { if (!map.has(prs[i].username)) map.set(prs[i].username, []); map.get(prs[i].username).push(prs[i]); + + if (i !== 0) clearLine(); + console.log(`PR's Downloaded: ${i} out of ${prs.length} (${prs.length - i} left)`); } + clearLine(); + + console.log("Downloaded All PR's"); return { contributors, @@ -151,7 +162,7 @@ async function tryToUpdateContributors() { async function updateContributors() { const allPrs = await downloadAllPrs(); - console.log(`Received ${allPrs.length} PRs`); + console.log(`Discovered ${allPrs.length} PRs`); const sorted = await sortPRs(allPrs); @@ -162,6 +173,21 @@ async function updateContributors() { function gulpTaskContributors($, gulp) { gulp.task("contributors.build", cb => tryToUpdateContributors().then(() => cb)); gulp.task("contributors.build.force", cb => updateContributors().then(() => cb)); + + gulp.task("contributors.test", async cb => { + const people = []; + for (let i = 0; i < 100; i++) people.push(i); + + console.log("Starting"); + for (let i = 0; i < 100; i++) { + console.log(`PR's Downloaded: ${i} out of ${people.length} (${people.length - i} left)`); + await new Promise(res => setTimeout(res, 100)); + } + + process.stdout.moveCursor(0, -1); // up one line + process.stdout.clearLine(1); + console.log("Finished"); + }); } module.exports = { From c1af4c5b3d1a720b8c52695a946ed7474aadda5e Mon Sep 17 00:00:00 2001 From: Edward Badel Date: Mon, 28 Jun 2021 13:22:41 -0400 Subject: [PATCH 10/10] built_temp --- gulp/contributors.js | 19 ++----------------- src/css/states/credits.scss | 5 +++-- src/js/states/credits.js | 12 +++++++----- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/gulp/contributors.js b/gulp/contributors.js index 0def5031..4a1ccbfe 100644 --- a/gulp/contributors.js +++ b/gulp/contributors.js @@ -5,7 +5,7 @@ const nodeFetch = require("node-fetch"); const APILink = "https://api.github.com/repos/tobspr/shapez.io"; const numOfReqPerPage = 100; // Max is 100, change to something lower if loads are too long -const personalAccessToken = "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"; +const personalAccessToken = "PUT TOKEN HERE"; const JSONFileLocation = path.join(__dirname, "..", "contributors.json"); @@ -91,8 +91,8 @@ async function sortPRs(prs) { if (i !== 0) clearLine(); console.log(`PR's Downloaded: ${i} out of ${prs.length} (${prs.length - i} left)`); } - clearLine(); + clearLine(); console.log("Downloaded All PR's"); return { @@ -173,21 +173,6 @@ async function updateContributors() { function gulpTaskContributors($, gulp) { gulp.task("contributors.build", cb => tryToUpdateContributors().then(() => cb)); gulp.task("contributors.build.force", cb => updateContributors().then(() => cb)); - - gulp.task("contributors.test", async cb => { - const people = []; - for (let i = 0; i < 100; i++) people.push(i); - - console.log("Starting"); - for (let i = 0; i < 100; i++) { - console.log(`PR's Downloaded: ${i} out of ${people.length} (${people.length - i} left)`); - await new Promise(res => setTimeout(res, 100)); - } - - process.stdout.moveCursor(0, -1); // up one line - process.stdout.clearLine(1); - console.log("Finished"); - }); } module.exports = { diff --git a/src/css/states/credits.scss b/src/css/states/credits.scss index da619a26..af6d53be 100644 --- a/src/css/states/credits.scss +++ b/src/css/states/credits.scss @@ -3,7 +3,6 @@ text-align: center; .tobspr .title { - @include S(margin-top, 10px); } .section { @@ -16,7 +15,6 @@ .title { @include Heading; - @include S(margin-bottom, 8px); color: #555; @include DarkThemeOverride { @@ -29,6 +27,9 @@ overflow: hidden; transition: max-height 0.5s ease-out; } + .people > :first-child { + @include S(margin-top, 8px); + } } } } diff --git a/src/js/states/credits.js b/src/js/states/credits.js index 9adffeeb..b5feb5c2 100644 --- a/src/js/states/credits.js +++ b/src/js/states/credits.js @@ -13,10 +13,12 @@ export class CreditsState extends TextualGameState { getMainContentHTML() { return ` -
${this.linkify( - "https://github.com/tobspr", - "Tobias Springer" - )} - ${T.credits.tobspr}
+
+ +
+
${this.linkify("https://github.com/tobspr", "Tobias Springer")}
+
+
@@ -57,7 +59,7 @@ export class CreditsState extends TextualGameState { i ].value .map(pr => { - return `${this.getGoodTitle(pr.title)}, `; + return `${this.linkify(pr.html_url, this.getGoodTitle(pr.title))}, `; }) .reduce((p, c) => p + c) .slice(0, -2)}