demodude4u / Factorio-FBSR

Factorio Blueprint String Renderer
MIT License
75 stars 20 forks source link

Can I render a blueprint string locally? (No bots) #126

Closed danielniccoli closed 4 years ago

danielniccoli commented 4 years ago

Can I use this to render a blueprint string locally, by passing the blueprint string in the command line?

How would I do that?

Bilka2 commented 4 years ago

Not currently. I can probably add a way to do that if you can describe what exactly you want. For example, do you want to supply image dimensions? Should the image be saved locally or uploaded to an image host? Do you want a commandline option or config file option for the previous question? Etc etc

Bilka2 commented 4 years ago

Also, it would be nice if you could describe your general use case(s). For example, the web API that is already available might also do the job, depending on the use case.

danielniccoli commented 4 years ago

My use case is this: I'd like to render a blueprint string using FSBR from within my python. Using your web API would add unnecessary overhead, both to the python app and the system configuration. Having a jar file would make it much simpler. I could call that from my python app as well as from a cron job.

Talking about options is a bit difficult for me. I don't know what options FSBR offers. I just describe a few, that I would find handy.

grafik (Visual reference)

demodude4u commented 4 years ago

The reason for preferring the Web API over running command arguments to a jar, is because FBSR pre-loads a lot of information related to image assets and running the lua interpreter on the factorio data. If you were to try and run FBSR every time you need an image rendered, you would have a large overhead of loading the factorio data every time.

danielniccoli commented 4 years ago

I see. Makes sense.

So back to topic, I now know there is a web service that I can start. How do I actually do that?

demodude4u commented 4 years ago

(I found an issue with one of the repositories while trying to test this)

The Web API only works on Java 8

You can modify the config.json to be only a Web API:

{
    "webapi": {
        "port": 8081,
        "bind": "0.0.0.0",
        "use-local-storage": true,
        "local-storage": "C:\\FBSR\\Images"
    },
    "factorio": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Factorio"
}

Set local-storage to a folder your python script can access. FBSR will use this folder to store completed image renders.

Command the Web API by sending a POST to /blueprint containing a JSON object:

POST http://localhost:8081/blueprint

Content-Type: application/json

{
  "blueprint": "https://pastebin.com/REkHLQTj (or any blueprint string)",
  "show-info-panels": true,
  "max-width": 10000,
  "max-height": 10000
}

The Web API will reply with a JSON object:

{
  "info": ["(Modded features are shown as question marks)"],
  "images": [
    {"link": "Blueprint1591052237564.png"},
    {"link": "Blueprint1591052237699.png"},
    {"link": "Blueprint1591052237812.png"},
    {"link": "Blueprint1591052237964.png"},
    {"link": "Blueprint1591052238095.png"},
    {"link": "Blueprint1591052238205.png"},
    {"link": "Blueprint1591052238329.png"},
    {"link": "Blueprint1591052238464.png"},
    {"link": "Blueprint1591052238570.png"},
    {"link": "Blueprint1591052238684.png"},
    {"link": "Blueprint1591052238778.png"},
    {"link": "Blueprint1591052238843.png"},
    {"link": "Blueprint1591052239006.png"},
    {"link": "Blueprint1591052239108.png"},
    {"link": "Blueprint1591052240965.png"}
  ]
}

show-info-panels, max-width, and max-height are optional.

demodude4u commented 4 years ago

Right now, there is no guide to setting up, running, or building a jar.

Since an extensive guide is beyond the scope of this issue, I'll only outline the general process here. If you would like some more help, find me on discord (Demod#0001) and I'll try to walk through the process.

Setting Up and Running in Eclipse

  1. Download and install Factorio. FBSR uses assets directly from a Factorio install.
  2. Download and install Java JDK 8. I recommend using AdoptOpenJDK.
  3. Download and install the latest version of Eclipse IDE for Java Developers. The project files contained within FBSR (and related projects) are eclipse project files.
  4. Verify eclipse is configured to use Java JDK 8.
  5. Download and import projects into eclipse (or git clone) Factorio-FBSR, Java-Factorio-Data-Wrapper, and Discord-Core-Bot-Apple. Eclipse has maven included, so these three projects will build and link together automatically, as well as automatically download and build other dependencies via maven.
  6. Verify Eclipse has finished building the three projects with no errors. If you encounter any errors at this point, let me know on discord and we can try to figure it out.
  7. Copy the example config.json shown in my last comment and save it in the project folder for Factorio-FBSR. Make the appropriate modifications that link Factorio and the Web API.
  8. To run, right-click FactorioBlueprintStringRenderer/src/com/demod/fbsr/app/StartAllServices.java in Eclipse, and click Run As... -> Java Application

Building a Jar and Running without Eclipse

  1. Right-click FactorioBlueprintStringRenderer Project in Eclipse, and click Export...
  2. Select Java -> Runnable Jar File.
  3. Pick Run Configuration StartAllServices - FactorioBlueprintStringRenderer, set an export destination (.jar file), and click Finish. This will package all binaries from all dependencies into one large jar file. It will likely finish with warnings, but that is okay.
  4. Copy the config.json file to where the jar file is located.
  5. To run the jar, use the command java -Xmx4g -jar <jar file>.jar. The program java should be installed on the PATH when Java JDK 8 was installed, but if not, you can directly call java.exe in the bin folder of the Java 8 JDK install location.

Whew.

I hope I did not forget anything when writing down these instructions, I'll edit this comment if I find something else to add!

danielniccoli commented 4 years ago

Thanks, that worked. Haven't run the jar yet, but I could build and package it. If it's not too much to ask, maybe when you do your next version, could you upload the jar as a release package in github? That' be great.