Skip to content
Snippets Groups Projects
CONTRIBUTING.md 7.1 KiB
Newer Older
# Contributing to FC: Pregmod
Arkerthan's avatar
Arkerthan committed

First off, thanks for taking the time to contribute!

If there is anything you don't understand feel free to ask. Many of the more advanced tools are also not required for
fixing small typos or simple bugs.
Arkerthan's avatar
Arkerthan committed

## Environment

### Requirements

To effectively work on the project the following tools are required:

* `Git`
* `Node.js` or another npm client
Arkerthan's avatar
Arkerthan committed
* an IDE capable of working with JavaScript, TypeScript and CSS. [VS Code](https://code.visualstudio.com/) is one option.
Arkerthan's avatar
Arkerthan committed
* Java Runtime Environment, minimum JRE8

### Setting everything up

0. Clone the project from GitGud.io ([Detailed Git setup and work cycle](devNotes/gitSetup.md))
Arkerthan's avatar
Arkerthan committed
1. Navigate to the `fc-pregmod` root directory.
   * Windows: Open the cmd/Powershell and execute `cd C:\path\to\project\fc-pregmod`
   * GNU/Linux: Open a terminal and execute `cd /path/to/project/fc-pregmod/`.
Arkerthan's avatar
Arkerthan committed
2. Run `npm install`
3. Open the directory in your preferred IDE
Blank_Alt's avatar
Blank_Alt committed
4. Configure your IDE to use ESLint.
Arkerthan's avatar
Arkerthan committed
5. Recommended extensions for VSCode:
   * [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) 
   * [GitLens — Git supercharged](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens).
Arkerthan's avatar
Arkerthan committed

## Compiling

While you can compile it like usual (`compile.bat`/`compile.sh`/`make`), there is also a `Gulp script` that creates
source maps for easier debugging. Other than that there are no differences between compiling for development or
Arkerthan's avatar
Arkerthan committed
compiling for playing the game.

# Code

## Code style

Generally the code style is based on our `.eslintrc.json`. If your IDE has an auto format feature it can often read the
rules from `.eslintrc.json`.
Arkerthan's avatar
Arkerthan committed

### Important Rules

* use spaces after commas
* do not omit semicolons
* no empty blocks
* don't pad blocks with blank lines
* prefer strict equality/inequality
* etc.

### Documentation
Arkerthan's avatar
Arkerthan committed

It's a good idea to provide meaningful documentation for new functions and classes where possible. We follow
Typescript's [JSDoc](https://jsdoc.app) type dialect for the most part (and we provide a Typescript configuration and
DCoded's avatar
DCoded committed
auxiliary type definition files if you'd like to use it yourself – it's pretty nifty). Don't worry too much about
specific type syntax if you can't make TS work or don't understand it, someone else will probably fix it for you as long
as you've made the intent clear in some form of JSDoc.
Arkerthan's avatar
Arkerthan committed

### Naming conventions
Arkerthan's avatar
Arkerthan committed

* JavaScript variable and function names should be `camelCase`.

```js
// good
let fooBar;

// bad
let foobar;
let Foobar;
let FooBar;
* JavaScript classes and namespaces should be `PascalCase`.

```js
class Foo {}
App.Foo.bar();

// bad
class foo {}
class FOO {}
App.foo.bar();
* Enum members should be `ALLCAPS`.

```ts
// good
enum Foo {
  BAR = 'bar',
  BAZ = 'baz',
}

// bad
enum Foo {
  bar = 'bar',
  Baz = 'baz',
}
```

This also applies to JavaScript objects that are used as enums.
/** @enum {string} */
const Foo = {
  BAR: 'bar',
  BAZ: 'baz',
}

/** @enum {string} */
const foo = {
  BAR: 'bar',
  BAZ: 'baz',
}
// worse
/** @enum {string} */
const foo = {
  bar: 'bar',
  Baz: 'baz',
}
```

* CSS classes are `kebob-case`.

```css
/* good */
.foo-bar {}

/* bad */
.fooBar {}
.FOO-BAR {}
```
Arkerthan's avatar
Arkerthan committed

Arkerthan's avatar
Arkerthan committed
New code should generally get organized into the `App` namespace. See [fc-js-init.js](js/002-config/fc-js-init.js) for a rough outline.
Arkerthan's avatar
Arkerthan committed

## JavaScript Features
Blank_Alt's avatar
Blank_Alt committed
* Generally, we're currently targeting ECMAScript 2021.
* It's not 2010 anymore and we don't try to support Internet Explorer or anything stupid like that.
* use `let`/`const` rather than `var`
* prefer fat arrow functions to inline long-form functions
* etc.
Arkerthan's avatar
Arkerthan committed

## Code quality

There are three main tools used to ensure good code quality, `ESLint`, `TypeScript Compiler (tsc)` and a custom sanity
check.

`ESLint` and `tsc` can be setup in most IDEs aimed at web development to show errors while editing the file.

Contributions should generally not add any new sanity check errors, and it's especially important to check this if
you're making changes to .tw files.
Use `./compile.sh --dry --sanity` or the short hand `./compile.sh -d -s` on linux or mac.
On Windows run `compile_debug+sanityCheck.bat`.
It searches for common spelling errors and syntax errors in the twine files. Don't worry about preexisting
errors, it's not totally clean as is and there are a few false positives.
Arkerthan's avatar
Arkerthan committed

## Project Structure

### Source files

* `src/` is the main directory for source code. It also contains the embedded art files. Since it is inside an `eval()` statement debugging and minification is more complicated than for `js/`.
* `js/` is loaded before SugarCube and therefore outside SugarCube's eval which `src/` is contained in. This means accessing SugarCube features (like `SugarCube.Engine`) is more complicated however it other than `src/` it can be minified and is easier to debug. Currently contains mainly static data, however new code not relying on SC2 should be sorted in here too.
* `css/` contains all CSS files. The internal structure is explained [here](css/css.md).
* `themes/` contains [custom themes](themes/themes.md) which are built separately.

### Dev Files

* `devNotes/` contains various wiki files and other potentially interesting files.
* `devTools/` contains various scripts and executables needed for working with the project or compiling. TypeScript typing files are stored here as well.
* `submodules/` contains git submodules. Only the custom version of SugarCube2 right now.

### Art files

* `artTools/`contains files for creating and updating [vector art](artTools/README.md).
* `resources/` contains various [art related files](resources/ReadmeBeforeAddingArt.md).

### External Programs
* `docker/` contains Docker files from which the docker containers for GitLabs CI are created.
* `FCHost/` contains the sources for [FCHost](FCHost/documentation_FCHost.md).
* `saveTools/` contains tools for [editing save files](saveTools/README.md).

Arkerthan's avatar
Arkerthan committed
# Further Reading

## Wiki Files

* Event Writing Guides
  * [Twine](devNotes/scene-guide.txt) (Twine is being phased out of the project however the concepts are still relevant)
DCoded's avatar
DCoded committed
  * [JavaScript](devNotes/jsEventCreationGuide.md)
Arkerthan's avatar
Arkerthan committed
* [Exception handling](devNotes/exceptions.md)
enbees's avatar
enbees committed
* [Sanity check](devNotes/sanityCheck.md)
Arkerthan's avatar
Arkerthan committed
* [Slave List](devNotes/slaveListing.md)
* [Pronouns](devNotes/Pronouns.md)
* External function documentation
  * [Eyes](devNotes/eye functions.md)
  * [Limbs](devNotes/limb functions.md)
  * [Standalone functions](devNotes/standaloneFunctions.md)
Blank_Alt's avatar
Blank_Alt committed
  * [Some potentially useful JS functions](devNotes/usefulJSFunctionDocumentation.txt)
Arkerthan's avatar
Arkerthan committed
  * [Content embedding chart](devNotes/contentEmbeddingChart.png) (for more details refer to [this issue](https://gitgud.io/pregmodfan/fc-pregmod/-/merge_requests/7453#note_118616))
Arkerthan's avatar
Arkerthan committed

## Useful issues

* [Setting up VS Code](https://gitgud.io/pregmodfan/fc-pregmod/-/issues/2448)
* [Classes in Game State](https://gitgud.io/pregmodfan/fc-pregmod/-/issues/696)
* [Self executing functions](https://gitgud.io/pregmodfan/fc-pregmod/-/issues/2325)
* [Sort a map](https://gitgud.io/pregmodfan/fc-pregmod/-/issues/2642)
Blank_Alt's avatar
Blank_Alt committed
* [How to create a Merge Request (MR)](https://gitgud.io/pregmodfan/fc-pregmod/-/issues/3903)