Skip to content

Commit

Permalink
refract the codes and add spliters and tesla_coils
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaqyoo committed Mar 20, 2022
1 parent 6e06750 commit 023dc8d
Show file tree
Hide file tree
Showing 21 changed files with 1,261 additions and 920 deletions.
12 changes: 3 additions & 9 deletions BP/blueprint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { time } from "console"
import { fstat } from "fs"
import { Area } from "./area"
import { Building, BuildingList } from "./builiding/builiding"
import { Building } from "./building/building"

const game_version = '0.9.24.11286'

Expand Down Expand Up @@ -106,12 +104,8 @@ export class BluePrint {
return building
}

addBuildings(buildings:BuildingList):BuildingList {
buildings.forEach((building, index, buildings) => {
building.setIndex(this.data.building_count)
this.data.buildings.push(building)
this.data.building_count++
});
addBuildings(buildings:Array<Building>):Array<Building> {
buildings.forEach(building => this.addBuilding(building))
return buildings
}
}
73 changes: 73 additions & 0 deletions BP/building/assembler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { local_diff } from "../../util";
import { Building } from "./building";
import { InserterLocalParam } from "./inserter";

export class Assembler extends Building {
constructor(
area_index:number,
local:[number, number, number] | null,
level = 3)
{
let item_id: number, model_index: number
if (level == 1) {
item_id = 2303
model_index = 65
}
else if (level == 2) {
item_id = 2304
model_index = 66
}
else if (level == 3) {
item_id = 2305
model_index = 67
}

super(area_index, local,local, item_id, model_index)
}

getInserterLocal(slot: number, is_ingress: boolean): InserterLocalParam {
let param = new InserterLocalParam()
let local: [number, number, number][]
let local_base = this.getLocal()

switch (slot) {
case 0:
case 1:
case 2:
local = [local_diff(local_base, [(1 - slot)*0.8, -0.8, 0]), local_diff(local_base, [(1 -slot)*0.8, -2, 0])]
break;

case 3:
case 4:
case 5:
local = [local_diff(local_base, [-0.8, (slot - 5)*0.8, 0]), local_diff(local_base, [-2, (slot - 5)*0.8, 0])]
break;

case 6:
case 7:
case 8:
local = [local_diff(local_base, [(slot - 7)*0.8, 0.8, 0]), local_diff(local_base, [(slot - 7)*0.8, 2, 0])]
break;

case 9:
case 10:
case 11:
local = [local_diff(local_base, [0.8, (10 - slot)*0.8, 0]), local_diff(local_base, [2, (10 -slot)*0.8, 0])]
break;
}

if (is_ingress) {
param.output_to_slot = slot
param.setOutputObject(this)
param.local2 = local[0]
param.local = local[1]
}
else {
param.input_from_slot = slot
param.setInputObject(this)
param.local2 = local[1]
param.local = local[0]
}
return param
}
}
103 changes: 21 additions & 82 deletions BP/builiding/belt.ts → BP/building/belt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BluePrint } from "../blueprint";
import { Building, BuildingList, BuilidingParam } from "./builiding";
import { Building, BuilidingParam } from "./building";

class BeltParamLabel {
label: number
Expand Down Expand Up @@ -42,9 +42,7 @@ export class BeltBlueprintParam extends BuilidingParam {
export class Belt extends Building {
constructor(
area_index:number,
local_offset_x:number,
local_offset_y:number,
local_offset_z:number,
local:[number, number, number] | null,
level=3,
) {
let item_id = 2003
Expand All @@ -55,25 +53,11 @@ export class Belt extends Building {
model_index = 37
}

super(area_index,
local_offset_x, local_offset_y, local_offset_z,
local_offset_x, local_offset_y, local_offset_z,
item_id, model_index, false)
if (local === null) local = [0, 0, 0]

super(area_index,local, undefined, item_id, model_index, false)
this.param = new BeltBlueprintParam()
this.header.parameter_count = 0
}

setLocal(
local_offset_x:number,
local_offset_y:number,
local_offset_z:number
) {
this.header.local_offset_x = local_offset_x
this.header.local_offset_x2 = local_offset_x
this.header.local_offset_y = local_offset_y
this.header.local_offset_y2 = local_offset_y
this.header.local_offset_z = local_offset_z
this.header.local_offset_z2 = local_offset_z
this.header.output_to_slot = 1
this.header.input_to_slot = 1
}
Expand Down Expand Up @@ -104,12 +88,24 @@ export class Belt extends Building {
}
}
}

setLabel(label:number) {
this.header.parameter_count = this.param.setLabel(label)
}
}

export function setBeltsLocalAndConnect(belts:Belt[], count: number, startLocal: [number, number, number], diff: [number, number, number]) {
export function connectBelts(belts:Array<Belt>) {
belts.forEach((belt, index) => {
if (index < belts.length - 1) {
belt.connect(belts[index + 1])
}
});
}

export function setBeltsLocalAndConnect(belts:Array<Belt>, count: number, startLocal: [number, number, number], diff: [number, number, number]) {
for (let index = 0; index < count; index++) {
let belt = belts[index];
belt.setLocal(startLocal[0] + diff[0] * index, startLocal[1] + diff[1] * index, startLocal[2] + diff[2] * index)
belt.setLocal([startLocal[0] + diff[0] * index, startLocal[1] + diff[1] * index, startLocal[2] + diff[2] * index])
if (index < count - 1) {
belt.connect(belts[index + 1])
}
Expand All @@ -123,7 +119,7 @@ export function appendBelts(bp: BluePrint, belts: Array<Belt>, count: number, di
let x = belt.header.local_offset_x, y = belt.header.local_offset_y, z = belt.header.local_offset_z
if (diff === undefined) diff = [0, 0, 0]
for (let i = 0; i < count; i++) {
let next_belt = new Belt(area_index, x + (i+1)*diff[0], y + (i+1)*diff[1], z + (i+1)*diff[2])
let next_belt = new Belt(area_index, [x + (i+1)*diff[0], y + (i+1)*diff[1], z + (i+1)*diff[2]])
bp.addBuilding(next_belt)
if (diff !== [0, 0, 0]) belt.connect(next_belt)
belts.push(next_belt)
Expand All @@ -135,66 +131,9 @@ export function prependBelts(bp: BluePrint, belts: Array<Belt>, count: number) {
let area_index = belts[0].header.area_index
let tmp_belts = new Array<Belt>()
for (let i = 0; i < count; i++) {
let pre_belt = new Belt(area_index, 0, 0, 0)
let pre_belt = new Belt(area_index, [0, 0, 0])
bp.addBuilding(pre_belt)
tmp_belts.push(pre_belt)
}
belts = tmp_belts.concat(belts)
}

export class BeltList extends BuildingList{
lst:Array<Belt>

constructor(
area_index:number, count:number,
local:[number,number,number],
diff = [1, 0, 0],
level = 3
) {
super()
this.lst = new Array<Belt>()
for (let index = 0; index < count; index++) {
this.lst.push(new Belt(area_index, local[0]+diff[0]*index, local[1]+diff[1]*index, local[2]+diff[2]*index, level))
}
}

getList() : Array<Belt> {
return this.lst
}

add(
area_index:number,
local_offset_x:number,
local_offset_y:number,
local_offset_z:number,
level=3
)
{
this.lst.push(new Belt(
area_index,
local_offset_x, local_offset_y, local_offset_z,
level
))
}

// Must after set belt index
// connect() {
// this.lst.forEach((belt, index, belt_list)=>{
// if (index > 0 ) {
// belt.header.input_object_index = belt_list[index - 1].header.index
// }
// if (index + 1 < belt_list.length) {
// belt.header.output_object_index = belt_list[index + 1].header.index
// }

// // Todo: how to set the input/output from/to slot?
// belt.header.output_to_slot = 1
// belt.header.input_to_slot = 1
// })
// return this
// }

// reverse() {
// // Todo
// }
}
Loading

0 comments on commit 023dc8d

Please sign in to comment.