Skip to content

Conversation

@jgoldshlag
Copy link
Contributor

As mentioned, this is not tested at all in belt, though I did do manual testing of the mod stuff. I included a properly set up BP string in the tests dir as well

Copy link

@rpdelaney rpdelaney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was sent to me and I mistook it as a request for code review. I'm posting the comments I had because they were already mostly done. I hope they're useful; I love that this work is being done and I'm happy to have a dialogue about it.

That said, this isn't my code so feel free to ignore me if it's not helpful.

local first_ghost = bp_ghost[1]
local offset = {first_ghost.position.x - first_ent.position.x, first_ghost.position.y - first_ent.position.y}
for _, bpe in pairs(bp_entity.stack.get_blueprint_entities()) do
if bpe.name == 'big-mining-drill' and bpe.items ~= nil then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like (pseudocode):

if not (bpe.name == 'big-mining-drill' and bpe.items ~= nil) then
   continue
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that failing fast is often more readable than another layer of indentation.

pub verbose_metrics: Vec<String>,
pub strip_prefix: Option<String>,
pub headless: Option<bool>,
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at EOF

Comment on lines 27 to 35
if req.id.name == 'efficiency-module-3' and req.id.quality == nil then
s.create_entity{name="stone", amount=10000000, position={bpe.position.x + offset[1], bpe.position.y + offset[2]}}
elseif req.id.name == 'efficiency-module-3' and req.id.quality == 'uncommon' then
s.create_entity{name="iron-ore", amount=10000000, position={bpe.position.x + offset[1], bpe.position.y + offset[2]}}
elseif req.id.name == 'efficiency-module-3' and req.id.quality == 'rare' then
s.create_entity{name="copper-ore", amount=10000000, position={bpe.position.x + offset[1], bpe.position.y + offset[2]}}
elseif req.id.name == 'efficiency-module-3' and req.id.quality == 'epic' then
s.create_entity{name="coal", amount=10000000, position={bpe.position.x + offset[1], bpe.position.y + offset[2]}}
end
Copy link

@rpdelaney rpdelaney Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have lots of long elseif chains, such as this one here. This pattern adds a lot of complexity to the code, making it more difficult to maintain and understand. It may be better to use a mapping data structure of some kind for looking up the ore type to place instead. Pseudocode:

resourceMapping = {
  [nil]    = "stone",
  uncommon = "iron-ore",
  rare     = "copper-ore",
  epic     = "coal"
}

function tryCreateResource(bpe, req) {
  resource = resourceMapping[req.id.quality]

  if bpe.name != "big-mining-drill"
     or not bpe.items
     or not resource
     or req.id.name != "efficiency-module-3" then
     return
  end

  s.create_entity{
    name = resource,
    amount = 10000000,
    position = {
      bpe.position.x + offset[1], 
      bpe.position.y + offset[2]
    }
  }
}

for _, bpe in pairs(bp_entity.stack.get_blueprint_entities()) do
  for _, req in pairs(bpe.items) do
    tryCreateResource(bpe, req)
  end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is more in this file and elsewhere in the PR that is ripe for such improvements to readability and test-ability. Hope this makes sense :)

@jgoldshlag
Copy link
Contributor Author

It seems like your latest changes lost the ability to run for a number of ticks before saving, no?

@florishafkenscheid
Copy link
Owner

It seems like your latest changes lost the ability to run for a number of ticks before saving, no?

Correct, I want to keep benchmarking and blueprinting separate.

@jgoldshlag
Copy link
Contributor Author

Right, but after placing the BP, we need to let it fill up buffers and stuff before you can benchmark it

@florishafkenscheid
Copy link
Owner

Right, but after placing the BP, we need to let it fill up buffers and stuff before you can benchmark it

Good shout, I'll revert to user input.

@florishafkenscheid florishafkenscheid force-pushed the benchmark-from-blueprints branch from dc440b4 to d975d6e Compare October 13, 2025 12:50
@jgoldshlag
Copy link
Contributor Author

I also wonder if we should be converting all the BPs to saves, then moving those saves somewhere. It would then enable us to check modification times on the bp files vs the converted saves to avoid having to regen stuff if only some bps changed

@florishafkenscheid
Copy link
Owner

There's already an --output option, and if the user only changes 3 of 10 bps, they'll just have to work with --pattern or removing bp files from the directory

@florishafkenscheid florishafkenscheid merged commit 7b9121a into florishafkenscheid:master Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants