Skip to content

RFC: Custom block plugin system #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions customblocks/wool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#from overviewer_core import textures

@material(blockid=35, data=range(16), solid=True)
def wool(self, blockid, data):
if data == 0: # white
texture = self.terrain_images[64]
elif data == 1: # orange
texture = self.terrain_images[210]
elif data == 2: # magenta
texture = self.terrain_images[194]
elif data == 3: # light blue
texture = self.terrain_images[178]
elif data == 4: # yellow
texture = self.terrain_images[162]
elif data == 5: # light green
texture = self.terrain_images[146]
elif data == 6: # pink
texture = self.terrain_images[130]
elif data == 7: # grey
texture = self.terrain_images[114]
elif data == 8: # light grey
texture = self.terrain_images[225]
elif data == 9: # cyan
texture = self.terrain_images[209]
elif data == 10: # purple
texture = self.terrain_images[193]
elif data == 11: # blue
texture = self.terrain_images[177]
elif data == 12: # brown
texture = self.terrain_images[161]
elif data == 13: # dark green
texture = self.terrain_images[145]
texture = Image.new("RGBA", (16, 16), 0x99FFFFFF)
elif data == 14: # red
texture = self.terrain_images[129]
texture = Image.open("/tmp/wool.png").convert("RGBA").resize((16,16))
elif data == 15: # black
texture = self.terrain_images[113]

return self.build_block(texture, texture)

6 changes: 4 additions & 2 deletions overviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,10 @@ def main():
worldcache[render['world']] = w

# find or create the textures object
texopts = util.dict_subset(render, ["texturepath", "bgcolor", "northdirection"])
texopts_key = tuple(texopts.items())
texopts = util.dict_subset(render, ["texturepath", "bgcolor", "northdirection", "customblocks"])
texopts_red = util.dict_subset(texopts, ["texturepath", "bgcolor", "northdirection"])
texopts_red["customblocks"] = " ".join(texopts.get("customblocks", None))
texopts_key = tuple(texopts_red.items())
if texopts_key not in texcache:
tex = textures.Textures(**texopts)
tex.generate()
Expand Down
2 changes: 2 additions & 0 deletions overviewer_core/settingsDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
"poititle": Setting(required=False, validator=validateStr, default="Signs"),
"customwebassets": Setting(required=False, validator=validateWebAssetsPath, default=None),
"maxzoom": Setting(required=False, validator=validateInt, default=None),
"customblocks": Setting(required=False, validator=validateCustomblocks, default=None),

# Remove this eventually (once people update their configs)
"worldname": Setting(required=False, default=None,
validator=error("The option 'worldname' is now called 'world'. Please update your config files")),
Expand Down
12 changes: 12 additions & 0 deletions overviewer_core/settingsValidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ def validatePath(p):
if not os.path.exists(abs_path):
raise ValidationException("'%s' does not exist. Path initially given as '%s'" % (abs_path,p))

def validateCustomblocks(p):
cb = []
for i in p:
ocb_path = os.path.join(util.get_program_path(), "customblocks", "%s.py" % i)
if os.path.isfile(ocb_path):
cb.append(ocb_path)
elif os.path.isfile(expand_path(i)):
cb.append(expand_path(i))
else:
raise ValidationException("Unable to find block definition file '%s'" % i)
return cb

def make_dictValidator(keyvalidator, valuevalidator):
"""Compose and return a dict validator -- a validator that validates each
key and value in a dictionary.
Expand Down
48 changes: 8 additions & 40 deletions overviewer_core/textures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ class Textures(object):
rendering. It accepts a background color, north direction, and
local textures path.
"""
def __init__(self, texturepath=None, bgcolor=(26, 26, 26, 0), northdirection=0):
def __init__(self, texturepath=None, bgcolor=(26, 26, 26, 0), northdirection=0, customblocks=None):
self.bgcolor = bgcolor
self.rotation = northdirection
self.find_file_local_path = texturepath

self.customblocks = customblocks

# not yet configurable
self.texture_size = 24
self.texture_dimensions = (self.texture_size, self.texture_size)
Expand Down Expand Up @@ -100,7 +101,11 @@ def generate(self):
block = tex[0]
scaled_block = block.resize(self.texture_dimensions, Image.ANTIALIAS)
blockmap[i] = self.generate_texture_tuple(scaled_block)


if not self.customblocks is None:
for i in self.customblocks:
execfile(i)

self.generated = True

##
Expand Down Expand Up @@ -1304,43 +1309,6 @@ def tall_grass(self, blockid, data):
# dead bush
billboard(blockid=32, index=55)

@material(blockid=35, data=range(16), solid=True)
def wool(self, blockid, data):
if data == 0: # white
texture = self.terrain_images[64]
elif data == 1: # orange
texture = self.terrain_images[210]
elif data == 2: # magenta
texture = self.terrain_images[194]
elif data == 3: # light blue
texture = self.terrain_images[178]
elif data == 4: # yellow
texture = self.terrain_images[162]
elif data == 5: # light green
texture = self.terrain_images[146]
elif data == 6: # pink
texture = self.terrain_images[130]
elif data == 7: # grey
texture = self.terrain_images[114]
elif data == 8: # light grey
texture = self.terrain_images[225]
elif data == 9: # cyan
texture = self.terrain_images[209]
elif data == 10: # purple
texture = self.terrain_images[193]
elif data == 11: # blue
texture = self.terrain_images[177]
elif data == 12: # brown
texture = self.terrain_images[161]
elif data == 13: # dark green
texture = self.terrain_images[145]
elif data == 14: # red
texture = self.terrain_images[129]
elif data == 15: # black
texture = self.terrain_images[113]

return self.build_block(texture, texture)

# dandelion
sprite(blockid=37, index=13)
# rose
Expand Down