diff --git a/calefaction/modules/campaigns/__init__.py b/calefaction/modules/campaigns/__init__.py new file mode 100644 index 0000000..c17a3a4 --- /dev/null +++ b/calefaction/modules/campaigns/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from .getters import get_current, get_count, get_summary, get_unit +from .routes import home, navitem +from .._provided import config diff --git a/calefaction/modules/campaigns/getters.py b/calefaction/modules/campaigns/getters.py new file mode 100644 index 0000000..87eb7b1 --- /dev/null +++ b/calefaction/modules/campaigns/getters.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- + +from flask import g + +from .._provided import config + +__all__ = ["get_current", "get_count", "get_summary", "get_unit"] + +def get_current(): + """Return the name of the currently selected campaign, or None.""" + if not config["enabled"]: + return None + setting = g.auth.get_character_modprop("campaigns", "current") + if not setting or setting not in config["enabled"]: + return config["enabled"][0] + return setting + +def get_count(cname, opname): + """Return the primary operation count for the given campaign/operation.""" + key = cname + "." + opname + operation = config["campaigns"][cname]["operations"][opname] + optype = operation["type"] + qualifiers = operation["qualifiers"] + + ... + import random + return [random.randint(0, 500), random.randint(10000, 500000), random.randint(10000000, 50000000000)][random.randint(0, 2)] + +def get_summary(name, opname, limit=5): + """Return a sample fraction of results for the given campaign/operation.""" + ... + return [] + +def get_unit(operation, num): + """Return the correct form of the unit tracked by the given operation.""" + types = { + "killboard": "ship|ships", + "collection": "item|items" + } + if "unit" in operation: + unit = operation["unit"] + else: + unit = types[operation["type"]] + + if "|" in unit: + return unit.split("|")[0 if num == 1 else 1] + return unit diff --git a/calefaction/modules/campaigns.py b/calefaction/modules/campaigns/routes.py similarity index 86% rename from calefaction/modules/campaigns.py rename to calefaction/modules/campaigns/routes.py index c1c1788..5b98bbe 100644 --- a/calefaction/modules/campaigns.py +++ b/calefaction/modules/campaigns/routes.py @@ -3,16 +3,11 @@ from flask import abort, g, redirect, request, url_for from flask_mako import render_template -from ._provided import blueprint, config +from .getters import get_current +from .._provided import blueprint, config -def get_current(): - """Return the name of the currently selected campaign, or None.""" - if not config["enabled"]: - return None - setting = g.auth.get_character_modprop("campaigns", "current") - if not setting or setting not in config["enabled"]: - return config["enabled"][0] - return setting +__all__ = ["home", "navitem", "current_campaign", "campaign", "operation", + "set_campaign"] def home(): """Render and return the main campaign page.""" diff --git a/config/modules/campaigns.yml.sample b/config/modules/campaigns.yml.sample index 18856d0..aca74f7 100644 --- a/config/modules/campaigns.yml.sample +++ b/config/modules/campaigns.yml.sample @@ -36,6 +36,7 @@ campaigns: titan: title: Let's Build a Titan type: collection + unit: unit|units qualifiers: |- return item_type == "Tritanium" bar: diff --git a/static/main.css b/static/main.css index 86e8ca2..6ba2ba2 100644 --- a/static/main.css +++ b/static/main.css @@ -376,24 +376,24 @@ h2 .disabled::after { justify-content: space-between; } -.operation .stats .primary { +.operation .overview .num { line-height: 60px; height: 60px; } -.operation .stats .primary .big { +.operation .overview .num.big { font-size: 300%; } -.operation .stats .primary .medium { +.operation .overview .num.medium { font-size: 200%; } -.operation .stats .primary .small { +.operation .overview .num.small { font-size: 150%; } -.operation .stats .unit { +.operation .overview .unit { font-style: italic; } @@ -421,11 +421,11 @@ h2 .disabled::after { margin: 0.5em 0; } - .operation .stats > div { + .operation .overview > div { display: inline-block; } - .operation .stats .unit { + .operation .overview .unit { margin-left: 0.25em; } } diff --git a/templates/campaigns/campaign.mako b/templates/campaigns/campaign.mako index fba5722..ee0aa70 100644 --- a/templates/campaigns/campaign.mako +++ b/templates/campaigns/campaign.mako @@ -6,28 +6,33 @@ Campaign: ${campaign["title"] | h} +<% mod = g.config.modules.campaigns %>
% for section in campaign["layout"]: <% klass = "loose" if len(section) < 3 else "tight" %>
% for opname in section: - <% operation = campaign["operations"][opname] %> + <% + operation = campaign["operations"][opname] + num = mod.get_count(name, opname) + summary = mod.get_summary(name, opname, limit=5) + klass = "big" if num < 1000 else "medium" if num < 1000000 else "small" + %>
-

${operation["title"] | h}

-
- - <% - random = __import__("random") - n = [random.randint(0, 500), random.randint(10000, 500000), random.randint(10000000, 50000000000)][random.randint(0, 2)] - %> - <% - klass = "big" if n < 1000 else "medium" if n < 1000000 else "small" - %> -
- ${"{:,}".format(n)} -
-
${"ships" if klass == "big" else "points" if klass == "medium" else "ISK"}
+

+ ${operation["title"] | h} +

+
+
${"{:,}".format(num)}
+
${mod.get_unit(operation, num)}
+ % if summary: +
    + % for item in summary: +
  • ${item}
  • + % endfor +
+ % endif
% endfor