mirror of
https://github.com/Nighthawk42/roll20-character-sheets.git
synced 2026-08-31 12:12:30 +00:00
colors for inline rolls and ability button in custom template
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2268,15 +2268,35 @@ This file is automatically generated from a template. Any change will be overwri
|
||||
custom
|
||||
</code>
|
||||
</strong>
|
||||
: This is the improved default template created by Jakob. See
|
||||
<code>
|
||||
https://wiki.roll20.net/Building_Character_Sheets/Roll_Templates#Jakob.27s_Better_Default_Rolltemplate
|
||||
</code>
|
||||
for details. All CSS v3 colors are supported by the
|
||||
<code>
|
||||
color
|
||||
</code>
|
||||
key (names must be all lowercase)
|
||||
:
|
||||
<ul>
|
||||
<li>
|
||||
This is the improved default template created by Jakob. See
|
||||
<code>
|
||||
https://wiki.roll20.net/Building_Character_Sheets/Roll_Templates#Jakob.27s_Better_Default_Rolltemplate
|
||||
</code>
|
||||
for details. All CSS v3 colors are supported by the
|
||||
<code>
|
||||
color
|
||||
</code>
|
||||
key (names must be all lowercase)
|
||||
</li>
|
||||
<li>
|
||||
In addition, the rolltemplate supports the
|
||||
<code>
|
||||
roll-color
|
||||
</code>
|
||||
and
|
||||
<code>
|
||||
button-color
|
||||
</code>
|
||||
to change the background color of inline rolls and ability buttons, respectively, within the template. Both values support all CSS v3 colors, as
|
||||
<code>
|
||||
color
|
||||
</code>
|
||||
does
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<strong>
|
||||
@@ -2609,6 +2629,28 @@ This file is automatically generated from a template. Any change will be overwri
|
||||
Changelog
|
||||
</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<strong>
|
||||
March 2021, v1.6.3
|
||||
</strong>
|
||||
<ul>
|
||||
<li>
|
||||
Added
|
||||
<code>
|
||||
roll-color
|
||||
</code>
|
||||
and
|
||||
<code>
|
||||
button-color
|
||||
</code>
|
||||
properties to the
|
||||
<code>
|
||||
custom
|
||||
</code>
|
||||
rolltemplate, with all CSSv3 colors
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<strong>
|
||||
February 2021, v1.6.2
|
||||
@@ -3154,16 +3196,16 @@ This file is automatically generated from a template. Any change will be overwri
|
||||
</rolltemplate>
|
||||
|
||||
<rolltemplate class="sheet-rolltemplate-custom">
|
||||
<div class="sheet-crt-container sheet-crt-color-{{color}}">
|
||||
<div class="sheet-crt-container sheet-crt-color-{{color}} sheet-crt-rlcolor-{{roll-color}} sheet-crt-btcolor-{{button-color}}">
|
||||
<div class="sheet-crt-header">
|
||||
{{#title}}<div class="sheet-crt-title"><b>{{title}}</b></div>{{/title}}
|
||||
{{#subtitle}}<div class="sheet-crt-subtitle">{{subtitle}}</div>{{/subtitle}}
|
||||
</div>
|
||||
<div class="sheet-crt-content">
|
||||
{{#allprops() title subtitle desc color}}
|
||||
{{#allprops() title subtitle desc color roll-color button-color}}
|
||||
<div class="sheet-crt-key">{{key}}</div>
|
||||
<div class="sheet-crt-value">{{value}}</div>
|
||||
{{/allprops() title subtitle desc color}}
|
||||
{{/allprops() title subtitle desc color roll-color button-color}}
|
||||
{{#desc}}<div class="sheet-crt-desc">{{desc}}</div>{{/desc}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -382,11 +382,21 @@ with open(Path(__file__).parent / "css_colors.csv", newline="") as f:
|
||||
reader = csv.DictReader(f)
|
||||
css_rules = []
|
||||
for color_def in reader:
|
||||
lines = [
|
||||
".sheet-rolltemplate-custom .sheet-crt-container.sheet-crt-color-%s {"
|
||||
% color_def["color"],
|
||||
" --header-bg-color: %s;" % color_def["hex"],
|
||||
# Base CSS rules
|
||||
lines_header = [
|
||||
f".sheet-rolltemplate-custom .sheet-crt-container.sheet-crt-color-{color_def['color']} {{",
|
||||
f" --header-bg-color: {color_def['hex']};",
|
||||
]
|
||||
lines_rolls = [
|
||||
f".sheet-rolltemplate-custom .sheet-crt-container.sheet-crt-rlcolor-{color_def['color']} .inlinerollresult {{",
|
||||
f" --roll-bg-color: {color_def['hex']};",
|
||||
]
|
||||
lines_buttons = [
|
||||
f".sheet-rolltemplate-custom .sheet-crt-container.sheet-crt-rlcolor-{color_def['color']} a {{",
|
||||
f" --button-bg-color: {color_def['hex']};",
|
||||
]
|
||||
|
||||
# Adapt text color to background color
|
||||
hex = color_def["hex"].lstrip("#")
|
||||
r, g, b = tuple(int(hex[2 * i : 2 * i + 2], 16) / 255 for i in range(3))
|
||||
# Assuming sRGB -> Luma
|
||||
@@ -394,7 +404,13 @@ with open(Path(__file__).parent / "css_colors.csv", newline="") as f:
|
||||
luma = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
if luma > 0.5: # arbitrary threshold
|
||||
# switch to black text if luma is high enough
|
||||
lines.append(" --header-text-color: #000;")
|
||||
lines.append("}")
|
||||
css_rules.append("\n".join(lines))
|
||||
lines_header.append(" --header-text-color: #000;")
|
||||
lines_buttons.append(" --button-text-color: #000;")
|
||||
if luma < 0.5:
|
||||
lines_rolls.append(" --roll-text-color: #FFF;")
|
||||
|
||||
# Build the rules
|
||||
for lines in (lines_header, lines_rolls, lines_buttons):
|
||||
lines.append("}")
|
||||
css_rules.append("\n".join(lines))
|
||||
GLOBALS["custom_rt_color_css"] = "\n".join(css_rules)
|
||||
|
||||
@@ -124,7 +124,9 @@ All rolltemplate support the following values:
|
||||
|
||||
Those are omitted in the following list of rolltemplate names and supported values:
|
||||
|
||||
+ **`custom`**: This is the improved default template created by Jakob. See `https://wiki.roll20.net/Building_Character_Sheets/Roll_Templates#Jakob.27s_Better_Default_Rolltemplate` for details. All CSS v3 colors are supported by the `color` key (names must be all lowercase)
|
||||
+ **`custom`**:
|
||||
+ This is the improved default template created by Jakob. See `https://wiki.roll20.net/Building_Character_Sheets/Roll_Templates#Jakob.27s_Better_Default_Rolltemplate` for details. All CSS v3 colors are supported by the `color` key (names must be all lowercase)
|
||||
+ In addition, the rolltemplate supports the `roll-color` and `button-color` to change the background color of inline rolls and ability buttons, respectively, within the template. Both values support all CSS v3 colors, as `color` does
|
||||
+ **`spell`**:
|
||||
+ `character`
|
||||
+ `duration`
|
||||
@@ -178,6 +180,8 @@ Those are omitted in the following list of rolltemplate names and supported valu
|
||||
+ `textlabel`
|
||||
|
||||
### Changelog
|
||||
+ **March 2021, v1.6.3**
|
||||
- Added `roll-color` and `button-color` properties to the `custom` rolltemplate, with all CSSv3 colors
|
||||
+ **February 2021, v1.6.2**
|
||||
- Fixed centering not working
|
||||
- Fixed translation of spellcasting words options
|
||||
|
||||
+41
-12
@@ -29,6 +29,7 @@ def process_template(
|
||||
end_delimiter: str,
|
||||
globalns: Dict[str, Any],
|
||||
localns: Dict[str, Any],
|
||||
verbose: int = 0,
|
||||
) -> Generator[str, None, None]:
|
||||
"""
|
||||
Read lines from a file and evaluates occurences of occurence_re
|
||||
@@ -56,20 +57,34 @@ def process_template(
|
||||
value = eval(expr, globalns, localns)
|
||||
except Exception as err:
|
||||
print(
|
||||
f"Expression at line {lineno}{'-' + str(lineno + offset) if offset else ''} raised an exception"
|
||||
)
|
||||
print("Offending expression:", start_delimiter + expr + end_delimiter)
|
||||
print(
|
||||
"Exception raised:\n\n",
|
||||
"".join(tb.format_exception(type(err), err, err.__traceback__)),
|
||||
f"Expression at line {lineno}{'-' + str(lineno + offset) if offset else ''} raised: {err.__class__.__name__}: {err}",
|
||||
end="",
|
||||
)
|
||||
if verbose < 1:
|
||||
print(" (use -v to display offending expression)")
|
||||
else:
|
||||
print(
|
||||
"\nOffending expression:",
|
||||
start_delimiter + expr + end_delimiter,
|
||||
)
|
||||
if verbose < 2:
|
||||
print("(use -vv to display detailed traceback)")
|
||||
else:
|
||||
print(
|
||||
"\nException raised:\n\n",
|
||||
"".join(tb.format_exception(type(err), err, err.__traceback__)),
|
||||
)
|
||||
raise HandledException from err
|
||||
|
||||
if not isinstance(value, str):
|
||||
print(
|
||||
f"Expression at line {lineno}{'-' + str(lineno + offset) if offset else ''} does not evaluate to a string"
|
||||
)
|
||||
print(f"Offending expression:", start_delimiter + expr + end_delimiter)
|
||||
if verbose > 0:
|
||||
print(
|
||||
f"Offending expression: ",
|
||||
start_delimiter + expr + end_delimiter,
|
||||
)
|
||||
raise HandledException from ValueError(
|
||||
f"{start_delimiter + expr + end_delimiter} does not evaluate to a string"
|
||||
)
|
||||
@@ -90,6 +105,7 @@ def main(
|
||||
delimiters: Union[Tuple[str], Tuple[str, str]],
|
||||
global_namespaces: List[str] = (),
|
||||
local_namespaces: List[str] = (),
|
||||
verbose: int = 0,
|
||||
) -> NoReturn:
|
||||
"""
|
||||
Main script entry point
|
||||
@@ -117,11 +133,16 @@ def main(
|
||||
module = importlib.import_module(module_name)
|
||||
ns.update(getattr(module, attr_name))
|
||||
except Exception as err:
|
||||
print(
|
||||
f"error: Could not load {name} due to:",
|
||||
"".join(tb.format_exception(type(err), err, err.__traceback__)),
|
||||
sep="\n\n",
|
||||
)
|
||||
print(f"error: Could not load {name}: {err}", end="")
|
||||
if verbose < 1:
|
||||
print(" (use -v to display detailed traceback)")
|
||||
else:
|
||||
print(
|
||||
"\n\n"
|
||||
+ "".join(
|
||||
tb.format_exception(type(err), err, err.__traceback__)
|
||||
)
|
||||
)
|
||||
exit(-1)
|
||||
|
||||
# process and write lines
|
||||
@@ -135,6 +156,7 @@ def main(
|
||||
end_delimiter,
|
||||
globalns,
|
||||
localns,
|
||||
verbose=verbose,
|
||||
)
|
||||
)
|
||||
except HandledException:
|
||||
@@ -172,6 +194,13 @@ for prettier formatting of the output.""",
|
||||
type=Path,
|
||||
help="File to write the content of the input with evaluated expressions",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
default=0,
|
||||
action="count",
|
||||
help="Increase verbosity",
|
||||
)
|
||||
|
||||
delimiter_group = parser.add_argument_group(title="delimiter arguments")
|
||||
delimiter_group.add_argument(
|
||||
|
||||
@@ -1856,6 +1856,15 @@ $$fatigue_level_css$$
|
||||
.sheet-rolltemplate-custom .sheet-crt-subtitle {
|
||||
font-size:.9em;
|
||||
}
|
||||
.sheet-rolltemplate-custom .sheet-crt-container .inlinerollresult {
|
||||
background-color: var(--roll-bg-color);
|
||||
border-color: var(--roll-bg-color);
|
||||
color: var(--roll-text-color);
|
||||
}
|
||||
.sheet-rolltemplate-custom .sheet-crt-container a {
|
||||
background-color: var(--button-bg-color);
|
||||
color: var(--button-text-color);
|
||||
}
|
||||
|
||||
/* example colors */
|
||||
.sheet-rolltemplate-custom .sheet-crt-container {
|
||||
@@ -1863,6 +1872,14 @@ $$fatigue_level_css$$
|
||||
--header-bg-color: rgba(112,32,130,1);
|
||||
--header-text-color: #FFF;
|
||||
}
|
||||
.sheet-rolltemplate-custom .sheet-crt-container .inlinerollresult {
|
||||
--roll-bg-color: #FEF68E;
|
||||
--roll-text-color: #000;
|
||||
}
|
||||
.sheet-rolltemplate-custom .sheet-crt-container a {
|
||||
--button-bg-color: #ce0f69;
|
||||
--button-text-color: #FFF;
|
||||
}
|
||||
|
||||
/*
|
||||
.sheet-rolltemplate-custom .sheet-crt-container.sheet-crt-color-red {
|
||||
|
||||
@@ -1709,16 +1709,16 @@ $$alert(
|
||||
</rolltemplate>
|
||||
|
||||
<rolltemplate class="sheet-rolltemplate-custom">
|
||||
<div class="sheet-crt-container sheet-crt-color-{{color}}">
|
||||
<div class="sheet-crt-container sheet-crt-color-{{color}} sheet-crt-rlcolor-{{roll-color}} sheet-crt-btcolor-{{button-color}}">
|
||||
<div class="sheet-crt-header">
|
||||
{{#title}}<div class="sheet-crt-title"><b>{{title}}</b></div>{{/title}}
|
||||
{{#subtitle}}<div class="sheet-crt-subtitle">{{subtitle}}</div>{{/subtitle}}
|
||||
</div>
|
||||
<div class="sheet-crt-content">
|
||||
{{#allprops() title subtitle desc color}}
|
||||
{{#allprops() title subtitle desc color roll-color button-color}}
|
||||
<div class="sheet-crt-key">{{key}}</div>
|
||||
<div class="sheet-crt-value">{{value}}</div>
|
||||
{{/allprops() title subtitle desc color}}
|
||||
{{/allprops() title subtitle desc color roll-color button-color}}
|
||||
{{#desc}}<div class="sheet-crt-desc">{{desc}}</div>{{/desc}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user