Skip to content

Commit

Permalink
Merge pull request #14 from ogamespec/main
Browse files Browse the repository at this point in the history
txtsaver.cpp
  • Loading branch information
ogamespec authored Oct 3, 2023
2 parents 598740d + 23c18cb commit 6dd2bad
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
2 changes: 1 addition & 1 deletion patterns/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);

printf("Patterns, " VERSION_STR "\n");
wprintf(L"Patterns, " VERSION_STR L"\n");
#endif

AddProfilerProcs();
Expand Down
69 changes: 63 additions & 6 deletions patterns/txtsaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,85 @@ void TxtSave(char* FileName)
{
int i, NumCells;
PatternEntry* Pattern;
PatternItem* Item;
FILE* f;
CHAR Name[0x100];

f = fopen(FileName, "wt");
if (!f)
return;

NumCells = GetPatternEntryNum();
// Collect patterns

NumCells = GetPatternEntryNum();
PatternEntry* patterns = new PatternEntry[NumCells];
for (i = 0; i < NumCells; i++)
{
Pattern = GetPatternEntry(i);
memcpy(&patterns[i], Pattern, sizeof(PatternEntry));
}

// Get the rows

std::list<RowEntry*> rows;

RecalcRows(rows, patterns, NumCells);

// Walk the rows

std::list< PatternEntry*> row_patterns;

for (auto it = rows.begin(); it != rows.end(); ++it)
{
RowEntry* row = *it;
row_patterns.clear();

for (i = 0; i < NumCells; i++)
{
Pattern = GetPatternEntry(i);

bool hit = false;

if (WorkspaceRowArrangement == 0) {
if (Pattern->PlaneX >= row->planeX && Pattern->PlaneX < (row->planeX + Pattern->Width)) {
hit = true;
}
}
else {
if (Pattern->PlaneY >= row->planeY && Pattern->PlaneY < (row->planeY + Pattern->Height)) {
hit = true;
}
}

Item = PatternGetItem(Pattern->PatternName);
if (hit) {
row_patterns.push_back(Pattern);
}
}

strcpy(Name, Pattern->PatternName);
ReplaceSpecialChars(Name);
// Sort
if (WorkspaceRowArrangement == 0) {
row_patterns.sort([](const PatternEntry* f, const PatternEntry* s) { return f->PlaneY < s->PlaneY; });
}
else {
row_patterns.sort([](const PatternEntry* f, const PatternEntry* s) { return f->PlaneX < s->PlaneX; });
}

fprintf(f, "%s ", Name);
fprintf(f, "row %d: ", row->index);
for (auto row_it = row_patterns.begin(); row_it != row_patterns.end(); ++row_it) {

Pattern = *row_it;

strcpy(Name, Pattern->PatternName);
ReplaceSpecialChars(Name);
fprintf(f, "%s ", Name);
}
fprintf(f, "\n");
}

// Cleanup

ClearRowsList(rows);
delete[] patterns;

fprintf(f, "\n");

fclose(f);
Expand Down

0 comments on commit 6dd2bad

Please sign in to comment.