Skip to content

Commit bea096a

Browse files
authored
Merge pull request #2 from Vi014/bonus-campaign-parsing
Bonus campaign parsing
2 parents 1ebd9cc + 671a063 commit bea096a

File tree

3 files changed

+122
-7
lines changed

3 files changed

+122
-7
lines changed

EXA-Parser/EXA-Parser.cpp

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <iostream>
66
#include <filesystem>
77
#include <string>
8+
#include <vector>
9+
#include <algorithm>
810

911
namespace fs = std::filesystem;
1012
using namespace std;
@@ -62,6 +64,7 @@ map<string, Solution> solutions;
6264
map<string, Info> dataMap;
6365
vector<string> ids = { };
6466
vector<string> battles = { };
67+
vector<string> bonus = { };
6568

6669
// Utils
6770
string readString(ifstream& stream) {
@@ -157,6 +160,7 @@ int main(int argc, char* argv[])
157160
int globalCounter = 0;
158161
int solutionCounter = 1;
159162
int battleCounter = 1;
163+
int bonusCounter = 1;
160164
string line;
161165
while (getline(dataStream, line)) {
162166
int i1 = line.find(',');
@@ -171,6 +175,8 @@ int main(int argc, char* argv[])
171175

172176
bool isBattle = description.rfind("battle-", 0) == 0;
173177
int counter = isBattle ? battleCounter++ : solutionCounter++;
178+
bool isBonus = description.rfind("bonus-", 0) == 0;
179+
counter = isBonus ? bonusCounter++ : counter;
174180

175181
// Create path based on title
176182
string path = ((counter < 10) ? ("0" + to_string(counter)) : to_string(counter)) + '-';
@@ -200,8 +206,9 @@ int main(int argc, char* argv[])
200206

201207
dataMap[id] = info;
202208

203-
if (!isBattle) ids.push_back(id);
209+
if(!isBattle) ids.push_back(id);
204210
else battles.push_back(id);
211+
if(isBonus) bonus.push_back(id);
205212

206213
globalCounter++;
207214
}
@@ -323,6 +330,15 @@ int main(int argc, char* argv[])
323330
cout << " No 'battles' directory found" << endl;
324331
}
325332

333+
fs::path pathOutputBonus = pathOutput / "bonus";
334+
if (fs::is_directory(pathOutputBonus)) {
335+
fs::remove_all(pathOutputBonus);
336+
cout << " Clearing 'bonus' directory" << endl;
337+
}
338+
else {
339+
cout << " No 'bonus' directory found" << endl;
340+
}
341+
326342
cout << endl << "Create files:" << endl;
327343

328344
// Create README
@@ -360,7 +376,7 @@ int main(int argc, char* argv[])
360376
for (int i = 0; i < maxChars + 2 + 4; i++) readmeOut << '-';
361377
readmeOut << "|--------|------|----------|" << endl;
362378

363-
for (int i = 0; i < ids.size(); i++) {
379+
for (int i = 0; i < 34; i++) {
364380
Info info = dataMap[ids[i]];
365381
readmeOut << "| [" << to_string(i + 1) << ": " << info.title << "](solutions/" << info.path << ") ";
366382

@@ -404,6 +420,34 @@ int main(int argc, char* argv[])
404420
writeNum(readmeOut, solution.losses, 6);
405421
readmeOut << " | S+ |" << endl;
406422
}
423+
424+
// Create bonus
425+
readmeOut << endl << "| Bonus campaign level";
426+
for (int i = 0; i < maxChars - 5 + 1 + 4; i++) readmeOut << ' ';
427+
readmeOut << "| Cycles | Size | Activity |" << endl;
428+
429+
readmeOut << "|";
430+
for (int i = 0; i < maxChars + 2 + 4; i++) readmeOut << '-';
431+
readmeOut << "|--------|------|----------|" << endl;
432+
433+
for (int i = 0; i < bonus.size(); i++) {
434+
Info info = dataMap[bonus[i]];
435+
readmeOut << "| [" << to_string(i + 1) << ": " << info.title << "](bonus/" << info.path << ") ";
436+
437+
int total = maxChars - (1 + info.title.length() + 12 + info.path.length() + 1);
438+
for (int j = 0; j < total; j++) readmeOut << ' ';
439+
440+
if (i < 9) readmeOut << ' ';
441+
442+
Solution solution = solutions[ids[34 + i]];
443+
readmeOut << "| ";
444+
writeNum(readmeOut, solution.cycles, CYCLE_N);
445+
readmeOut << " | ";
446+
writeNum(readmeOut, solution.size, SIZE_N);
447+
readmeOut << " | ";
448+
writeNum(readmeOut, solution.activity, ACTIVITY_N);
449+
readmeOut << " |" << endl;
450+
}
407451
}
408452
else if (line == "<!-- EXA_END -->") {
409453
readmeOut << line << endl;
@@ -425,7 +469,7 @@ int main(int argc, char* argv[])
425469

426470
cout << endl << " Making solutions:" << endl;
427471

428-
for (int i = 0; i < ids.size(); i++) {
472+
for (int i = 0; i < 34; i++) {
429473
Info info = dataMap[ids[i]];
430474

431475
fs::create_directories(pathOutputSolutions / info.path);
@@ -531,4 +575,66 @@ int main(int argc, char* argv[])
531575

532576
cout << " " << info.title << endl;
533577
}
578+
579+
// Create bonus folder
580+
fs::create_directories(pathOutputBonus);
581+
582+
cout << endl << " Making bonus:" << endl;
583+
584+
for (int i = 0; i < bonus.size(); i++) {
585+
Info info = dataMap[bonus[i]];
586+
587+
fs::create_directories(pathOutputBonus / info.path);
588+
ofstream readmeOut(pathOutputBonus / info.path / "README.md");
589+
590+
readmeOut << "# " << to_string(i + 1) << ": " << info.title << endl << endl;
591+
592+
// Copy GIF
593+
fs::copy(info.gif, pathOutputBonus / info.path / info.gif.filename());
594+
readmeOut << "<div align=\"center\"><img src=\"" << info.gif.filename().string() << "\" /></div>" << endl << endl;
595+
596+
// Read description files
597+
ifstream descriptionStream(pathDescriptions / info.description);
598+
if (descriptionStream) {
599+
readmeOut << "## Instructions" << endl;
600+
while (getline(descriptionStream, line)) {
601+
readmeOut << "> " << line << endl;
602+
}
603+
readmeOut << endl;
604+
}
605+
606+
readmeOut << "## Solution" << endl << endl;
607+
608+
// Add source as well
609+
Solution solution = solutions[bonus[i]];
610+
611+
for (int j = 0; j < solution.exas.size(); j++) {
612+
EXA exa = solution.exas[j];
613+
readmeOut << "### [" << exa.name << "](" << exa.name << ".exa) (" << (exa.local ? "local" : "global") << ")" << endl;
614+
readmeOut << "```asm" << endl;
615+
readmeOut << exa.source << endl;
616+
readmeOut << "```" << endl << endl;
617+
618+
// Generate file as well
619+
ofstream exaOut(pathOutputBonus / info.path / (exa.name + ".exa"));
620+
exaOut << exa.source;
621+
}
622+
623+
// Copy OG file save as well
624+
fs::copy(solution.path, pathOutputBonus / info.path / solution.path.filename());
625+
626+
// Add score
627+
readmeOut << "#### Results" << endl;
628+
readmeOut << "| Cycles | Size | Activity |" << endl;
629+
readmeOut << "|--------|------|----------|" << endl;
630+
readmeOut << "| ";
631+
writeNum(readmeOut, solution.cycles, CYCLE_N);
632+
readmeOut << " | ";
633+
writeNum(readmeOut, solution.size, SIZE_N);
634+
readmeOut << " | ";
635+
writeNum(readmeOut, solution.activity, ACTIVITY_N);
636+
readmeOut << " |" << endl;
637+
638+
cout << " " << info.title << endl;
639+
}
534640
}

EXA-Parser/data.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PB022,battle-3,Deadlock's Domain (Deadlock)
2626
PB023,baseball,Xtreme League Baseball (Player Database)
2727
PB024,mmo,King's Ransom Online (US West Realm)
2828
PB028,satellite,KGOG-TV (Satellite Uplink)
29-
PB025,bank,Equity First Bank (San Francisco (ATMs Offline)
29+
PB025,bank,Equity First Bank (San Francisco - ATMs Offline)
3030
PB019,battle-4,The Wormhole (X10X10X)
3131
PB026B,worm,TEC EXA-Blaster Modem (Dataphone Network)
3232
PB029B,snaxnet,Last Stop Snaxnet (Warehouse 27)
@@ -36,4 +36,13 @@ PB031B,battle-5,Aberdeen (selenium_wolf)
3636
PB033,dna,US Government (Fema Genetic Database)
3737
PB034,secure-enclave,Unknown Network 2 (Unknown Context)
3838
PB035B,pagers,TEC EXA-Blaster Modem (Pager Network)
39-
PB036,interface,Mitsuzen HDI-10 (Cerebral Cortex)
39+
PB036,interface,Mitsuzen HDI-10 (Cerebral Cortex)
40+
PB054,bonus-mutex,Bloodlust Online (US East Realm)
41+
PB053,bonus-nth,Motor Vehicle Administration (Scheduling System)
42+
PB050,bonus-ghast,Cybermyth Studios (Accounting System)
43+
PB056,bonus-hydro,US Department of Defense (USAF Secure Facility)
44+
PB051,bonus-plastered,Netronics NET40 Modem (The Wardialer)
45+
PB057,bonus-selenium,Española Valley High School (School Management System)
46+
PB052,bonus-x10,Mitsuzen D300-N (Personal Storage Array)
47+
PB055,bonus-deadlock,Crystalair International (Ticketing System)
48+
PB058,bonus-moss,Your Computer (Unknown Context)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ Linux:
9393
## TODO
9494
- [ ] Generate circa 1997 geocities static html pages
9595
- [ ] [Achievements](https://steamcommunity.com/stats/716490/achievements)
96-
- [ ] Bonus Levels
97-
- [ ] Nonograms
96+
- [x] Bonus Levels
97+
- [ ] Nonograms

0 commit comments

Comments
 (0)