NiftyManiac / factorio-stickynotes

StickyNotes mod for Factorio
MIT License
2 stars 6 forks source link

Note text lost when revived by script #18

Open Adilf opened 7 years ago

Adilf commented 7 years ago

Let me pester you a bit more. You see, I'm writing a mod that revives blueprints via command. Unlike creative mod that doesn't infer global changes in the behavior of the blueprints. I use it to spawn some bases that do not belong to player force.

Currently I try to warn other mods about their entities by throwing events pretending to be robot building. However, spawned sticky notes seem to lose their text somehow. I've checked the blueprints, they do contain correct entities (note signs).

I don't quite grasp the flow of sticky notes logic, so maybe you could tell, what in needs to be changed in the code below for sticky notes to be spawned correctly? I use the following code to do the spawning:

local event = function(e)--this function is used to fake robot building
    game.raise_event(defines.events.on_robot_built_entity,{
        name=defines.events.on_robot_built_entity,
        created_entity=e,
        robot={valid=false},
        tick=game.tick,
        })
end

local es=i.build_blueprint{surface=s,force=force,position=pos}

for _,e in pairs(es) do
    event(e)
end

for k,v in pairs(es) do if not v.valid then
    --see if mods took some of their entities
    table.remove(es,k)
end end

for t,g in pairs(es) do if g.ghost_type=='tile' then
    --build tiles
    _,n=g.revive()
    if n then event(n) end
    table.remove(es,t)
end end

for k,v in pairs(es) do if not v.valid then
    --see if tiles erased some ghosts
    table.remove(es,k)
end end

local built={}

for _,g in pairs(es) do 
    --build entities
    local _,n= g.revive()
    if n then
        table.insert(built,n)--i do things to revived buildings, so I need an array of them
    end
end

for k,b in pairs(built) do
    event(b)
end
Adilf commented 7 years ago

Additionally, it'd be nice if there was remote interface to setup the signs via script.

Adilf commented 7 years ago

Did some testing. For whatever reason if the leftmost sign in the blueprint is autoshown, it can retain its message. Sometimes the ordinary sign retains their info as well.