0

[genPOI] Work around JSON signs

lol Mojang
This commit is contained in:
Nicolas F
2015-03-07 18:16:32 +01:00
parent e6f44aed26
commit b5ecf8a7f4

View File

@@ -24,6 +24,7 @@ import urllib2
import multiprocessing import multiprocessing
import itertools import itertools
import gzip import gzip
import json
from collections import defaultdict from collections import defaultdict
from multiprocessing import Pool from multiprocessing import Pool
@@ -44,6 +45,35 @@ def replaceBads(s):
x = x.replace(bad,"_") x = x.replace(bad,"_")
return x return x
# If you want to keep your stomach contents do not, under any circumstance,
# read the body of the following function. You have been warned.
def jsonText(s):
if (s.startswith('"') and s.endswith('"')) or \
(s.startswith('{') and s.endswith('}')):
try:
js = json.loads(s)
except ValueError:
return s
def parseLevel(foo):
bar = ""
if isinstance(foo, list):
for extra in foo:
bar += parseLevel(extra)
return bar
if isinstance(foo, dict):
if "text" in foo:
bar += foo["text"]
if "extra" in foo:
bar += parseLevel(foo["extra"])
return bar
elif isinstance(foo, basestring):
return foo
return parseLevel(js)
else:
return s
# yes there's a double parenthesis here # yes there's a double parenthesis here
# see below for when this is called, and why we do this # see below for when this is called, and why we do this
@@ -59,6 +89,8 @@ def parseBucketChunks((bucket, rset, filters)):
try: try:
data = rset.get_chunk(b[0],b[1]) data = rset.get_chunk(b[0],b[1])
for poi in itertools.chain(data['TileEntities'], data['Entities']): for poi in itertools.chain(data['TileEntities'], data['Entities']):
if poi['id'] == 'Sign':
poi = signWrangler(poi)
for name, filter_function in filters: for name, filter_function in filters:
result = filter_function(poi) result = filter_function(poi)
if result: if result:
@@ -76,6 +108,14 @@ def parseBucketChunks((bucket, rset, filters)):
return markers return markers
def signWrangler(poi):
"""
Just does the JSON things for signs
"""
for field in ["Text1", "Text2", "Text3", "Text4"]:
poi[field] = jsonText(poi[field])
return poi
def handleEntities(rset, config, filters, markers): def handleEntities(rset, config, filters, markers):
""" """
@@ -97,6 +137,8 @@ def handleEntities(rset, config, filters, markers):
try: try:
data = rset.get_chunk(x, z) data = rset.get_chunk(x, z)
for poi in itertools.chain(data['TileEntities'], data['Entities']): for poi in itertools.chain(data['TileEntities'], data['Entities']):
if poi['id'] == 'Sign': # kill me
poi = signWrangler(poi)
for name, __, filter_function, __, __, __ in filters: for name, __, filter_function, __, __, __ in filters:
result = filter_function(poi) result = filter_function(poi)
if result: if result: