Commit f9a08c37 authored by sirjorj's avatar sirjorj

changes to handle new upgrade type system

parent 470c8ae9
......@@ -212,9 +212,9 @@ void pilot2(struct kreq *req) {
khtml_elem(&r, KELEM_TR);
khtml_attr(&r, KELEM_TD, KATTR_STYLE, CSS::Key().c_str(), KATTR__MAX); khtml_puts(&r, "Upgrades"); khtml_closeelem(&r, 1);
khtml_attr(&r, KELEM_TD, KATTR__MAX);
for(UpT u : pilot.GetNatUpgradeSlots()) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(u).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(u).c_str());
for(const UpgradeSlot& s : pilot.GetNatUpgradeBar()) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(s.GetTypes()[0]).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(s.GetTypes()[0]).c_str());
khtml_closeelem(&r, 1); // span
}
khtml_closeelem(&r, 2); // td tr
......
......@@ -192,8 +192,8 @@ void pilots2(struct kreq *req) {
}
{
int uc=0;
for(UpT u : p.GetNatUpgradeSlots()) {
pilots[pc]["upgrades"][uc] = UpgradeType::GetUpgradeType(u).GetName();
for(const UpgradeSlot& s : p.GetNatUpgradeBar()) {
pilots[pc]["upgrades"][uc] = UpgradeType::GetUpgradeType(s.GetTypes()[0]).GetName();
uc++;
}
}
......
......@@ -213,9 +213,9 @@ void ship2(struct kreq *req) {
}
{ //upgrades
khtml_attr(&r, KELEM_TD, KATTR_STYLE, CSS::UpgradeBar().c_str(), KATTR__MAX);
for(UpT u : p.GetNatUpgradeSlots()) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(u).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(u).c_str());
for(const UpgradeSlot& s : p.GetNatUpgradeBar()) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(s.GetTypes()[0]).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(s.GetTypes()[0]).c_str());
khtml_closeelem(&r, 1); // span
}
khtml_closeelem(&r, 1); // td
......
......@@ -156,27 +156,35 @@ void upgrade2(struct kreq *req) {
}
}
{ // upgrade slots modification
std::vector<UpT> as = upgrade.GetModifier().GetAddedSlots();
UpgradeBar as = upgrade.GetModifier().GetAddedSlots();
if(as.size()) {
khtml_elem(&r, KELEM_TR);
khtml_attr(&r, KELEM_TD, KATTR_STYLE, CSS::Key().c_str(), KATTR__MAX); khtml_puts(&r, "Upgrades (added)"); khtml_closeelem(&r, 1);
khtml_attr(&r, KELEM_TD, KATTR__MAX);
for(UpT t : as) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(t).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(t).c_str());
khtml_closeelem(&r, 1); // span
for(const UpgradeSlot& s : as) {
if(s.IsMulti()) { khtml_puts(&r, "["); }
for(UpT t : s.GetTypes()) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(t).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(t).c_str());
khtml_closeelem(&r, 1); // span
}
if(s.IsMulti()) { khtml_puts(&r, "]"); }
}
khtml_closeelem(&r, 2); // td, tr
}
std::vector<UpT> rs = upgrade.GetModifier().GetRemovedSlots();
UpgradeBar rs = upgrade.GetModifier().GetRemovedSlots();
if(rs.size()) {
khtml_elem(&r, KELEM_TR);
khtml_attr(&r, KELEM_TD, KATTR_STYLE, CSS::Key().c_str(), KATTR__MAX); khtml_puts(&r, "Upgrades (removed)"); khtml_closeelem(&r, 1);
khtml_attr(&r, KELEM_TD, KATTR__MAX);
for(UpT t : rs) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(t).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(t).c_str());
khtml_closeelem(&r, 1); // span
for(const UpgradeSlot& s : rs) {
if(s.IsMulti()) { khtml_puts(&r, "["); }
for(UpT t : s.GetTypes()) {
khtml_attr(&r, KELEM_SPAN, KATTR_STYLE, CSS::Upgrade().c_str(), KATTR_TITLE, UpgradeType::GetUpgradeType(t).GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(t).c_str());
khtml_closeelem(&r, 1); // span
}
if(s.IsMulti()) { khtml_puts(&r, "]"); }
}
khtml_closeelem(&r, 2); // td, tr
}
......
......@@ -171,162 +171,6 @@ void upgrades2(struct kreq *req) {
khtml_close(&r);
}
#if 0
else if(format == "test3") {
struct khtmlreq r;
// page
resp_open(req, KHTTP_200);
khtml_open(&r, req, KHTML_PRETTY);
khtml_elem(&r, KELEM_DOCTYPE);
khtml_attr(&r, KELEM_HTML, KATTR_LANG, "en", KATTR__MAX);
// head
PrintHead(r, std::string(req->pname) + req->fullpath);
// body
khtml_elem(&r, KELEM_BODY);
PrintBreadcrumbs(r, {{req->pname, StripLeadingSlash(req->pname)}}, req->pagename);
khtml_attr(&r, KELEM_DIV, KATTR_CLASS, "container", KATTR__MAX);
// list of upgrades
for(const Faction& f : Faction::GetAllFactions()) {
khtml_attr(&r, KELEM_DIV, KATTR_CLASS, "floater", KATTR__MAX);
khtml_attr(&r, KELEM_TABLE, KATTR_CLASS, "upgradesList", KATTR__MAX);
{ // faction
std::string css;
switch(f.GetType()) {
case Fac::Rebel: css = "fac reb"; break;
case Fac::Imperial: css = "fac imp"; break;
case Fac::Scum: css = "fac scm"; break;
case Fac::Resistance: css = "fac res"; break;
case Fac::FirstOrder: css = "fac fir"; break;
default: css = "";
}
khtml_elem(&r, KELEM_TR);
khtml_attr(&r, KELEM_TD, KATTR_CLASS, css.c_str(), KATTR_COLSPAN, "2", KATTR__MAX);
khtml_attr(&r, KELEM_SPAN, KATTR_TITLE, f.GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(f.GetType()).c_str());
khtml_closeelem(&r, 3); // span td tr
}
const std::vector<UpgradeType>& types = UpgradeType::GetUpgradeTypes(f.GetType());
for(const UpgradeType& ut : types) {
std::vector<Upgrade> upgrades;
for(const Upgrade& u : Upgrade::GetAllUpgrades()) {
if(((u.GetRestriction().GetAllowedFactions() & f.GetType()) == f.GetType()) &&
(u.GetUpgradeType().GetType() == ut.GetType())) {
upgrades.push_back(u);
}
}
if(upgrades.size()) {
bool drawType=true;
for(const Upgrade& u : upgrades) {
khtml_elem(&r, KELEM_TR);
if(drawType) {
khtml_attr(&r, KELEM_TD, KATTR_CLASS, "upt", KATTR_ROWSPAN, std::to_string(upgrades.size()).c_str(), KATTR__MAX);
khtml_attr(&r, KELEM_SPAN, KATTR_TITLE, u.GetUpgradeType().GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(u.GetUpgradeType().GetType()).c_str());
khtml_closeelem(&r, 2); // span td
drawType=false;
}
khtml_elem(&r, KELEM_TD);
PrintUpgradeName(req, r, u);
khtml_closeelem(&r, 2); // td tr
}
}
}
khtml_closeelem(&r, 2); // table div
}
/*
struct khtmlreq r;
// page
resp_open(req, KHTTP_200);
khtml_open(&r, req, KHTML_PRETTY);
khtml_elem(&r, KELEM_DOCTYPE);
khtml_elem(&r, KELEM_HTML);
// head
khtml_elem(&r, KELEM_HEAD);
khtml_attr(&r, KELEM_META, KATTR_CHARSET, "utf-8", KATTR__MAX);
khtml_elem(&r, KELEM_TITLE); khtml_puts(&r, (std::string(req->pname) + "/upgrades2").c_str()); khtml_closeelem(&r, 1);
khtml_attr(&r, KELEM_LINK, KATTR_REL, "stylesheet", KATTR_TYPE, "text/css", KATTR_HREF, "/xwingcgi.css", KATTR__MAX);
khtml_closeelem(&r, 1); // head
// body
khtml_elem(&r, KELEM_BODY);
PrintBreadcrumbs(r, {{req->pname, StripLeadingSlash(req->pname)}}, req->pagename);
khtml_attr(&r, KELEM_DIV, KATTR_CLASS, "container", KATTR__MAX);
// list of upgrades
for(const UpgradeType& ut : UpgradeType::GetAllUpgradeTypes()) {
khtml_attr(&r, KELEM_DIV, KATTR_CLASS, "floater", KATTR__MAX);
khtml_attr(&r, KELEM_TABLE, KATTR_CLASS, "upgradesList", KATTR__MAX);
{ // upgrade type
khtml_elem(&r, KELEM_TR);
khtml_attr(&r, KELEM_TD, KATTR_CLASS, "upt", KATTR__MAX);
khtml_attr(&r, KELEM_SPAN, KATTR_TITLE, ut.GetName().c_str(), KATTR__MAX);
khtml_puts(&r, IconGlyph::GetGlyph(ut.GetType()).c_str());
khtml_closeelem(&r, 3); // span td tr
}
for(const Upgrade& u : Upgrade::GetAllUpgrades()) {
if(u.GetUpgradeType().GetType() == ut.GetType()) {
// upgrade name
xws::upgrade::xwsData xd;
try{
xd = xws::upgrade::GetUpgrade(u.GetType());
}
catch(UpgradeNotFound &unf) {
khtml_puts(&r, std::string("CANNOT FIND UPGRADE" + std::to_string((int)u.GetType())).c_str());
continue;
}
catch(std::runtime_error &re) {
khtml_puts(&r, (std::string("error: ") + re.what()).c_str());
}
catch(...) {
khtml_puts(&r, "WTF?");
continue;
}
std::string uUrl = std::string(req->pname)+"/upgrade2?type=" + xd.type + "&name=" + xd.name;
khtml_elem(&r, KELEM_TR);
khtml_elem(&r, KELEM_TD);
//if(u.IsUnreleased()) {
// khtml_attr(&r, KELEM_SPAN, KATTR_CLASS, "unreleased", KATTR__MAX);
// khtml_puts(&r, "[UNRELEASED] ");
// khtml_closeelem(&r, 1); // span
//}
khtml_attr(&r, KELEM_A, KATTR_HREF, uUrl.c_str(), KATTR__MAX);
if(u.GetLimited()) {
khtml_attr(&r, KELEM_SPAN, KATTR_CLASS, "iconGlyph", KATTR__MAX);
for(int i=0; i<u.GetLimited(); i++) {
khtml_puts(&r, IconGlyph::GetGlyph(Ico::unique).c_str());
}
khtml_closeelem(&r, 1);
}
khtml_puts(&r, u.GetName().c_str());
khtml_closeelem(&r, 3); // a td tr
}
}
khtml_closeelem(&r, 2); // table div[floater]
}
khtml_closeelem(&r, 2); // div[container] body
khtml_close(&r);
*/
}
#endif
else if(format == "json") {
std::optional<UpT> type;
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment