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

Commit

Permalink
Merge pull request #1 from NotoriousPyro/1.0.3-pre
Browse files Browse the repository at this point in the history
1.0.3 pre
  • Loading branch information
NotoriousPyro authored Oct 8, 2022
2 parents 9dd55bd + 9354928 commit 155b8aa
Show file tree
Hide file tree
Showing 23 changed files with 444 additions and 235 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root=true

[*.cs]
indent_style = space
indent_size = 4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Builds/
*.suo
*.user
.vsconfig
dist/
release/

# Windows rubbish
Thumbs.db
Expand Down
67 changes: 67 additions & 0 deletions Builders/SorterProtoBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Mafi.Core.Economy;
using Mafi.Core.Entities.Static;
using Mafi.Core.Prototypes;
using Mafi.Core.Factory.Sorters;


namespace Mafi.Core.Mods;

public class SorterProtoBuilder : IProtoBuilder
{
public class State : LayoutEntityBuilderState<State>
{
private readonly StaticEntityProto.ID m_id;

public State(SorterProtoBuilder builder, StaticEntityProto.ID id, string name)
: base(builder, id, name)
{
m_id = id;
}

[MustUseReturnValue]
public override State Description(string description, string explanation = "short description of a machine")
{
return base.Description(description, explanation);
}

[MustUseReturnValue]
public State SetElectricityConsumption(Electricity electricity)
{
base.Electricity = electricity;
return (State)this;
}

[MustUseReturnValue]
public State SetDeconstructionParams(AssetValue productGiven, EntityCosts entityCosts)
{
// Assert.That(productGiven.IsNotEmpty).IsTrue();
// Assert.That(durationPerProduct).IsPositive();
// m_durationPerProduct = durationPerProduct;
// m_productsGiven = productGiven;
return this;
}

public SorterProto BuildAndAdd()
{
return AddToDb(new SorterProto(m_id, base.Strings, layout: base.LayoutOrThrow, productsFilter: base.ProductsFilterOrThrow, costs: base.Costs, base.Electricity, graphics: base.Graphics));
}
}

public ProtosDb ProtosDb => Registrator.PrototypesDb;

public ProtoRegistrator Registrator
{
get;
}

public SorterProtoBuilder(ProtoRegistrator registrator)
: base()
{
Registrator = registrator;
}

public State Start(string name, StaticEntityProto.ID labId)
{
return new State(this, labId, name);
}
}
67 changes: 67 additions & 0 deletions Builders/ZipperProtoBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Mafi.Core.Economy;
using Mafi.Core.Entities.Static;
using Mafi.Core.Prototypes;
using Mafi.Core.Factory.Zippers;


namespace Mafi.Core.Mods;

public class ZipperProtoBuilder : IProtoBuilder
{
public class State : LayoutEntityBuilderState<State>
{
private readonly StaticEntityProto.ID m_id;

public State(ZipperProtoBuilder builder, StaticEntityProto.ID id, string name)
: base(builder, id, name)
{
m_id = id;
}

[MustUseReturnValue]
public override State Description(string description, string explanation = "short description of a machine")
{
return base.Description(description, explanation);
}

[MustUseReturnValue]
public State SetElectricityConsumption(Electricity electricity)
{
base.Electricity = electricity;
return (State)this;
}

[MustUseReturnValue]
public State SetDeconstructionParams(AssetValue productGiven, EntityCosts entityCosts)
{
// Assert.That(productGiven.IsNotEmpty).IsTrue();
// Assert.That(durationPerProduct).IsPositive();
// m_durationPerProduct = durationPerProduct;
// m_productsGiven = productGiven;
return this;
}

public ZipperProto BuildAndAdd()
{
return AddToDb(new ZipperProto(m_id, base.Strings, layout: base.LayoutOrThrow, costs: base.Costs, base.Electricity, graphics: base.Graphics));
}
}

public ProtosDb ProtosDb => Registrator.PrototypesDb;

public ProtoRegistrator Registrator
{
get;
}

public ZipperProtoBuilder(ProtoRegistrator registrator)
: base()
{
Registrator = registrator;
}

public State Start(string name, StaticEntityProto.ID labId)
{
return new State(this, labId, name);
}
}
7 changes: 7 additions & 0 deletions Extensions/ProtoRegistratorEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Mafi.Core.Mods;

public static class ProtoRegistratorEx
{
public static ZipperProtoBuilder ZipperProtoBuilder(this ProtoRegistrator registrator) => new ZipperProtoBuilder(registrator);
public static SorterProtoBuilder SorterProtoBuilder(this ProtoRegistrator registrator) => new SorterProtoBuilder(registrator);
}
14 changes: 14 additions & 0 deletions Extensions/ProtosDbEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Mafi.Core.Ports.Io;
using Mafi.Core.Factory.Zippers;
using Mafi.Core.Factory.Sorters;
using System;

namespace Mafi.Core.Prototypes;

public static class ProtosDbEx
{
public static ZipperProto GetZipperProto(this ProtosDb protosDb, IoPortShapeProto.ID portShape) =>
protosDb.GetOrThrow<ZipperProto>(IdsCore.Transports.GetZipperIdFor(portShape));
public static SorterProto GetSorterProto(this ProtosDb protosDb, IoPortShapeProto.ID portShape) =>
protosDb.GetOrThrow<SorterProto>(IdsCore.Transports.GetSorterIdFor(portShape));
}
68 changes: 0 additions & 68 deletions Extensions/ZipperProtoBuilder.cs

This file was deleted.

80 changes: 80 additions & 0 deletions Machines/UnpoweredBalancersData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Mafi.Base;
using Mafi.Core;
using Mafi.Core.Mods;
using Mafi.Core.Ports.Io;
using Mafi.Core.Entities.Static.Layout;
using Mafi.Core.Prototypes;
using Mafi.Core.Factory.Zippers;
using Mafi.Core.Factory.Machines;

namespace UnpoweredBalancers.Machines;

internal class UnpoweredBalancersData : IModData
{
public void RegisterData(ProtoRegistrator registrator)
{
ZipperProto flatZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.FlatConveyor);
ZipperProto moltenZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.MoltenMetalChannel);
ZipperProto uShapeZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.LooseMaterialConveyor);
ZipperProto pipeZipperProto = registrator.PrototypesDb.GetZipperProto(Ids.IoPortShapes.Pipe);

register(
registrator,
Ids.IoPortShapes.FlatConveyor,
UnpoweredBalancersIds.Machines.UnpoweredFlatBalancer,
"Flat",
Assets.Base.Zippers.BalancerFlat_prefab,
flatZipperProto.Graphics.IconPath,
Costs.Build.CP3(6)
);
register(
registrator,
Ids.IoPortShapes.MoltenMetalChannel,
UnpoweredBalancersIds.Machines.UnpoweredMoltenBalancer,
"Molten",
Assets.Base.Zippers.BalancerMolten_prefab,
moltenZipperProto.Graphics.IconPath,
Costs.Build.CP3(9)
);
register(
registrator,
Ids.IoPortShapes.LooseMaterialConveyor,
UnpoweredBalancersIds.Machines.UnpoweredUShapeBalancer,
"U-shape",
Assets.Base.Zippers.BalancerUShape_prefab,
uShapeZipperProto.Graphics.IconPath,
Costs.Build.CP3(9)
);
register(
registrator,
Ids.IoPortShapes.Pipe,
UnpoweredBalancersIds.Machines.UnpoweredPipeBalancer,
"Pipe",
Assets.Base.Zippers.BalancerFluid_prefab,
pipeZipperProto.Graphics.IconPath,
Costs.Build.CP3(6)
);
}

private void register(
ProtoRegistrator registrator,
IoPortShapeProto.ID portShape,
MachineProto.ID id,
string name,
string prefab,
string icon,
EntityCostsTpl costs
) => registrator.ZipperProtoBuilder()
.Start($"Unpowered {name} balancer", id)
.Description($"Allows distributing and prioritizing products using any of its two input and output ports.")
.SetCost(costs)
.SetElectricityConsumption(Mafi.Electricity.Zero)
.SetLayout(
new EntityLayoutParams(null, useNewLayoutSyntax: true, null, portsCanOnlyConnectToTransports: true),
Ports.SetLayout(registrator.PrototypesDb.GetOrThrow<IoPortShapeProto>(portShape).LayoutChar, " D?+C?+ ", "E?+[1][1]+?B", "F?+[1][1]+?A", " G?+H?+ ")
)
.SetCategories(Ids.ToolbarCategories.Transports)
.SetPrefabPath(prefab)
.SetCustomIconPath(icon)
.BuildAndAdd();
}
69 changes: 69 additions & 0 deletions Machines/UnpoweredSortersData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Mafi.Base;
using Mafi.Core.Products;
using Mafi.Core.Mods;
using Mafi.Core.Ports.Io;
using Mafi.Core.Entities.Static.Layout;
using Mafi.Core.Prototypes;
using Mafi.Core.Factory.Sorters;
using Mafi.Core.Factory.Machines;

namespace UnpoweredBalancers.Machines;

internal class UnpoweredSortersData : IModData
{
public void RegisterData(ProtoRegistrator registrator)
{
SorterProto flatSorterProto = registrator.PrototypesDb.GetSorterProto(Ids.IoPortShapes.FlatConveyor);
SorterProto uShapeSorterProto = registrator.PrototypesDb.GetSorterProto(Ids.IoPortShapes.LooseMaterialConveyor);

register(
registrator,
Ids.IoPortShapes.FlatConveyor,
UnpoweredBalancersIds.Machines.UnpoweredFlatSorter,
CountableProductProto.ProductType,
"Flat",
Assets.Base.Zippers.SorterFlat_prefab,
flatSorterProto.Graphics.IconPath,
Costs.Build.CP3(6)
);
register(
registrator,
Ids.IoPortShapes.LooseMaterialConveyor,
UnpoweredBalancersIds.Machines.UnpoweredUShapeSorter,
LooseProductProto.ProductType,
"U-shape",
Assets.Base.Zippers.SorterUShape_prefab,
uShapeSorterProto.Graphics.IconPath,
Costs.Build.CP3(9)
);
}

private void register(
ProtoRegistrator registrator,
IoPortShapeProto.ID portShape,
MachineProto.ID id,
ProductType productType,
string name,
string prefab,
string icon,
EntityCostsTpl costs
) => registrator.SorterProtoBuilder()
.Start($"Unpowered {name} sorter", id)
.Description($"Allows sorting of products.")
.SetCost(costs)
.SetElectricityConsumption(Mafi.Electricity.Zero)
.SetLayout(
new EntityLayoutParams(null, useNewLayoutSyntax: true),
Ports.SetLayout(registrator.PrototypesDb.GetOrThrow<IoPortShapeProto>(portShape).LayoutChar, "A?>[1][1]>?X", " [1][1] ", " v?S ")
)
.SetCategories(Ids.ToolbarCategories.Transports)
.SetProductsFilter(
(ProductProto x) => x.Type == productType
)
.SetPrefabPath(prefab)
.SetCustomIconPath(icon)
.BuildAndAdd();
}



Loading

0 comments on commit 155b8aa

Please sign in to comment.