Skip to content

Commit b8cf9c0

Browse files
Merge pull request #5 from Con-JS-Development/development
Documentation
2 parents 2f5d7a0 + 00a89c5 commit b8cf9c0

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Con-Databases
22
This package contains three types of databases, JsonDatabase, NBTDatabase, CustomDatabase.
33
Each of these database types supports all possible [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) class operations from ECMAScript, which means.
4+
- [Starting Using Con-Databases](./docs/HOW_TO_SETUP.md)
5+
- [Using CustomDatabase](./docs/CUSTOM_DATABASE.md) *(Soon)*
6+
47
### Inherited from Map
58
- size: number of properties
69
- [Symbol.iterator]: is iterable [key, value]

docs/HOW_TO_SETUP.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Starting with Con-Databases
2+
If you don't have experience with the Map build-in class, go get acquainted. Here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
3+
4+
## Steps
5+
6+
### Downloading specific version
7+
Pick your version what you want to use [here](https://github.com/Con-JS-Development/Con-Database/tags)
8+
9+
![](./Images/Tags%20Versions.png)
10+
11+
Then download your required files
12+
- *(try downloading types for better experience)*
13+
14+
![](./Images/Assets.png)
15+
16+
### Import and use!
17+
- Place database files into your coding folder
18+
- Import your required classes from database file
19+
```js
20+
import {JsonDatabase} from "./database"; //import your downloaded file
21+
```
22+
Now you can just use, save and load your data
23+
```js
24+
25+
const database = new JsonDatabase("my_database_id").load();
26+
27+
database.set("some key", "string data");
28+
database.set("some key2", 645654);
29+
database.set("some key3", ["array","array",{name:"object"}]);
30+
31+
database.get("some key2") - 645654;
32+
database.get("some key") + " is useful";
33+
database.remove("some key3");
34+
```
35+
## Example saving deaths for each player
36+
Each key is unique to its player because key include players id, so database keys looks like
37+
```
38+
5648463deaths
39+
6843684deaths
40+
6545463deaths
41+
```
42+
Code
43+
```js
44+
import {world} from "@minecraft/server";
45+
46+
const stats = new JsonDatabase("playerStats").load();
47+
48+
world.afterEvents.entityDie.subscribe(({deadEntity})=>
49+
setDeaths(deadEntity,getDeaths(deadEntity) + 1);
50+
,{entityTypes:["mineraft:player"]});
51+
52+
53+
function getDeaths(player){
54+
return stats.get(player.id + "deaths")??0;}
55+
56+
function setDeaths(player,deaths){
57+
stats.set(player.id + "deaths",deaths);}
58+
```

docs/Images/Assets.png

5.87 KB
Loading

docs/Images/Tags Versions.png

10.9 KB
Loading

0 commit comments

Comments
 (0)