Skip to content

Instantly share code, notes, and snippets.

@KazKoboDev
Created February 1, 2015 20:18
Show Gist options
  • Save KazKoboDev/7685b11036cc78b558e3 to your computer and use it in GitHub Desktop.
Save KazKoboDev/7685b11036cc78b558e3 to your computer and use it in GitHub Desktop.
This script builds a new version of the WeComeInPeace mod for Starbound. It must be run inside a directory next to the spawner.config file.
require 'fileutils'
require 'json'
template = ' {
"op": "replace",
"path": "/spawns/CREATURE/monsterParameters/aggressive",
"value": false
}'
puts "#{Time.now.strftime("%H:%M:%S")} : Scanning for aggressive aliens"
File.open("spawner.config", "r+") do |spawner|
contents = File.read(spawner)
json = JSON.parse(contents)
@hostiles = Array.new
json["spawns"].map do |hostile|
name = hostile.first.to_s
hostile.each do |details|
next if details.is_a? String
if details["monsterParameters"]["aggressive"] == true
@hostiles << name
end
end
end
end
puts "#{Time.now.strftime("%H:%M:%S")} : Preparing Buildspace"
# You'll need to manually add a modinfo file
if File.exist?("#{Dir.pwd}/WCIP/spawner.config.patch")
FileUtils.rm_rf(Dir.glob("#{Dir.pwd}/WCIP/spawner.config.patch"))
else
FileUtils.mkdir_p("#{Dir.pwd}/WCIP")
end
puts "#{Time.now.strftime("%H:%M:%S")} : Starting build"
patch_contents = "[\n"
@hostiles.each do |name|
modified_template = template.gsub("CREATURE", name.to_s)
patch_contents << "#{modified_template}, \n"
end
patch_contents.chomp!(", \n")
patch_contents << "\n]"
File.open("#{Dir.pwd}/WCIP/spawner.config.patch", "w+") do |patch|
patch.write(patch_contents)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment