Skip to content

Commit

Permalink
Move docs to mkdocs base (#134)
Browse files Browse the repository at this point in the history
* improve current docs

* remove placeholders from funding

* bug report template markdown standard

* mkdocs base

* Hyperlinks fix in contributing

* mkdocs somewhy doesnt support crossing text with ~~, lol

* Using actual noitamp logo for logo

* better job name

* del: useless \

* renamed resources to res

* Mirror github communty files to docs

* more funding

* add bug to bug report

* Correct OSes in bug report example

* Remove browsers from bug report

Co-authored-by: Torben H. <Ismoh@users.noreply.github.com>

* Update docs/index.md

Co-authored-by: Torben H. <Ismoh@users.noreply.github.com>

* Correct version example in bug report

Co-authored-by: Torben H. <Ismoh@users.noreply.github.com>

* Remove mobile from bug report

* typo

* Correct discord bot info

* Missed support

* Link to credits in readme

* Path in changelog script

* Missing eof lines

* Fixed discord channel in docs/index.md

---------

Co-authored-by: Torben H. <Ismoh@users.noreply.github.com>
  • Loading branch information
Furrior and Ismoh committed Nov 21, 2023
1 parent a54dbaa commit 4160934
Show file tree
Hide file tree
Showing 27 changed files with 1,763 additions and 825 deletions.
16 changes: 3 additions & 13 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# These are supported funding model platforms

github: Ismoh # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
github: Ismoh
patreon: ismoh
custom: ["https://donatebot.io/checkout/747169041457872917", "https://discord.gg/DhMurdcw4k"]
15 changes: 5 additions & 10 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
labels: 'bug'
assignees: ''

---
Expand All @@ -12,6 +12,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +25,9 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- OS: [Windows, Linux]
- Version [NoitaMP version, e.g. `v5.0.0-alpha+1262`, have a look into `mods/noita-mp/.version]

**Additional context**
Add any other context about the problem here.
36 changes: 36 additions & 0 deletions .github/workflows/deploy_mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy mkdocs
on:
push:
branches:
- master
permissions:
contents: write
jobs:
deploy:
name: 'Deploy mkdocs'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v4
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material
- name: Mirror GitHub md's
run: |
cp -f CONTRIBUTING.md docs/contributing/CONTRIBUTING.md
cp -f CODE_OF_CONDUCT.md docs/contributing/CODE_OF_CONDUCT.md
cp -f LICENSE.md docs/about/LICENSE.md
cp -f SUPOORT.md docs/SUPORT.md
- run: mkdocs gh-deploy --force

8 changes: 4 additions & 4 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ representative at an online or offline event.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
https://github.com/Ismoh/NoitaMP/issues/new/choose.
<https://github.com/Ismoh/NoitaMP/issues/new/choose>.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down Expand Up @@ -116,13 +116,13 @@ the community.

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
<https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
<https://www.contributor-covenant.org/faq>. Translations are available at
<https://www.contributor-covenant.org/translations>.
94 changes: 62 additions & 32 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,90 @@
# Contributing to NoitaMP
I am happy to accept contributions to NoitaMP.\
Please follow these guidelines when contributing,\

I am happy to accept contributions to NoitaMP.
Please follow these guidelines when contributing,
but first off, thanks for taking the time to contribute!

## Table of Contents

- [Requirements](#requirements)
- [Contributing](#contributing)
- [Before contributing](#before-contributing)
- [How does NoitaMP work?](#how-does-noitamp-work)
- [Important resources](#important-resources)

## Requirements

- [ ] I have read the [Contributing](CONTRIBUTING.md) document.
- [ ] I have read the [Code of Conduct](CODE_OF_CONDUCT.md) document.
- [ ] I have read the [README](README.md) document.
- [ ] I have read the [LICENSE](LICENSE) document.
- [ ] I have read the [LICENSE](/about/LICENSE.md) document.
- [ ] I have experience in Lua.
- [ ] I have experience in Noita modding.

To be honest, I am sure that you have experience in Lua and Noita modding and if you read this, you will probably be able to contribute to NoitaMP.\
To be honest, I am sure that you have experience in Lua and Noita modding and if you read this, you will probably be able to contribute to NoitaMP.
Everything will be explained here and if there are still questions, you can ask them in the [Discord server](https://discord.gg/DhMurdcw4k).

## Contributing

### Before contributing

Please get in contact with me or the other collaborators on [Discord](https://discord.gg/DhMurdcw4k), before you start working on a feature or a bug fix.
This is to avoid duplicate work.

## How does NoitaMP work?
NoitaMP is a mod that uses the [Noita API](https://noita.wiki.gg/wiki/Modding), but there is something that you need to know about the API.\
The API is a Lua library that is used to interact with the game.\

NoitaMP is a mod that uses the [Noita API](https://noita.wiki.gg/wiki/Modding), but there is something that you need to know about the API.
The API is a Lua library that is used to interact with the game.
The API is not a mod, it is a library that is used to create mods.

### Lua context

There are different Lua contexts in Noita, but the most important one is the `init.lua` context.

### Contexts in Noita

Let me try to explain it with an example:
![NoitaMP](miscs/contributing-md/lua-contexts.png)
In the diagram above you can see the default Noita modding structure.\
![NoitaMP](/res/img/lua-contexts.png)
In the diagram above you can see the default Noita modding structure.
There are different Lua contexts:

- One for `init.lua`
- This is the 'main' context that is used to interact with NoitaMP, because unrestricted Lua code (unrestricted mod mode) is only available in the `init.lua` context.
- and contexts for `LuaComponents`
- How contexts for LuaComponents are defined, depends on the value of `vm_type`.\
SHARED_BY_MANY_COMPONENTS means that for that script path, it uses a single Lua context.\
ONE_PER_COMPONENT_INSTANCE means that even with the same script path, every LuaComponent has its own Lua context.
The path of the entity XML file is irrelevant as far as I can tell.\
SHARED_BY_MANY_COMPONENTS is the default, see [wiki](https://noita.wiki.gg/wiki/Documentation:_LuaComponent)
_Credits to dextercd_
- How contexts for LuaComponents are defined, depends on the value of `vm_type`.
`SHARED_BY_MANY_COMPONENTS` means that for that script path, it uses a single Lua context.
`ONE_PER_COMPONENT_INSTANCE` means that even with the same script path, every LuaComponent has its own Lua context.
The path of the entity XML file is irrelevant as far as I can tell.
`SHARED_BY_MANY_COMPONENTS` is the default, see [wiki](https://noita.wiki.gg/wiki/Documentation:_LuaComponent)

_Credits to dextercd_

**You are able to use Noita API functions in each context, but you are not able to use functions from other contexts.**
There is no way to access the `init.lua` context from a LuaComponent context and vice versa, **but there are workarounds**!

### Workarounds for communication between contexts

There are different ways to communicate between contexts:

- by Noita API Globals `GlobalsSetValue` and `GlobalsGetValue`
- VariableStorageComponents
- Using `init.lua` context only

Assume we need a value in NoitaMP, which can only be fetched in LuaComponents. So in different Lua contexts!\
Assume we need a value in NoitaMP, which can only be fetched in LuaComponents. So in different Lua contexts!
We can solve this problem by the examples below:

#### GlobalsSetValue and GlobalsGetValue

Then we would set a global "foo" variable in the `LuaComponent` context _(see 1 and 2 in the diagram below)_
and afterwards we would use the `init.lua` context to fetch the value of the global "foo" variable _(see 3 and 4 in the diagram below)_.\
and afterwards we would use the `init.lua` context to fetch the value of the global "foo" variable _(see 3 and 4 in the diagram below)_.
In addition, please note that `GlobalsSetValue` and `GlobalsGetValue` has nothing to do with Lua globals `_G`.
See diagram below for a better understanding:
![NoitaMP](miscs/contributing-md/lua-contexts-workaround.png)
![NoitaMP](/res/img/lua-contexts-workaround.png)

#### VariableStorageComponents

Another workaround is to use `VariableStorageComponents` to store values in the `LuaComponent` context and to fetch them in the `init.lua` context.
In a LuaComponent context, we would create a `VariableStorageComponent` and set a value in it:

```lua
local componentId = EntityAddComponent2(entityId, "VariableStorageComponent",
{
Expand All @@ -82,7 +93,9 @@ local componentId = EntityAddComponent2(entityId, "VariableStorageComponent",
}
)
```

In the `init.lua` context, we would fetch the value of the `VariableStorageComponent` with the name `"exampleName"`:

```lua
local componentIds = EntityGetComponentIncludingDisabled(entityId, "VariableStorageComponent") or {}
for i = 1, #componentIds do
Expand All @@ -98,8 +111,10 @@ end
```

#### Using init.lua context only
If you are able to use the `init.lua` context only, then you can use the NoitaMP functions directly.\

If you are able to use the `init.lua` context only, then you can use the NoitaMP functions directly.
For example, if you want to get local player/Minä, then you can use the NoitaMP function `MinaUtils.getLocalMinaInformation()`:

```lua
--- Gets the local player information.
--- Including polymorphed entity id. When polymorphed, entityId will be the new one and not minäs anymore.
Expand All @@ -115,25 +130,29 @@ end
```

## 'Classes' in NoitaMP
Most of NoitaMPs functions are in 'class' tables, available in Luas globals `_G`.\

Most of NoitaMPs functions are in 'class' tables, available in Luas globals `_G`.
I tried to create topics for each class table, so you can find the global classes per topic:

- Mostly everything regarding Entities: `EntityUtils.lua`
- Mostly everything regarding Globals: `GlobalsUtils.lua`
- Mostly everything regarding Network: `NetworkUtils.lua`, besides `Server.lua` and `Client.lua`
- Mostly everything regarding (Network)VariableStorageComponents: `NetworkVscUtils.lua`
- Just some utilise functions: `util.lua`
- and so on...

I try to use KISS (Keep It Simple Stupid) and DRY (Don't Repeat Yourself) as much as possible.\
So before you want to add a new function, please try to use existing functions and classes, if possible.\
I try to use KISS (Keep It Simple Stupid) and DRY (Don't Repeat Yourself) as much as possible.
So before you want to add a new function, please try to use existing functions and classes, if possible.
If there are no existing functions or classes you could use, then take in mind:

- to create a new class with functions
- or to add functions to existing classes
- and add the `CustomProfiler` per new function.

`CustomProfiler` is a class that is used to measure the execution time of a function, because we had terrible performance issues and memory leaks in the past.\
Therefore it is important to measure the time of each function, so we can find the functions that are causing performance issues.\
`CustomProfiler` is a class that is used to measure the execution time of a function, because we had terrible performance issues and memory leaks in the past.
Therefore it is important to measure the time of each function, so we can find the functions that are causing performance issues.
To add the CustomProfiler to a function, you can use the following example:

```lua
function EntityUtils.isEntityPolymorphed(entityId)
-- first line of the function should be the CustomProfiler
Expand All @@ -150,33 +169,44 @@ end
```

## Making use of LuaRocks

### Setup

### Usage

## TTD - Test Driven Development
Please! Please! Please, make sure to write tests for your functions!\
I know it is not easy to write tests, but it is very important to do so.\
If you are not able to write tests, then please ask for help in the Discord server.\
I will help you to write tests for your functions.\
I will not accept any pull requests without tests, sorry.\

Please! Please! Please, make sure to write tests for your functions!
I know it is not easy to write tests, but it is very important to do so.
If you are not able to write tests, then please ask for help in the Discord server.
I will help you to write tests for your functions.
I will not accept any pull requests without tests, sorry.

### Location of tests

`mods/noita-mp/tests/`

### How to run tests

See LuaRocks section above.

### How to write tests?
Simple example by adding a new function to an existing test class:\

Simple example by adding a new function to an existing test class:
_Assume you've added a new event to **NetworkUtils.events**, then make sure to extend the **TestNetworkUtils** table in **NetworkUtils_test.lua**.)_

```lua
```

How to run tests?\
How to run tests?
`luarocks test > result.log`

If there are any questions left, then please ask them on [Discord](https://discord.gg/DhMurdcw4k).

### Important resources

Along with this document, the following resources are important when contributing to NoitaMP:

- documentation
- bugs
- communication
Loading

0 comments on commit 4160934

Please sign in to comment.