Skip to content

Commit 9256100

Browse files
NyakoFoxflibitijibibo
authored andcommitted
Add ifversion
This command adds `ifversion`, as both a simplified and internal command. The system works like so: - `ifversion(2.6,script2)` -> If you're on 2.6.0 or greater - `ifversion(2.6.0,script2)` -> Same as above - `ifversion(2.6.3,script2)` -> You're using 2.6.3 or greater - `ifversion(2.5,script2)` -> You're using 2.5 or greater - `ifversion(2,script2)` -> You're using 2.0.0 or greater (yep...) `ReleaseVersion.h` has a few new defines to make this possible, being `MAJOR_VERSION`, `MINOR_VERSION` and `PATCH_VERSION`. With the help of a few macros, `RELEASE_VERSION` is now constructed using those.
1 parent b8ca587 commit 9256100

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#ifndef RELEASEVERSION_H
22
#define RELEASEVERSION_H
33

4-
#define RELEASE_VERSION "v2.5"
4+
#define MAJOR_VERSION 2
5+
#define MINOR_VERSION 5
6+
#define PATCH_VERSION 0
7+
8+
#define VVV_STRINGIFY(x) #x
9+
#define VVV_TOSTRING(x) VVV_STRINGIFY(x)
10+
11+
#if PATCH_VERSION == 0
12+
#define RELEASE_VERSION "v" VVV_TOSTRING(MAJOR_VERSION) "." VVV_TOSTRING(MINOR_VERSION)
13+
#else
14+
#define RELEASE_VERSION "v" VVV_TOSTRING(MAJOR_VERSION) "." VVV_TOSTRING(MINOR_VERSION) "." VVV_TOSTRING(PATCH_VERSION)
15+
#endif
516

617
#endif /* RELEASEVERSION_H */

desktop_version/src/Script.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "LocalizationStorage.h"
2121
#include "Map.h"
2222
#include "Music.h"
23+
#include "ReleaseVersion.h"
2324
#include "Unreachable.h"
2425
#include "UtilityClass.h"
2526
#include "VFormat.h"
@@ -338,6 +339,67 @@ void scriptclass::run(void)
338339
}
339340
}
340341
}
342+
if (words[0] == "ifversion")
343+
{
344+
// A short for each is SURELY enough
345+
unsigned short version[3] = { 0, 0, 0 };
346+
bool valid_version = true;
347+
int current = 0;
348+
349+
// Crawl through the string
350+
for (int i = 0; i < words[1].size(); i++)
351+
{
352+
// If the current character is a number, add it to the current version part
353+
if (words[1][i] >= '0' && words[1][i] <= '9')
354+
{
355+
version[current] = version[current] * 10 + (words[1][i] - '0');
356+
}
357+
else if (words[1][i] == '.')
358+
{
359+
current++;
360+
if (current >= 3)
361+
{
362+
break;
363+
}
364+
}
365+
else
366+
{
367+
// Unexpected character
368+
valid_version = false;
369+
break;
370+
}
371+
}
372+
373+
if (valid_version)
374+
{
375+
bool version_is_met = false;
376+
377+
if (MAJOR_VERSION > version[0])
378+
{
379+
version_is_met = true;
380+
}
381+
else if (MAJOR_VERSION == version[0])
382+
{
383+
if (MINOR_VERSION > version[1])
384+
{
385+
version_is_met = true;
386+
}
387+
else if (MINOR_VERSION == version[1])
388+
{
389+
if (PATCH_VERSION >= version[2])
390+
{
391+
version_is_met = true;
392+
}
393+
}
394+
}
395+
396+
if (version_is_met)
397+
{
398+
loadalts("custom_" + words[2], "custom_" + raw_words[2]);
399+
position--;
400+
}
401+
}
402+
}
341403
if (words[0] == "customiftrinkets")
342404
{
343405
if (game.trinkets() >= ss_toi(words[1]))
@@ -3574,6 +3636,9 @@ bool scriptclass::loadcustom(const std::string& t)
35743636
}else if(words[0] == "iftrinketsless"){
35753637
if(customtextmode==1){ add("endtext"); customtextmode=0;}
35763638
add("custom"+lines[i]);
3639+
}else if(words[0] == "ifversion"){
3640+
if(customtextmode==1){ add("endtext"); customtextmode=0;}
3641+
add(lines[i]);
35773642
}else if(words[0] == "textcase"){
35783643
if(customtextmode==1){ add("endtext"); customtextmode=0;}
35793644
add(lines[i]);

0 commit comments

Comments
 (0)