-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitOrigin-RevId: c8ca3fa438281864298dfe2ac5f37ba26b8a1ecf
- Loading branch information
Showing
27 changed files
with
460 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"esbenp.prettier-vscode", | ||
"styled-components.vscode-styled-components", | ||
"sysoev.vscode-open-in-github", | ||
"usernamehw.errorlens", | ||
"wix.vscode-import-cost" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"files.insertFinalNewline": true, | ||
"files.trimFinalNewlines": true, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[json]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"typescript.updateImportsOnFileMove.enabled": "always", | ||
"typescript.reportStyleChecksAsWarnings": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
We as members, contributors, and leaders pledge to make participation in our | ||
community a harassment-free experience for everyone, regardless of age, body | ||
size, visible or invisible disability, ethnicity, sex characteristics, gender | ||
identity and expression, level of experience, education, socio-economic status, | ||
nationality, personal appearance, race, caste, color, religion, or sexual | ||
identity and orientation. | ||
|
||
We pledge to act and interact in ways that contribute to an open, welcoming, | ||
diverse, inclusive, and healthy community. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to a positive environment for our | ||
community include: | ||
|
||
- Demonstrating empathy and kindness toward other people | ||
- Being respectful of differing opinions, viewpoints, and experiences | ||
- Giving and gracefully accepting constructive feedback | ||
- Accepting responsibility and apologizing to those affected by our mistakes, | ||
and learning from the experience | ||
- Focusing on what is best not just for us as individuals, but for the overall | ||
community | ||
|
||
Examples of unacceptable behavior include: | ||
|
||
- The use of sexualized language or imagery, and sexual attention or advances of | ||
any kind | ||
- Trolling, insulting or derogatory comments, and personal or political attacks | ||
- Public or private harassment | ||
- Publishing others' private information, such as a physical or email address, | ||
without their explicit permission | ||
- Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Enforcement Responsibilities | ||
|
||
Community leaders are responsible for clarifying and enforcing our standards of | ||
acceptable behavior and will take appropriate and fair corrective action in | ||
response to any behavior that they deem inappropriate, threatening, offensive, | ||
or harmful. | ||
|
||
Community leaders have the right and responsibility to remove, edit, or reject | ||
comments, commits, code, wiki edits, issues, and other contributions that are | ||
not aligned to this Code of Conduct, and will communicate reasons for moderation | ||
decisions when appropriate. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies within all community spaces, and also applies when | ||
an individual is officially representing the community in public spaces. | ||
Examples of representing our community include using an official email address, | ||
posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported to the community leaders responsible for enforcement at [email protected]. | ||
All complaints will be reviewed and investigated promptly and fairly. | ||
|
||
All community leaders are obligated to respect the privacy and security of the | ||
reporter of any incident. | ||
|
||
## Enforcement Guidelines | ||
|
||
Community leaders will follow these Community Impact Guidelines in determining | ||
the consequences for any action they deem in violation of this Code of Conduct: | ||
|
||
### 1. Correction | ||
|
||
**Community Impact**: Use of inappropriate language or other behavior deemed | ||
unprofessional or unwelcome in the community. | ||
|
||
**Consequence**: A private, written warning from community leaders, providing | ||
clarity around the nature of the violation and an explanation of why the | ||
behavior was inappropriate. A public apology may be requested. | ||
|
||
### 2. Warning | ||
|
||
**Community Impact**: A violation through a single incident or series of | ||
actions. | ||
|
||
**Consequence**: A warning with consequences for continued behavior. No | ||
interaction with the people involved, including unsolicited interaction with | ||
those enforcing the Code of Conduct, for a specified period of time. This | ||
includes avoiding interactions in community spaces as well as external channels | ||
like social media. Violating these terms may lead to a temporary or permanent | ||
ban. | ||
|
||
### 3. Temporary Ban | ||
|
||
**Community Impact**: A serious violation of community standards, including | ||
sustained inappropriate behavior. | ||
|
||
**Consequence**: A temporary ban from any sort of interaction or public | ||
communication with the community for a specified period of time. No public or | ||
private interaction with the people involved, including unsolicited interaction | ||
with those enforcing the Code of Conduct, is allowed during this period. | ||
Violating these terms may lead to a permanent ban. | ||
|
||
### 4. Permanent Ban | ||
|
||
**Community Impact**: Demonstrating a pattern of violation of community | ||
standards, including sustained inappropriate behavior, harassment of an | ||
individual, or aggression toward or disparagement of classes of individuals. | ||
|
||
**Consequence**: A permanent ban from any sort of public interaction within the | ||
community. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], | ||
version 2.1, available at | ||
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. | ||
|
||
Community Impact Guidelines were inspired by | ||
[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. | ||
|
||
For answers to common questions about this code of conduct, see the FAQ at | ||
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at | ||
[https://www.contributor-covenant.org/translations][translations]. | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html | ||
[Mozilla CoC]: https://github.com/mozilla/diversity | ||
[FAQ]: https://www.contributor-covenant.org/faq | ||
[translations]: https://www.contributor-covenant.org/translations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,118 @@ | ||
# Athena Crisis | ||
|
||
<p align="center"> | ||
<a href="https://athenacrisis.com"> | ||
<img alt="Athena Crisis Logo" src="./deimos/public/athena-crisis.svg" style="width: 70%;" /> | ||
</a> | ||
</p> | ||
|
||
[Athena Crisis](https://athenacrisis.com) is an Open Core video game developed by [Nakazawa Tech](https://nkzw.tech) and published by [Null](https://null.com). The source code in this repository is licensed under the [MIT License](./LICENSE.md) and can be used to improve Athena Crisis, build additional tools, study game development with JavaScript or create entirely new turn-based strategy games. | ||
|
||
Content like the single-player campaign, multiplayer, art and music are not open source. You can try a demo at [athenacrisis.com](https://athenacrisis.com) and you can wishlist or purchase [Athena Crisis on Steam Early Access](https://store.steampowered.com/app/2456430/Athena_Crisis/) or [buy Athena Crisis directly](https://app.athenacrisis.com/checkout) to play the full game. | ||
|
||
If you like Athena Crisis, [please consider a sponsorship to support its development](https://github.com/sponsors/cpojer). | ||
|
||
<a href="https://athenacrisis.com"> | ||
<img alt="Athena Crisis Gameplay" src="https://github.com/nkzw-tech/athena-crisis/assets/13352/800717e7-fda9-4265-9e0f-25c6c99326ce"> | ||
</a> | ||
|
||
## Setup | ||
|
||
Athena Crisis requires [Node.js](https://nodejs.org/en/download/package-manager) and the latest major version of [`pnpm`](https://pnpm.io/installation). | ||
|
||
```bash | ||
pnpm install && pnpm dev:setup | ||
pnpm dev | ||
``` | ||
|
||
Visit [localhost:3002](http://localhost:3002/) to see the landing page. | ||
|
||
## Packages | ||
|
||
- `apollo` → Data structures and algorithms for manipulating _game_ state (_client/server_). | ||
- `art` → Handling of assets (_client/build_). | ||
The codebase is split into multiple packages to enforce the separation of concerns. We suggest starting with these packages to get an end-to-end overview: | ||
|
||
- `athena` → Data structures and algorithms for manipulating _map_ state (_client/server_). | ||
- `codegen` → Run `pnpm codegen` when changing game `Actions` or `ActionResponses` to generate encoded actions and formatters (_build_). | ||
- `apollo` → Data structures and algorithms for manipulating _game_ state (_client/server_). | ||
- `hera` → Game engine and rendering (_client_). | ||
- `ui` → Design system (_client_). | ||
- `deimos` → Landing page (_client_). | ||
|
||
These are secondary packages focused on specific domains: | ||
|
||
- `art` → Handling of assets (_client/build_). | ||
- `codegen` → Run `pnpm codegen` when changing game `Action`s or `ActionResponse`s to generate encoded actions and formatters (_build_). | ||
- `dionysus` → AI code (_client/server_). | ||
- `hephaestus` → Iterator and Immutable data structures (_client/server_). | ||
- `hera` → Game engine and rendering (_client_). | ||
- `hermes` → Campaign related data structures and algorithms (_client/server_). | ||
- `i18n` → Internationalization (_client/build_). | ||
- `offline` → Offline splash screen for app (_client_). | ||
- `tests` → e2e tests. | ||
- `ui` -> Design system (_client_). | ||
|
||
# Q&A | ||
|
||
## What is open source and what isn't? | ||
|
||
About 75% of all non-content related Athena Crisis code is open source, including the core data structures, algorithms, game engine, rendering, AI, landing page and the map editor. Backend implementations such as user management, database, APIs, multiplayer, realtime spectating, translations, third-party integrations like Discord, server configuration and application wrappers for Steam or app stores are not open source. We aim to open source more of the game over time, but the content will remain the intellectual property of Nakazawa Tech KK and therefore not be open source. You can buy and enjoy [Athena Crisis on Steam Early Access](https://store.steampowered.com/app/2456430/Athena_Crisis/) or [buy it on athenacrisis.com](https://app.athenacrisis.com/checkout). | ||
|
||
## Why did you open source Athena Crisis? | ||
|
||
[Nakazawa Tech](https://nkzw.tech) is an Open Core company. See [the Athena Crisis is Now Open Source blog post](https://cpojer.net/posts/athena-crisis-open-source) for more information. | ||
|
||
## How is this codebase used at Nakazawa Tech? | ||
|
||
We use a monorepo for Athena Crisis at Nakazawa Tech and are syncing a portion of the codebase to this repository. Code merged into this open-source repository is automatically synced to the internal monorepo, and vice versa. Athena Crisis always runs the latest version of code from this repository in production. | ||
|
||
### Why are some folders almost empty? | ||
|
||
To simplify dependency management with [`pnpm`](https://pnpm.io/), most of the internal `package.json` files and the `pnpm-lock.yaml` are public. This makes it easier to share code between the internal monorepo and this repository, but also means that there are some placeholders in this repository, most notably the `ares` and `artemis` packages. | ||
|
||
## Why are packages named after Greek gods? | ||
|
||
Why not!? At some point it became necessary to split the codebase into multiple packages to share code between the client and server. The first package was named `athena`, and it was hard to come up with meaningful names for the other packages. We decided to name them after Greek gods because it seemed cute. | ||
|
||
Over time many pieces are expected to be extracted into separate packages and published on npm under the `@nkzw` organization. Please send a Pull Request if you find a piece of code that you think should be extracted into a separate package. | ||
|
||
## How do assets work in this codebase? | ||
|
||
Assets are not part of this codebase. For testing, development and browsing, all assets are loaded remotely from the Athena Crisis servers. | ||
|
||
## I would like to build a commercial project based on this codebase. Can I? | ||
|
||
Yes, you can. However, any content such as art, music, story, characters and their descriptions are not open source and are the intellectual property of Nakazawa Tech KK. You can use the codebase to build your own game, but you must replace all content with your own. For example, you have to replace all references to assets in [`Images.tsx`](https://github.com/nkzw-tech/athena-crisis/blob/main/hera/render/Images.tsx) or change character descriptions in [`Unit.tsx`](https://github.com/nkzw-tech/athena-crisis/blob/dc1c06b7f033e4c52a29db1524dc08226eacf63a/athena/info/Unit.tsx) if you want to publish your own game. | ||
|
||
If you'd like to use content from Athena Crisis for commercial or non-commercial purposes, you must obtain a license from Nakazawa Tech KK by emailing [email protected]. | ||
|
||
# Contributing | ||
|
||
We welcome contributions to Athena Crisis. Here are some guidelines to get you started: | ||
|
||
- The style guide is enforced through tests and linting. Please run `pnpm test` to run all checks. If they pass, you are good to send a Pull Request. | ||
- Check out [The Perfect Development Environment](https://cpojer.net/posts/the-perfect-development-environment) and [Fastest Frontend Tooling](https://cpojer.net/posts/fastest-frontend-tooling-in-2022) for tips on how to optimize your environment setup. | ||
- We suggest adding tests to Pull Requests. You can find many examples in the [`tests` folder](https://github.com/nkzw-tech/athena-crisis/tree/main/tests). | ||
|
||
Here are some types of contributions which we greatly appreciate: | ||
|
||
- Bug fixes. | ||
- AI improvements. | ||
- New game features. | ||
- Balancing improvements. | ||
- Tests to cover untested functionality. | ||
- Performance Improvements to core data structures. | ||
- Separation of concerns into smaller libraries that can be published on npm and consumed by other projects. | ||
|
||
# More information | ||
|
||
Check out these videos to learn more about the tech behind Athena Crisis: | ||
|
||
- [How NOT to Build a Video Game](https://www.youtube.com/watch?v=m8SmXOTM8Ec) | ||
- [Building the AI for Athena Crisis](https://www.youtube.com/watch?v=0V9XaIK0xlQ) | ||
|
||
# Supporters | ||
|
||
| <a href="https://www.hetzner.com/?mtm_campaign=athenacrisis_sponsoring&mtm_source=athenacrisis_community&mtm_medium=referral&mtm_content=sponsoring_link"><img src="./infra/assets/hetzner.svg" alt="Hetzner" style="width: 320px;"></a> | <a href="https://crowdin.com/project/athena-crisis" style="display: block;"><img src="./infra/assets/crowdin.svg" alt="Crowdin" style="width: 320px;"></a> | | ||
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| <a href="https://polar.sh" style="display: block;"><img src="./infra/assets/polar.svg" alt="Polar" style="width: 320px;"></a> | <a href="https://null.com" style="display: block;"><img src="./infra/assets/null.svg" alt="Null" style="width: 320px;"></a> | | ||
|
||
<a href="https://athenacrisis.com"> | ||
<img alt="Athena Crisis Keyart" src="./deimos/public/athena/keyart.jpg" /> | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,61 @@ | ||
import maxBy from '@deities/hephaestus/maxBy.tsx'; | ||
|
||
export type AttributeRangeValue = 1 | 2 | 3 | 4 | 5; | ||
export type AttributeRange = 1 | 2 | 3 | 4 | 5; | ||
export type AttributeRangeWithZero = 0 | 1 | 2 | 3 | 4 | 5; | ||
export type LargeAttributeRangeWithZero = | ||
| AttributeRangeWithZero | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10; | ||
|
||
export function validateAttributeRange( | ||
value?: number | null, | ||
): value is AttributeRangeValue { | ||
): value is AttributeRange { | ||
return !!value && value >= 1 && value <= 5; | ||
} | ||
|
||
export default function getAttributeRange<T>( | ||
list: ReadonlyArray<T>, | ||
extract: (entry: T) => number, | ||
min: number = 0, | ||
length: number = 5, | ||
) { | ||
const entry = maxBy(list, extract); | ||
if (!entry) { | ||
return []; | ||
} | ||
|
||
const step = (extract(entry) - min) / 4; | ||
const step = (extract(entry) - min) / (length - 1); | ||
return Array.from( | ||
{ length: 5 }, | ||
{ length }, | ||
(_, index) => min + index * step - (index > 0 ? step / 2 : 0), | ||
); | ||
} | ||
|
||
export function getAttributeRangeValue( | ||
range: ReadonlyArray<number>, | ||
value: number, | ||
): AttributeRangeValue { | ||
const index = range.findIndex((item) => item >= value); | ||
return (index === -1 ? range.length : index + 1) as AttributeRangeValue; | ||
) { | ||
if (value < range[0]) { | ||
return 0; | ||
} | ||
|
||
const index = range.findLastIndex((item) => item <= value); | ||
return (index === -1 ? range.length : index + 1) as AttributeRangeWithZero; | ||
} | ||
|
||
export function getLargeAttributeRangeValue( | ||
range: ReadonlyArray<number>, | ||
value: number, | ||
) { | ||
if (value < range[0]) { | ||
return 0; | ||
} | ||
|
||
const index = range.findLastIndex((item) => item <= value); | ||
return ( | ||
index === -1 ? range.length : index + 1 | ||
) as LargeAttributeRangeWithZero; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.