Skip to content

Commit 526f7fa

Browse files
committed
Added custom splash files!
2 parents 877eec6 + 795c2d5 commit 526f7fa

File tree

7 files changed

+141
-37
lines changed

7 files changed

+141
-37
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Splash Text!
2+
This is a simple mod that adds some splash text like in Minecraft to your GD main menu!
3+
4+
# Creating Custom Splashes
5+
To create custom splashes, create a file somewhere and give it
6+
the file extension `.splash`, `.txt`, or `.text`. Making a splash
7+
is as simple as just writing one per line. However, there are some
8+
additional features which may help you in writing cooler splashes.
9+
10+
> [!WARNING]
11+
> Only ASCII characters supported by `goldFont.fnt` are supported and
12+
> **invalid characters will result in the file failing to be parsed.**
13+
> If your file is failing to parse, the reason why will be outputted
14+
> as an error in the developer console.
15+
16+
## Comments
17+
You can add comments to the file which will be ignored by the mod.
18+
To make one you simply type a hashtag `#` and all characters after it will
19+
be ignored.
20+
21+
```
22+
I'm a custom splash!
23+
# This is a comment!
24+
25+
I have an inline comment! # Hello, world!
26+
```
27+
28+
- The first line will be unmodified.
29+
- The second line will be ignored.
30+
- The third line will be ignored.
31+
- The fourth line will be stripped of its inline comment.
32+
33+
## Macros
34+
Additionally, there are some special macros you can use. These can
35+
add some special flair to your splashes.
36+
| Macro | Description |
37+
| ----- | ----------- |
38+
| \_\_LINE\_\_ | The line number in the file |
39+
| \_\_PLAYER\_USERNAME\_\_ | The GD account username of the user |
40+
| \_\_RANDOM\_\_ | Random number between 0 and 100 |

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.1.0
2+
- Users can now create their own splashes!
3+
4+
# 1.0.3
5+
- Fixed newline parsing
6+
17
# 1.0.2
28
- Updated Geode SDK to 4.6.1
39

mod.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,40 @@
88
},
99
"id": "alphii.gd-splash-text",
1010
"name": "Splash Text!",
11-
"version": "v1.0.2",
11+
"version": "v1.1.0",
1212
"developer": "Alphii",
1313
"description": "",
14+
"tags": ["enhancement", "offline"],
15+
"links": {
16+
"community": "https://discord.gg/tVPtwJexSX",
17+
"source": "https://github.com/AlphiiGD/Splash-Text"
18+
},
1419
"resources": {
1520
"files": [
1621
"resources/*.splash"
1722
]
23+
},
24+
"settings": {
25+
"extra-splash-file": {
26+
"type": "file",
27+
"name": "Extra Splashes",
28+
"description": "Additional splash texts, one per line. Restart your game to apply. See more info about writing these on the GitHub page!",
29+
"requires-restart": true,
30+
"default": {
31+
"win": "",
32+
"mac": "",
33+
"android": "",
34+
"ios": "{gd_dir}/Clubstep.mp3"
35+
},
36+
"control": {
37+
"dialog": "open",
38+
"filters": [
39+
{
40+
"files": ["*.splash", "*.txt", "*.text"],
41+
"description": "Splash files."
42+
}
43+
]
44+
}
45+
}
1846
}
1947
}

resources/splash.splash

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ Mod by Alphii!
33
Also try The Impossible Game!
44
What's your hardest?
55
Over 9000 Stars!
6-
This splash text message is very long and at line 6 in the file!
6+
This splash text message is very long and at line __LINE__ in the file!
77
rust sucks
88
Look! Creator points!
99
As seen on YouTube!
1010
Uses OpenGL!
1111
Yaaay!
12-
you are fuck map
12+
"Unlock new icons and colors by completing achievements!"
1313
Closed source!
1414
Open source!
1515
4,294,967,296 colors!
@@ -68,4 +68,8 @@ Jump up, jump up, and get down!
6868
IDDQD
6969
impulse 101
7070
swpreme
71-
Good luck Doggie!
71+
Good luck Doggie!
72+
__PLAYER_USERNAME__ is you!
73+
You are __RANDOM__% complete!
74+
Unlock icons from achievements!
75+
Triple Spikes!

src/MenuLayer.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@ class $modify(ST_MenuLayer, MenuLayer)
2121
return false;
2222
}
2323

24-
if (!m_fields->m_SplashRead) m_fields->m_SplashRead = new SplashRead("splash.splash");
24+
if (!m_fields->m_SplashRead)
25+
{
26+
m_fields->m_SplashRead = new SplashRead();
27+
if (!m_fields->m_SplashRead->loadFile(Mod::get()->getResourcesDir() / "splash.splash"))
28+
{
29+
log::error("Failed to load file {}", Mod::get()->getResourcesDir() / "splash.splash");
30+
}
31+
32+
auto extraPath = Mod::get()->getSettingValue<std::filesystem::path>("extra-splash-file");
33+
if (!extraPath.empty() && !m_fields->m_SplashRead->loadFile(extraPath))
34+
{
35+
log::error("Failed to load file {}", extraPath.string());
36+
}
37+
}
2538
m_fields->m_SplashStr = m_fields->m_SplashRead->getRandomLine();
26-
auto mainTitle = getChildByID("main-title");
39+
auto mainTitle = getChildByIDRecursive("main-title");
2740

2841
m_fields->m_SplashText = ScalingLabel::create(m_fields->m_SplashStr.c_str(), "goldFont.fnt");
2942
m_fields->m_SplashText->setScale(0.5f / (1.0f + 0.05f * strlen(m_fields->m_SplashText->getLabel()->getString())));

src/SplashRead.cpp

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
using namespace geode::prelude;
55

66
// Loads the file into a std::vector<string>, returns false if it fails.
7-
bool SplashRead::loadFile()
7+
bool SplashRead::loadFile(std::filesystem::path filePath)
88
{
9+
if (filePath.empty()) return false;
10+
11+
m_FileStream.open(filePath);
912
if (!m_FileStream.is_open())
1013
{
11-
log::error("Attempting to load a file from unopened stream!");
14+
log::error("File failed to open! May not exist!");
1215
return false;
1316
}
1417

@@ -45,53 +48,51 @@ bool SplashRead::loadFile()
4548
continue;
4649
}
4750
}
51+
52+
// Replace __LINE__ with the line number
53+
std::string lineMacro = "__LINE__";
54+
if (size_t pos = line.find(lineMacro);
55+
pos != std::string::npos)
56+
{
57+
line.replace(pos, lineMacro.length(), std::to_string(lineNum));
58+
}
59+
60+
// Replace __PLAYER_USERNAME__ with player name
61+
std::string playerMacro = "__PLAYER_USERNAME__";
62+
if (size_t pos = line.find(playerMacro);
63+
pos != std::string::npos)
64+
{
65+
line.replace(pos, playerMacro.length(), GJAccountManager::get()->m_username);
66+
}
4867

49-
// Non-alphanumeric characters are not allowed, if we see one, we fail.
5068
// Algorithm provided by undefined06855 on Discord and Git
69+
std::string trimmedLine;
70+
trimmedLine.reserve(line.length());
5171
for (int i = 0; i < line.length(); i++)
5272
{
53-
if (line[i] == '\0') continue;
54-
if (line[i] < ' ' || line[i] > '~')
55-
{
56-
if (line[i] != '\n' && line[i] != '\r')
57-
{
58-
log::error("Non-alphanumeric character detected at col {} of line {}", i + 1, lineNum);
59-
return false;
60-
}
61-
}
73+
if (line[i] == '\0' || line[i] == '\n' || line[i] == '\r' || line[i] < ' ' || line[i] > '~') continue;
74+
trimmedLine += line[i];
6275
}
6376

6477
// If our file stream fails during loading then we gotta return false
6578
if (m_FileStream.fail())
6679
{
6780
log::error("File stream failed during load.");
81+
m_FileStream.close();
6882
return false;
6983
}
7084

7185
// Finally we can push back our processed string
72-
m_Lines.push_back(line);
86+
m_Lines.push_back(trimmedLine);
7387
lineNum++;
7488
}
7589

90+
m_FileStream.close();
7691
return true;
7792
}
7893

79-
SplashRead::SplashRead(std::string filePath)
94+
SplashRead::SplashRead()
8095
{
81-
m_FileStream.open(Mod::get()->getResourcesDir() / filePath);
82-
if (m_FileStream.fail())
83-
{
84-
log::error("Failed to open file {}", Mod::get()->getResourcesDir() / filePath);
85-
m_FileStream.close();
86-
}
87-
88-
if (!loadFile())
89-
{
90-
log::error("Failed to load file {}", filePath);
91-
m_Lines.clear();
92-
}
93-
94-
m_FileStream.close();
9596
}
9697

9798
std::string SplashRead::getRandomLine()
@@ -105,5 +106,17 @@ std::string SplashRead::getRandomLine()
105106
std::random_device rd;
106107
std::mt19937 gen(rd());
107108
std::uniform_int_distribution<> dis(0, m_Lines.size() - 1);
108-
return m_Lines[dis(gen)];
109+
110+
std::string selected = m_Lines[dis(gen)];
111+
std::string splashText(selected); // Copy to avoid modifying original
112+
113+
std::string randMacro = "__RANDOM__";
114+
if (size_t pos = splashText.find(randMacro);
115+
pos != std::string::npos)
116+
{
117+
std::uniform_int_distribution<> dis0_100(0, 100);
118+
splashText.replace(pos, randMacro.length(), std::to_string(dis0_100(gen)));
119+
}
120+
121+
return splashText;
109122
}

src/SplashRead.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class SplashRead
88
private:
99
std::ifstream m_FileStream;
1010
std::vector<std::string> m_Lines;
11-
bool loadFile();
1211
public:
13-
SplashRead(std::string filePath);
12+
bool loadFile(std::filesystem::path filePath);
13+
SplashRead();
1414
std::string getRandomLine();
1515
};

0 commit comments

Comments
 (0)