Skip to content

Commit

Permalink
Factorio 2.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Nov 6, 2024
1 parent 2f6896d commit 901b528
Show file tree
Hide file tree
Showing 42 changed files with 1,640 additions and 224,469 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/test.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ semi: true
singleQuote: true
printWidth: 100
useTabs: true
overrides:
- files: ['**/*.yaml', '**/*.yml']
options:
tabWidth: 2
useTabs: false
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Jens Forstmann
Copyright (c) 2024 Jens Forstmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
39 changes: 13 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
## Features

- encode & decode blueprint strings
- fully typed
- support for deconstruction & upgrade planner
- support for nested blueprint books
- fully typed:
- blueprints
- blueprint books
- upgrade planner
- deconstruction planner



## Installation

```sh
npm install @jensforstmann/factorio-blueprint-tools
# or
yarn add @jensforstmann/factorio-blueprint-tools
```

## Usage

```typescript
import { encodePlan, decodePlan } from '@jensforstmann/factorio-blueprint-tools';
// or
const { encodePlan, decodePlan } = require('@jensforstmann/factorio-blueprint-tools');
```


Expand All @@ -36,45 +36,32 @@ Available functions:
- isDeconstructionPLanner
- isUpgradePlanner

Available types:
- blueprint
- blueprintBook
- color
- deconstructionPlanner
- entity
- icon
- itemFilter
- plan
- position
- signal
- tile
- upgradePlanner
- ... and more


## Examples

```typescript
import { encodePlan, decodePlan, isBlueprint, addEntity } from '@jensforstmann/factorio-blueprint-tools';

const bpString = '0eNp9j90KwjAMhV9l5LoO5w/WPoHvICKdCxpY09JGcYy+u91E9EoIJCec85GM0PZ3DJFYwIzQYbpECkKewcAB+96rSm6UqlKWK3RBhuriOYllKYNria34WIMCmvZgjiMkurLtJ6AMAQuJBF1xsHWT+uQX3zzkkucOn2CafFKALCSEb9wshjPfXYuxGP6CFASf6P3BCIW3rLcKhrnnCT3fYn7+VvDAmObASjeb3X61W691o7XO+QX5HWGk';
const bpString = '0eNqVUcFOhDAQ/RWcc9lkEVRIvK9nDx7MhhR2lElKi2VACeHfnUJcsx40ppf2dd6bN29mqMyAnSfLUMxwwr721DE5CwU86ilqKGIXcYPRu/PmdAUKqHa2h+J5hp5erTaBaHWLwgg/rC3HtWsrspqdh0UY9oQfUOyXowK0TEy4CayPqbRDW6GXAvWbkILO9bR5m0H08mSXKZigiNN0l0kfYbF3pqyw0SMJRep6rAOlv7xL7y9TCl7IMPqfKE9dcDKS50GGPFvbho4PgrzJh/gX0DrfrkXit9N+9VvA/QoMIdv9os7iyZ/iD/8VP8qRADqjJ/Tl5RoPaIyLnrb1hRUQYyv49+YVGF2hCbUUXSQ+Si6rSnaT5GmeZ2lye53c7ZflE3TWvxE=';

const plan = decodePlan(bpString);

if (isBlueprint(plan)) {
console.log(plan.blueprint.description); // Hello, this is an empty constant combinator.
console.log(plan.blueprint.description); // "Say hi to the world!"

plan.blueprint.description = "Hello, have another combinator.";
addEntity(plan, {
position: {
x: 1.5,
y: 0.5
x: plan.blueprint.entities[0].position.x + 1,
y: plan.blueprint.entities[0].position.y + 1
},
name: "constant-combinator"
});

const newBpString = encodePlan(plan);

console.log(newBPString); // 0eNp9kNEKwjAMRX9l5LkONxVrv8B/EJFuCxrY0tFm4hj9d7vtQUHwKQTuOdxkgqodsPfEAmaCBkPtqRdyDAbO2LZOZQ/7xMyykwf6rHZdRWzF+RwUUO04gLlMEOjOtp0dMvaYYBLsUoJtN29zTizL5sNDTDw3+AJTxKsCZCEhXHXLMt546Cr0KfBXpKB3gdbSEyTfNj8oGJcZo/qxlT9A8QX875yKLpeZr8cpeKIPi63Uxf54Ko+7nS601jG+AXGqduE=
console.log(newBPString); // 0eNqVkkFvgzAMhf8K8zmtVArbQOq9O++ww1RVgXqrpZCwYNgQ4r/PAY2pPWyquIDj9/nlmQEK02LtyTLkA5ywKT3VTM5CDs+6j84UsYv4jNGn8+Z0BwqodLaB/HWAht6tNkFodYWiCCesLa9KVxVkNTsPoyjsCb8g34wHBWiZmHAGTB/90bZVgV4a1F8gBbVraPY2gPCyeJ0q6CFfJck6lTmiYu/MscCz7kgk0tdgGSTN5bvM/jGl4I0Mo7+ucl8HJx15buWSi7X50qu9VD7kQPxL0TpfTU3it9Z+8pvDbiq0IdvNqBZ4/C/86Vb4QR4JoDa6R3+8XOMejXHRy7y+YOOmjLdLxtsp46uVxWGnxFgJ8PdXUmB0gSYMp+gC30nQEz29j7Mky9IkftjGj5tx/AajGdm0

} else {
console.error("not a blueprint");
Expand Down
6 changes: 3 additions & 3 deletions examples/01.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plan } from "../src/types/plan"
import { Plan } from "../src/plan";

const blueprint: Plan = {
"deconstruction_planner": {
Expand All @@ -23,7 +23,7 @@ const blueprint: Plan = {
],
"tile_filters": [
{
"name": "Arci-marking-white-dl-left-turn-down",
"name": "stone-path",
"index": 3
},
{
Expand Down Expand Up @@ -53,4 +53,4 @@ const blueprint: Plan = {
"label": "deconNAME",
"version": 281474976710656
}
}
};
4 changes: 2 additions & 2 deletions examples/02.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Plan } from "../src/types/plan"
import { Plan } from "../src/plan";

const blueprint: Plan = {
"deconstruction_planner": {
"settings": null,
"item": "deconstruction-planner",
"version": 281474976710656
}
}
};
4 changes: 2 additions & 2 deletions examples/03.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plan } from "../src/types/plan"
import { Plan } from "../src/plan";

const blueprint: Plan = {
"blueprint": {
Expand All @@ -24,4 +24,4 @@ const blueprint: Plan = {
"item": "blueprint",
"version": 281474976710656
}
}
};
4 changes: 2 additions & 2 deletions examples/04.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plan } from "../src/types/plan"
import { Plan } from "../src/plan";

const blueprint: Plan = {
"blueprint_book": {
Expand Down Expand Up @@ -106,4 +106,4 @@ const blueprint: Plan = {
"active_index": 0,
"version": 281474976710656
}
}
};
4 changes: 2 additions & 2 deletions examples/05.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plan } from "../src/types/plan"
import { Plan } from "../src/plan";

const blueprint: Plan = {
"deconstruction_planner": {
Expand All @@ -8,4 +8,4 @@ const blueprint: Plan = {
"item": "deconstruction-planner",
"version": 281474976710656
}
}
};
8 changes: 5 additions & 3 deletions examples/06.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plan } from "../src/types/plan"
import { Plan } from "../src/plan";

const blueprint: Plan = {
"upgrade_planner": {
Expand All @@ -11,7 +11,9 @@ const blueprint: Plan = {
},
"to": {
"type": "entity",
"name": "fast-transport-belt"
"name": "fast-transport-belt",
"module_limit": 0,
"module_slots": []
},
"index": 0
}
Expand All @@ -20,4 +22,4 @@ const blueprint: Plan = {
"item": "upgrade-planner",
"version": 281474976710656
}
}
};
Loading

0 comments on commit 901b528

Please sign in to comment.