Skip to content

Commit

Permalink
Merge 179ac30 into f6e3d87
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Aug 11, 2020
2 parents f6e3d87 + 179ac30 commit e419944
Show file tree
Hide file tree
Showing 148 changed files with 12,840 additions and 13,591 deletions.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
node_modules
.DS_Store
coverage
coverage
docs/api
docs/**/*.html
docs/assets/js/kontra.js
kontra.*
test/permutations/*.js
test/permutations/*.spec.js
test/typings/*.js
test/playground.html

!test/permutations/index.js
!test/permutations/karma.conf.template.js
54 changes: 53 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,56 @@ dist: trusty
sudo: required
addons:
chrome: stable
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"

jobs:
include:
- name: "Unit Tests"
if: type = pull_request
script:
- npm test
after_success: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
- name: "Typescript Tests"
if: type = pull_request
script:
- npm run build
- npm run test:ts

# run permutations in parallel (starting with the longer running ones
# so they have more time to complete while the shorter ones finish)
- name: "Permutation Tests: vector"
if: type = pull_request
script:
- npm run build
- npm run test:permutations vector
- name: "Permutation Tests: gameObject"
if: type = pull_request
script:
- npm run build
- npm run test:permutations gameObject
- name: "Permutation Tests: text"
if: type = pull_request
script:
- npm run build
- npm run test:permutations text
- name: "Permutation Tests: updatable"
if: type = pull_request
script:
- npm run build
- npm run test:permutations updatable
- name: "Permutation Tests: sprite"
if: type = pull_request
script:
- npm run build
- npm run test:permutations sprite

- name: "Deploy gh-pages"
if: type = push
script: npm run build:docs
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
keep_history: true
local_dir: docs
on:
branch: main
97 changes: 97 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Contributing

By participating in this project you agree to abide by the terms in the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).

## Goal

The goal of Kontra is not to implement everything you could possibly need to make a game. There are already libraries out there that do that (like [Phaser](http://phaser.io/)).

Instead, Kontra aims to implement basic game requirements like asset loading, input, the game loop, and spites to keep the library very small and focused. This allows it to be used when your game size is limited (like the [js13k games competition](https://js13kgames.com/)).

### Features Kontra Won't Support

Below is a list of features the library will not support or add:

- Physics engine
- Math helpers

## Code Style

To help keep the code small the library follows some unconventional code patterns. Take a look at these [byte-saving techniques](https://github.com/jed/140bytes/wiki/Byte-saving-techniques) and follow these recommendations:

- Use `==` over `===` (save a byte)
- Use `| 0` over `Math.floor()`

## Building

To build the development code, run `npm run build`. To build the distribution version of the code, run `npm run dist`. Both should be built before submitting a pull request.

## Testing

Please add unit and/or integration tests for all new changes, as well as TypeScript tests found in [test/typings](test/typings). To run the tests, run `npm test`.

The TypeScript tests just ensure that the TypesCript declaration file is correct and doesn't miss any obvious use cases with the various APIs.

## Exports

Please update the export files for all new changes (if need be). [kontra.defaults.js](src/kontra.defaults.js) imports all functionality and then adds it to the `kontra` object. [kontra.js](src/kontra.js) exports all functionality directly. You will also need to tests to their respected spec files that ensures the functionality is exported.

## Documentation and TypeScript Declaration File

The [documentation](/docs) and the [TypeScript declaration file](kontra.d.ts) is built from the JSDoc-like comments in the source files using [LivingCSS](https://github.com/straker/livingcss) (I know, not what it was intended for but it makes it really easy to build multiple pages of docs. And it's highly configurable). To update the documentation or the declaration file, just modify the JSDoc-like comments.

The comments are not true JSDoc syntax, but a modified version that supports both JSDoc tags and TypeSript declarations. For example, a comment for an object will be declared using TypeSript for the JSDoc type.

```js
/**
* @param {{x: number, y: number}} [properties.anchor={x:0,y:0}] - The x and y origin of the game object. {x:0, y:0} is the top left corner of the game object, {x:1, y:1} is the bottom right corner.
*/
```

The documentation will automatically read the TypeScript type and say it's an Object, while the declaration file will take the type directly.

```html
<!-- docs -->
<dt>
<code>properties.anchor</code>
<span class="optional">Optional</span>
</dt>
<dd>
<p>Object. The x and y origin of the game object. {x:0, y:0} is the top left corner of the game object, {x:1, y:1} is the bottomright corner. Defaults to <code>{x:0,y:0}</code>.
</p>
</dd>
```

```ts
// kontra.d.ts
interface GameObject{
anchor: {x: number, y: number};
}
```

The docs and declaration file are built along with the development version of the code, so running `npm run build` will build the docs as well. This ensures they stay in sync with any changes to the code.

All documentation related gulp tasks and `@tag` information can be found in [tasks/doc.js](tasks/docs.js). All TypeScript related gulp tasks and `@tag` information can be found in [tasks/typescript.js](tasks/typescript.js).

### TypeScript Code Style

Use uppercase for the first letter of each basic type: `Number`, `Boolean`, `String`, `Object`, `Function`.

If the type is a `Function` and takes no arguments and doesn't return anything, use `Function`. Otherwise declare the arguments and return using the syntax `(params: Type) => ReturnType`.

```js
/**
* @param {(dt?: Number) => void} update - Function called every frame to update the game. Is passed the fixed `dt` as a parameter.
* @param {Function} render - Function called every frame to render the game.
*/
```

If the type is an Object and can take any number of properties, use `Object`. Otherwise declare the properties of the object using the syntax `{key: Type}`.

```js
/**
* @param {Object} [properties] - Properties of the quadtree.
* @param {{x: Number, y: Number, width: Number, height: Number}} [properties.bounds] - The 2D space (x, y, width, height) the quadtree occupies. Defaults to the entire canvas width and height.
*/
```

18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,4 @@ When you become a Patron, you get access to behind the scenes development logs,

## Contributing

Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

### Building

To build the development code, run `npm run build`. To build the distribution version of the code, run `npm run dist`. Both should be built before submitting a pull request.

### Testing

Please add unit and/or integration tests for all new changes. To run the tests, run `npm test`.

### Docs

The documentation is built from the JSDoc comments in the source files using [LivingCSS](https://github.com/straker/livingcss) (I know, not what it was intended for but it makes it really easy to build multiple pages of docs. And it's highly configurable). To update the docs just modify the JSDoc comments.

The docs are built along with the development version of the code, so running `npm run build` will build the docs as well. This ensures they stay in sync with any changes to the code.

All doc related gulp tasks and `@tag` information can be found in the `doc-tasks.js` file.
See the [Contributing file](CONTRIBUTING.md).

0 comments on commit e419944

Please sign in to comment.