Skip to content
This repository was archived by the owner on Jun 25, 2023. It is now read-only.

Commit 155b8aa

Browse files
Merge pull request #1 from NotoriousPyro/1.0.3-pre
1.0.3 pre
2 parents 9dd55bd + 9354928 commit 155b8aa

23 files changed

+444
-235
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root=true
2+
3+
[*.cs]
4+
indent_style = space
5+
indent_size = 4

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Builds/
1414
*.suo
1515
*.user
1616
.vsconfig
17-
dist/
17+
release/
1818

1919
# Windows rubbish
2020
Thumbs.db

Builders/SorterProtoBuilder.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Mafi.Core.Economy;
2+
using Mafi.Core.Entities.Static;
3+
using Mafi.Core.Prototypes;
4+
using Mafi.Core.Factory.Sorters;
5+
6+
7+
namespace Mafi.Core.Mods;
8+
9+
public class SorterProtoBuilder : IProtoBuilder
10+
{
11+
public class State : LayoutEntityBuilderState<State>
12+
{
13+
private readonly StaticEntityProto.ID m_id;
14+
15+
public State(SorterProtoBuilder builder, StaticEntityProto.ID id, string name)
16+
: base(builder, id, name)
17+
{
18+
m_id = id;
19+
}
20+
21+
[MustUseReturnValue]
22+
public override State Description(string description, string explanation = "short description of a machine")
23+
{
24+
return base.Description(description, explanation);
25+
}
26+
27+
[MustUseReturnValue]
28+
public State SetElectricityConsumption(Electricity electricity)
29+
{
30+
base.Electricity = electricity;
31+
return (State)this;
32+
}
33+
34+
[MustUseReturnValue]
35+
public State SetDeconstructionParams(AssetValue productGiven, EntityCosts entityCosts)
36+
{
37+
// Assert.That(productGiven.IsNotEmpty).IsTrue();
38+
// Assert.That(durationPerProduct).IsPositive();
39+
// m_durationPerProduct = durationPerProduct;
40+
// m_productsGiven = productGiven;
41+
return this;
42+
}
43+
44+
public SorterProto BuildAndAdd()
45+
{
46+
return AddToDb(new SorterProto(m_id, base.Strings, layout: base.LayoutOrThrow, productsFilter: base.ProductsFilterOrThrow, costs: base.Costs, base.Electricity, graphics: base.Graphics));
47+
}
48+
}
49+
50+
public ProtosDb ProtosDb => Registrator.PrototypesDb;
51+
52+
public ProtoRegistrator Registrator
53+
{
54+
get;
55+
}
56+
57+
public SorterProtoBuilder(ProtoRegistrator registrator)
58+
: base()
59+
{
60+
Registrator = registrator;
61+
}
62+
63+
public State Start(string name, StaticEntityProto.ID labId)
64+
{
65+
return new State(this, labId, name);
66+
}
67+
}

Builders/ZipperProtoBuilder.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Mafi.Core.Economy;
2+
using Mafi.Core.Entities.Static;
3+
using Mafi.Core.Prototypes;
4+
using Mafi.Core.Factory.Zippers;
5+
6+
7+
namespace Mafi.Core.Mods;
8+
9+
public class ZipperProtoBuilder : IProtoBuilder
10+
{
11+
public class State : LayoutEntityBuilderState<State>
12+
{
13+
private readonly StaticEntityProto.ID m_id;
14+
15+
public State(ZipperProtoBuilder builder, StaticEntityProto.ID id, string name)
16+
: base(builder, id, name)
17+
{
18+
m_id = id;
19+
}
20+
21+
[MustUseReturnValue]
22+
public override State Description(string description, string explanation = "short description of a machine")
23+
{
24+
return base.Description(description, explanation);
25+
}
26+
27+
[MustUseReturnValue]
28+
public State SetElectricityConsumption(Electricity electricity)
29+
{
30+
base.Electricity = electricity;
31+
return (State)this;
32+
}
33+
34+
[MustUseReturnValue]
35+
public State SetDeconstructionParams(AssetValue productGiven, EntityCosts entityCosts)
36+
{
37+
// Assert.That(productGiven.IsNotEmpty).IsTrue();
38+
// Assert.That(durationPerProduct).IsPositive();
39+
// m_durationPerProduct = durationPerProduct;
40+
// m_productsGiven = productGiven;
41+
return this;
42+
}
43+
44+
public ZipperProto BuildAndAdd()
45+
{
46+
return AddToDb(new ZipperProto(m_id, base.Strings, layout: base.LayoutOrThrow, costs: base.Costs, base.Electricity, graphics: base.Graphics));
47+
}
48+
}
49+
50+
public ProtosDb ProtosDb => Registrator.PrototypesDb;
51+
52+
public ProtoRegistrator Registrator
53+
{
54+
get;
55+
}
56+
57+
public ZipperProtoBuilder(ProtoRegistrator registrator)
58+
: base()
59+
{
60+
Registrator = registrator;
61+
}
62+
63+
public State Start(string name, StaticEntityProto.ID labId)
64+
{
65+
return new State(this, labId, name);
66+
}
67+
}

Extensions/ProtoRegistratorEx.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Mafi.Core.Mods;
2+
3+
public static class ProtoRegistratorEx
4+
{
5+
public static ZipperProtoBuilder ZipperProtoBuilder(this ProtoRegistrator registrator) => new ZipperProtoBuilder(registrator);
6+
public static SorterProtoBuilder SorterProtoBuilder(this ProtoRegistrator registrator) => new SorterProtoBuilder(registrator);
7+
}

Extensions/ProtosDbEx.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Mafi.Core.Ports.Io;
2+
using Mafi.Core.Factory.Zippers;
3+
using Mafi.Core.Factory.Sorters;
4+
using System;
5+
6+
namespace Mafi.Core.Prototypes;
7+
8+
public static class ProtosDbEx
9+
{
10+
public static ZipperProto GetZipperProto(this ProtosDb protosDb, IoPortShapeProto.ID portShape) =>
11+
protosDb.GetOrThrow<ZipperProto>(IdsCore.Transports.GetZipperIdFor(portShape));
12+
public static SorterProto GetSorterProto(this ProtosDb protosDb, IoPortShapeProto.ID portShape) =>
13+
protosDb.GetOrThrow<SorterProto>(IdsCore.Transports.GetSorterIdFor(portShape));
14+
}

Extensions/ZipperProtoBuilder.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.

Machines/UnpoweredBalancersData.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using Mafi.Base;
2+
using Mafi.Core;
3+
using Mafi.Core.Mods;
4+
using Mafi.Core.Ports.Io;
5+
using Mafi.Core.Entities.Static.Layout;
6+
using Mafi.Core.Prototypes;
7+
using Mafi.Core.Factory.Zippers;
8+
using Mafi.Core.Factory.Machines;
9+
10+
namespace UnpoweredBalancers.Machines;
11+
12+
internal class UnpoweredBalancersData : IModData
13+
{
14+
public void RegisterData(ProtoRegistrator registrator)
15+
{
16+
ZipperProto flatZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.FlatConveyor);
17+
ZipperProto moltenZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.MoltenMetalChannel);
18+
ZipperProto uShapeZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.LooseMaterialConveyor);
19+
ZipperProto pipeZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.Pipe);
20+
21+
register(
22+
registrator,
23+
Ids.IoPortShapes.FlatConveyor,
24+
UnpoweredBalancersIds.Machines.UnpoweredFlatBalancer,
25+
"Flat",
26+
Assets.Base.Zippers.BalancerFlat_prefab,
27+
flatZipperProto.Graphics.IconPath,
28+
Costs.Build.CP3(6)
29+
);
30+
register(
31+
registrator,
32+
Ids.IoPortShapes.MoltenMetalChannel,
33+
UnpoweredBalancersIds.Machines.UnpoweredMoltenBalancer,
34+
"Molten",
35+
Assets.Base.Zippers.BalancerMolten_prefab,
36+
moltenZipperProto.Graphics.IconPath,
37+
Costs.Build.CP3(9)
38+
);
39+
register(
40+
registrator,
41+
Ids.IoPortShapes.LooseMaterialConveyor,
42+
UnpoweredBalancersIds.Machines.UnpoweredUShapeBalancer,
43+
"U-shape",
44+
Assets.Base.Zippers.BalancerUShape_prefab,
45+
uShapeZipperProto.Graphics.IconPath,
46+
Costs.Build.CP3(9)
47+
);
48+
register(
49+
registrator,
50+
Ids.IoPortShapes.Pipe,
51+
UnpoweredBalancersIds.Machines.UnpoweredPipeBalancer,
52+
"Pipe",
53+
Assets.Base.Zippers.BalancerFluid_prefab,
54+
pipeZipperProto.Graphics.IconPath,
55+
Costs.Build.CP3(6)
56+
);
57+
}
58+
59+
private void register(
60+
ProtoRegistrator registrator,
61+
IoPortShapeProto.ID portShape,
62+
MachineProto.ID id,
63+
string name,
64+
string prefab,
65+
string icon,
66+
EntityCostsTpl costs
67+
) => registrator.ZipperProtoBuilder()
68+
.Start($"Unpowered {name} balancer", id)
69+
.Description($"Allows distributing and prioritizing products using any of its two input and output ports.")
70+
.SetCost(costs)
71+
.SetElectricityConsumption(Mafi.Electricity.Zero)
72+
.SetLayout(
73+
new EntityLayoutParams(null, useNewLayoutSyntax: true, null, portsCanOnlyConnectToTransports: true),
74+
Ports.SetLayout(registrator.PrototypesDb.GetOrThrow<IoPortShapeProto>(portShape).LayoutChar, " D?+C?+ ", "E?+[1][1]+?B", "F?+[1][1]+?A", " G?+H?+ ")
75+
)
76+
.SetCategories(Ids.ToolbarCategories.Transports)
77+
.SetPrefabPath(prefab)
78+
.SetCustomIconPath(icon)
79+
.BuildAndAdd();
80+
}

Machines/UnpoweredSortersData.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Mafi.Base;
2+
using Mafi.Core.Products;
3+
using Mafi.Core.Mods;
4+
using Mafi.Core.Ports.Io;
5+
using Mafi.Core.Entities.Static.Layout;
6+
using Mafi.Core.Prototypes;
7+
using Mafi.Core.Factory.Sorters;
8+
using Mafi.Core.Factory.Machines;
9+
10+
namespace UnpoweredBalancers.Machines;
11+
12+
internal class UnpoweredSortersData : IModData
13+
{
14+
public void RegisterData(ProtoRegistrator registrator)
15+
{
16+
SorterProto flatSorterProto = registrator.PrototypesDb.GetSorterProto(Ids.IoPortShapes.FlatConveyor);
17+
SorterProto uShapeSorterProto = registrator.PrototypesDb.GetSorterProto(Ids.IoPortShapes.LooseMaterialConveyor);
18+
19+
register(
20+
registrator,
21+
Ids.IoPortShapes.FlatConveyor,
22+
UnpoweredBalancersIds.Machines.UnpoweredFlatSorter,
23+
CountableProductProto.ProductType,
24+
"Flat",
25+
Assets.Base.Zippers.SorterFlat_prefab,
26+
flatSorterProto.Graphics.IconPath,
27+
Costs.Build.CP3(6)
28+
);
29+
register(
30+
registrator,
31+
Ids.IoPortShapes.LooseMaterialConveyor,
32+
UnpoweredBalancersIds.Machines.UnpoweredUShapeSorter,
33+
LooseProductProto.ProductType,
34+
"U-shape",
35+
Assets.Base.Zippers.SorterUShape_prefab,
36+
uShapeSorterProto.Graphics.IconPath,
37+
Costs.Build.CP3(9)
38+
);
39+
}
40+
41+
private void register(
42+
ProtoRegistrator registrator,
43+
IoPortShapeProto.ID portShape,
44+
MachineProto.ID id,
45+
ProductType productType,
46+
string name,
47+
string prefab,
48+
string icon,
49+
EntityCostsTpl costs
50+
) => registrator.SorterProtoBuilder()
51+
.Start($"Unpowered {name} sorter", id)
52+
.Description($"Allows sorting of products.")
53+
.SetCost(costs)
54+
.SetElectricityConsumption(Mafi.Electricity.Zero)
55+
.SetLayout(
56+
new EntityLayoutParams(null, useNewLayoutSyntax: true),
57+
Ports.SetLayout(registrator.PrototypesDb.GetOrThrow<IoPortShapeProto>(portShape).LayoutChar, "A?>[1][1]>?X", " [1][1] ", " v?S ")
58+
)
59+
.SetCategories(Ids.ToolbarCategories.Transports)
60+
.SetProductsFilter(
61+
(ProductProto x) => x.Type == productType
62+
)
63+
.SetPrefabPath(prefab)
64+
.SetCustomIconPath(icon)
65+
.BuildAndAdd();
66+
}
67+
68+
69+

0 commit comments

Comments
 (0)