Update convert-dump with groups, scrubbing
Update the convert-dump script to allow mod scripts to assign groups and to scrub inout lines to remove/replace text from the Minetweaker output.
This commit is contained in:
+27
-4
@@ -170,6 +170,7 @@ lookUpItems = (itemIds)->
|
|||||||
gridCell.item = item
|
gridCell.item = item
|
||||||
|
|
||||||
normalizeMinecraftId = (minecraftId)->
|
normalizeMinecraftId = (minecraftId)->
|
||||||
|
return null unless minecraftId
|
||||||
return minecraftId unless minecraftId.mod is 'ore'
|
return minecraftId unless minecraftId.mod is 'ore'
|
||||||
entries = MOD.oreDict[minecraftId.toString()]
|
entries = MOD.oreDict[minecraftId.toString()]
|
||||||
return minecraftId unless entries?
|
return minecraftId unless entries?
|
||||||
@@ -258,6 +259,10 @@ parseRecipeInputs = (recipeType, text)->
|
|||||||
|
|
||||||
# Stage Functions ######################################################################################################
|
# Stage Functions ######################################################################################################
|
||||||
|
|
||||||
|
assignGroups = ->
|
||||||
|
for item in MOD.items
|
||||||
|
MOD.assignGroup item
|
||||||
|
|
||||||
copyImages = ->
|
copyImages = ->
|
||||||
for item in MOD.items
|
for item in MOD.items
|
||||||
continue unless item.iconFile?
|
continue unless item.iconFile?
|
||||||
@@ -284,10 +289,12 @@ loadModHelper = ->
|
|||||||
MOD.oreDict ?= {}
|
MOD.oreDict ?= {}
|
||||||
|
|
||||||
MOD.adjustRecipe ?= (recipe)-> return recipe
|
MOD.adjustRecipe ?= (recipe)-> return recipe
|
||||||
|
MOD.assignGroup ?= (item)-> return null
|
||||||
MOD.contains ?= (id)-> return true
|
MOD.contains ?= (id)-> return true
|
||||||
MOD.correctItem ?= (item)-> # do nothing
|
MOD.correctItem ?= (item)-> # do nothing
|
||||||
MOD.makeCorrections ?= -> # do nothing
|
MOD.makeCorrections ?= -> # do nothing
|
||||||
MOD.normalizeName ?= (item, index=1)-> return item.gameName
|
MOD.normalizeName ?= (item, index=1)-> return item.gameName
|
||||||
|
MOD.scrubMinetweakerLine ?= (lineText)-> return lineText
|
||||||
MOD.shouldNormalizeGrid ?= (item, grid)-> return false
|
MOD.shouldNormalizeGrid ?= (item, grid)-> return false
|
||||||
|
|
||||||
makeCorrections = ->
|
makeCorrections = ->
|
||||||
@@ -310,6 +317,7 @@ removeDuplicates = ->
|
|||||||
scanFurnaceRecipes = ->
|
scanFurnaceRecipes = ->
|
||||||
fileText = fs.readFileSync path.join(WORLD_DIR, MINETWEAKER_LOG), 'utf-8'
|
fileText = fs.readFileSync path.join(WORLD_DIR, MINETWEAKER_LOG), 'utf-8'
|
||||||
for line in fileText.split '\n'
|
for line in fileText.split '\n'
|
||||||
|
line = MOD.scrubMinetweakerLine line
|
||||||
match = line.match /furnace.addRecipe\(<([^>]*)>, <([^>]*)>/
|
match = line.match /furnace.addRecipe\(<([^>]*)>, <([^>]*)>/
|
||||||
continue unless match?
|
continue unless match?
|
||||||
|
|
||||||
@@ -421,6 +429,7 @@ scanOreDict = ->
|
|||||||
scanRecipes = ->
|
scanRecipes = ->
|
||||||
fileText = fs.readFileSync path.join(WORLD_DIR, MINETWEAKER_LOG), 'utf-8'
|
fileText = fs.readFileSync path.join(WORLD_DIR, MINETWEAKER_LOG), 'utf-8'
|
||||||
for line in fileText.split '\n'
|
for line in fileText.split '\n'
|
||||||
|
line = MOD.scrubMinetweakerLine line
|
||||||
match = line.match /recipes.add(Shaped|Shapeless)\(<([^>]*)>( \* ([0-9]+))?, (.*)\);/
|
match = line.match /recipes.add(Shaped|Shapeless)\(<([^>]*)>( \* ([0-9]+))?, (.*)\);/
|
||||||
continue unless match?
|
continue unless match?
|
||||||
|
|
||||||
@@ -428,9 +437,7 @@ scanRecipes = ->
|
|||||||
|
|
||||||
outputId = parseMinecraftId match[2]
|
outputId = parseMinecraftId match[2]
|
||||||
outputItem = findItem minecraftId:outputId
|
outputItem = findItem minecraftId:outputId
|
||||||
if not outputItem?
|
continue unless outputItem?
|
||||||
console.error "Ignoring recipe because there's no matching item: #{line}"
|
|
||||||
continue
|
|
||||||
|
|
||||||
quantity = parseInt match[4]
|
quantity = parseInt match[4]
|
||||||
quantity = if _.isNaN(quantity) then 1 else quantity
|
quantity = if _.isNaN(quantity) then 1 else quantity
|
||||||
@@ -456,6 +463,11 @@ scanRecipes = ->
|
|||||||
|
|
||||||
sortItems = ->
|
sortItems = ->
|
||||||
MOD.items.sort (a, b)->
|
MOD.items.sort (a, b)->
|
||||||
|
if a.groupName isnt b.groupName
|
||||||
|
if not a.groupName? then return -1
|
||||||
|
if not b.groupName? then return +1
|
||||||
|
return if a.groupName < b.groupName then -1 else +1
|
||||||
|
|
||||||
if a.displayName isnt b.displayName
|
if a.displayName isnt b.displayName
|
||||||
return if a.displayName < b.displayName then -1 else +1
|
return if a.displayName < b.displayName then -1 else +1
|
||||||
|
|
||||||
@@ -470,10 +482,20 @@ writeModVersionFile = ->
|
|||||||
lineText = ' ' + lineText
|
lineText = ' ' + lineText
|
||||||
lines.push lineText
|
lines.push lineText
|
||||||
|
|
||||||
|
currentGroupName = null
|
||||||
for item in MOD.items
|
for item in MOD.items
|
||||||
|
if item.groupName isnt currentGroupName
|
||||||
|
indent = 0
|
||||||
|
write "group: #{item.groupName}"
|
||||||
|
write ''
|
||||||
|
currentGroupName = item.groupName
|
||||||
|
indent++
|
||||||
|
|
||||||
write "item: #{item.displayName}"
|
write "item: #{item.displayName}"
|
||||||
indent++
|
indent++
|
||||||
|
|
||||||
|
# write "minecraftId: #{item.minecraftId}"
|
||||||
|
|
||||||
if (not item.isGatherable? and not item.recipes?) or item.isGatherable
|
if (not item.isGatherable? and not item.recipes?) or item.isGatherable
|
||||||
write 'gatherable: yes'
|
write 'gatherable: yes'
|
||||||
|
|
||||||
@@ -517,10 +539,11 @@ scanRecipes()
|
|||||||
scanFurnaceRecipes()
|
scanFurnaceRecipes()
|
||||||
|
|
||||||
discardNonModItems()
|
discardNonModItems()
|
||||||
|
assignGroups()
|
||||||
sortItems()
|
sortItems()
|
||||||
removeDuplicates()
|
removeDuplicates()
|
||||||
makeCorrections()
|
makeCorrections()
|
||||||
|
|
||||||
writeModVersionFile()
|
writeModVersionFile()
|
||||||
writeJsonDump()
|
# writeJsonDump()
|
||||||
copyImages()
|
copyImages()
|
||||||
|
|||||||
Reference in New Issue
Block a user