default values for options are now specified alongside their definitions
This commit is contained in:
@@ -28,6 +28,11 @@ class RenderPrimitive(object):
|
|||||||
if not key in self.options:
|
if not key in self.options:
|
||||||
raise ValueError("primitive `{0}' has no option `{1}'".format(self.name, key))
|
raise ValueError("primitive `{0}' has no option `{1}'".format(self.name, key))
|
||||||
self.option_values[key] = val
|
self.option_values[key] = val
|
||||||
|
|
||||||
|
# set up defaults
|
||||||
|
for name, (description, default) in self.options.iteritems():
|
||||||
|
if not name in self.option_values:
|
||||||
|
self.option_values[name] = default
|
||||||
|
|
||||||
class Base(RenderPrimitive):
|
class Base(RenderPrimitive):
|
||||||
name = "base"
|
name = "base"
|
||||||
@@ -44,14 +49,14 @@ class HeightFading(RenderPrimitive):
|
|||||||
class Depth(RenderPrimitive):
|
class Depth(RenderPrimitive):
|
||||||
name = "depth"
|
name = "depth"
|
||||||
options = {
|
options = {
|
||||||
"min": "lowest level of blocks to render (default: 0)",
|
"min": ("lowest level of blocks to render", 0),
|
||||||
"max": "highest level of blocks to render (default: 127)",
|
"max": ("highest level of blocks to render", 127),
|
||||||
}
|
}
|
||||||
|
|
||||||
class EdgeLines(RenderPrimitive):
|
class EdgeLines(RenderPrimitive):
|
||||||
name = "edge-lines"
|
name = "edge-lines"
|
||||||
options = {
|
options = {
|
||||||
"opacity": "darkness of the edge lines, from 0.0 to 1.0 (default: 0.15)",
|
"opacity": ("darkness of the edge lines, from 0.0 to 1.0", 0.15),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Render 3 blending masks for lighting
|
# Render 3 blending masks for lighting
|
||||||
|
|||||||
@@ -26,11 +26,8 @@ static int
|
|||||||
depth_start(void *data, RenderState *state, PyObject *support) {
|
depth_start(void *data, RenderState *state, PyObject *support) {
|
||||||
PrimitiveDepth *self = (PrimitiveDepth *)data;
|
PrimitiveDepth *self = (PrimitiveDepth *)data;
|
||||||
|
|
||||||
self->min = 0;
|
|
||||||
if (!render_mode_parse_option(support, "min", "I", &(self->min)))
|
if (!render_mode_parse_option(support, "min", "I", &(self->min)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
self->max = 127;
|
|
||||||
if (!render_mode_parse_option(support, "max", "I", &(self->max)))
|
if (!render_mode_parse_option(support, "max", "I", &(self->max)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ typedef struct {
|
|||||||
static int
|
static int
|
||||||
edge_lines_start(void *data, RenderState *state, PyObject *support) {
|
edge_lines_start(void *data, RenderState *state, PyObject *support) {
|
||||||
PrimitiveEdgeLines *self = (PrimitiveEdgeLines *)data;
|
PrimitiveEdgeLines *self = (PrimitiveEdgeLines *)data;
|
||||||
|
|
||||||
self->opacity = 0.15;
|
|
||||||
if (!render_mode_parse_option(support, "opacity", "f", &(self->opacity)))
|
if (!render_mode_parse_option(support, "opacity", "f", &(self->opacity)))
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -176,16 +176,16 @@ int render_mode_parse_option(PyObject *support, const char *name, const char *fo
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (support == NULL || name == NULL)
|
if (support == NULL || name == NULL)
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
dict = PyObject_GetAttrString(support, "option_values");
|
dict = PyObject_GetAttrString(support, "option_values");
|
||||||
if (!dict)
|
if (!dict)
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
item = PyDict_GetItemString(dict, name);
|
item = PyDict_GetItemString(dict, name);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
Py_DECREF(dict);
|
Py_DECREF(dict);
|
||||||
return 1;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* make sure the item we're parsing is a tuple
|
/* make sure the item we're parsing is a tuple
|
||||||
|
|||||||
Reference in New Issue
Block a user