Skip to content

Commit

Permalink
GameInfoReader: Cleaned up code, now works cleanly with NewGame Menu
Browse files Browse the repository at this point in the history
Has added but optional supports for comments in an episode definition, for gametype, header, description, and a development flag.
  • Loading branch information
Lemon-King committed Oct 21, 2023
1 parent 317f8bc commit 391b76f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 54 deletions.
32 changes: 31 additions & 1 deletion resources/assets/mapinfo.gameinfo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include mapinfo/heretic.mapinfo
include mapinfo/hexen.mapinfo
include mapinfo/hexdd.mapinfo
include mapinfo/hxdd.mapinfo
include mapinfo/title.mapinfo

GameInfo {
titlepage = "TITLE"
Expand Down Expand Up @@ -177,66 +178,95 @@ episode e1m1
{
name = "$MNU_COTD"
key = "c"
//gametype = "heretic"
//header = "$MNU_HEADER_HERETIC"
//description = "$MNU_STORY_HERETIC"
}

episode e2m1
{
name = "$MNU_HELLSMAW"
key = "h"
//gametype = "heretic"
//header = "$MNU_HEADER_HERETIC"
//description = "$MNU_STORY_HERETIC"
}

episode e3m1
{
name = "$MNU_DOME"
key = "d"
//gametype = "heretic"
//header = "$MNU_HEADER_HERETIC"
//description = "$MNU_STORY_HERETIC"
}

episode e4m1
{
name = "$MNU_OSSUARY"
key = "o"
//gametype = "heretic"
//header = "$MNU_HEADER_HERETIC"
//description = "$MNU_STORY_HERETIC"
extended
}

episode e5m1
{
name = "$MNU_DEMESNE"
key = "s"
//gametype = "heretic"
//header = "$MNU_HEADER_HERETIC"
//description = "$MNU_STORY_HERETIC"
optional
extended
}

episode e6m1
{
name = "$MNU_FATEPTH"
key = "f"
//gametype = "heretic"
//header = "$MNU_HEADER_HERETIC"
//description = "$MNU_STORY_HERETIC"
optional
extended
}

episode MAP01
{
name = "$MNU_HEXEN"
key = "b"
optional
//gametype = "hexen"
//header = "$MNU_HEADER_HEXEN"
//description = "$MNU_STORY_HEXEN"
}

episode MAP50
{
name = "$MNU_HEXDD"
key = "k"
//gametype = "hexen"
//header = "$MNU_HEADER_HEXEN"
//description = "$MNU_STORY_HEXDD"
optional
}

episode heretest
{
name = "HERETIC TEST"
key = "1"
//gametype = "heretic"
optional
//development
}
episode hextest
{
name = "HEXEN TEST"
key = "2"
//gametype = "hexen"
optional
//development
}

defaultmap
Expand Down
89 changes: 42 additions & 47 deletions resources/assets/zscript/lib/gameinforeader.zs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ class GameInfoReader {
info.split(lines, "\n");

for (let i = 0; i < lines.Size(); i++) {
if (lines[i].IndexOf("PlayerClasses") != -1) {
String line = lines[i];
String line = lines[i];
if (line.IndexOf("PlayerClasses") != -1) {

line.Substitute('"', ""); // remove quotes
line.Substitute(" ", ""); // remove spaces

Array<String> classLine;
line.split(classLine, "=");
Array<String> split;
line.split(split, "=");

String lineClasses = classLine[classLine.Size() - 1];
String lineClasses = split[split.Size() - 1];
lineClasses.split(classes, ",");

break;
}
}
Expand Down Expand Up @@ -77,41 +76,33 @@ class GameInfoReader {
if (idxSkill != -1 && idxBraceOpen != -1 && idxBraceClose != -1) {
SkillInfo skInfo = new("SkillInfo");

String between = minfo.Mid(idxBraceOpen, idxBraceClose);

//console.printf("info %s", between);

Array<String> split;
between.split(split, "\n");
for (int i = 0; i < split.Size(); i++) {
String line = split[i];

int idxQuoteOpen = line.IndexOf('"');
String value = line.Mid(idxQuoteOpen + 1);
int idxQuoteClosed = value.IndexOf('"');
value = value.Mid(0, idxQuoteClosed);
String strBlock = minfo.Mid(idxBraceOpen, idxBraceClose);

Array<String> lines;
strBlock.split(lines, "\n");
for (let i = 0; i < lines.Size(); i++) {
String line = lines[i];
if (line.MakeLower().IndexOf("playerclassname") != -1) {
String className = value;
line.Substitute('"', ""); // remove quotes
line.Substitute(" ", ""); // remove spaces

Array<String> split;
line.split(split, "=");

Array<String> splitLine;
line.split(splitLine, ",");
String details = split[split.Size() - 1];

String section = splitLine[splitLine.Size() - 1];
idxQuoteOpen = section.IndexOf('"');
String classSkill = section.Mid(idxQuoteOpen + 1);
idxQuoteClosed = classSkill.IndexOf('"');
classSkill = classSkill.Mid(0, idxQuoteClosed);
console.printf("classSkill %s", classSkill);

skInfo.classes.push(className);
skInfo.names.push(classSkill);
console.printf("class %s, skill %s", className, classSkill);
split.Clear();
details.split(split, ",");
skInfo.classes.push(split[0]);
skInfo.names.push(split[1]);
} else if (line.MakeLower().IndexOf("name") != -1) {
skInfo.name = value;
console.printf("skill %s", value);
line.Substitute('"', ""); // remove quotes
line.Substitute(" ", ""); // remove spaces

Array<String> split;
line.split(split, "=");
skInfo.name = split[1];
}

}

self.skills.Push(skInfo);
Expand Down Expand Up @@ -148,24 +139,27 @@ class GameInfoReader {
if (idxEpisode != -1 && idxBraceOpen != -1 && idxBraceClose != -1) {
EpisodeInfo epInfo = new("EpisodeInfo");

String between = minfo.Mid(idxBraceOpen, idxBraceClose);
String strBlock = minfo.Mid(idxBraceOpen, idxBraceClose);

Array<String> split;
between.split(split, "\n");
for (int i = 0; i < split.Size(); i++) {
String line = split[i];
Array<String> lines;
strBlock.split(lines, "\n");
for (int i = 0; i < lines.Size(); i++) {
String line = lines[i];

line.Substitute('"', ""); // remove quotes
line.Substitute(" ", ""); // remove spaces

int idxQuoteOpen = line.IndexOf('"');
String value = line.Mid(idxQuoteOpen + 1);
int idxQuoteClosed = value.IndexOf('"');
Array<String> split;
line.split(split, "=");

value = value.Mid(0, idxQuoteClosed);
if (line.IndexOf("name") != -1) {
epInfo.name = value;
epInfo.name = split[1];
} else if (line.IndexOf("header") != -1) {
epInfo.header = split[1];
} else if (line.IndexOf("description") != -1) {
epInfo.description = value;
epInfo.description = split[1];
} else if (line.IndexOf("gametype") != -1) {
epInfo.gametype = value;
epInfo.gametype = split[1];
} else if (line.IndexOf("development")) {
epInfo.development = true;
}
Expand Down Expand Up @@ -204,6 +198,7 @@ class SkillInfo {
class EpisodeInfo {
String name;
String gametype;
String header;
String description;
bool extended;
bool development;
Expand Down
28 changes: 28 additions & 0 deletions resources/assets/zscript/lib/lemonutil.zs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ class LemonUtil {
};
return classes[id];
}
static int ClassNameToSimple(string className) {
Array<string> simple = {
"corvus",
"fighter",
"cleric",
"mage",
"paladin",
"cleric",
"necromancer",
"assassin",
"succubus",
"corvus"
};
return simple.Find(className);
}

static void LaunchMap(String mapId, int skill) {
LemonUtil.CVAR_SetString("hxdd_map_select", String.format("%s,%d", mapId, skill));
Expand Down Expand Up @@ -105,6 +120,19 @@ class LemonUtil {
return -1;
}

static int GetGameType(String type) {
String gametype = type.MakeLower();
if (gametype == "heretic") {
return 1;
} else if (gametype == "hexen") {
return 2;
} else if (gametype == "doom") {
return 3;
} else {
return 0;
}
}

static int GetOptionGameMode() {
int cvarGameMode = LemonUtil.CVAR_GetInt("hxdd_gamemode", 0);
int gameType = gameinfo.gametype;
Expand Down
21 changes: 15 additions & 6 deletions resources/assets/zscript/menu/newgame.zs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class ZFPreGameSetupHandler : HXDD_ZF_Handler {
} else if (menu.frame.getPosX() == -1920) {
// start game with selected settings
Menu.MenuSound("menu/choose");
if (menu.selectedGameMode == 0) {
EpisodeInfo episode = menu.frameGameOptions.gameinfo.episodes[menu.selectedEpisode];
menu.selectedGameMode = LemonUtil.GetGameType(episode.gametype);
}
LemonUtil.CVAR_SetInt("hxdd_gamemode", menu.selectedGameMode);
LemonUtil.CVAR_SetInt("hxdd_armor_mode", menu.selectedArmorMode);
LemonUtil.CVAR_SetInt("hxdd_progression", menu.selectedProgressionMode);
Expand Down Expand Up @@ -118,12 +122,17 @@ class ZFGameOptionsHandler : HXDD_ZF_Handler {
}

void ShowEpisodeInformation() {
if (menu.selectedEpisode < 6) {
optMenu.SetInfoText("$MNU_HEADER_HERETIC", "$MNU_STORY_HERETIC");
} else if (menu.selectedEpisode == 6) {
optMenu.SetInfoText("$MNU_HEADER_HEXEN", "$MNU_STORY_HEXEN");
} else if (menu.selectedEpisode == 7) {
optMenu.SetInfoText("$MNU_HEADER_HEXDD", "$MNU_STORY_HEXDD");
if (optMenu.gameinfo.episodes.Size() - 1 < menu.selectedEpisode) {
optMenu.SetInfoText("ERROR!", "THIS EPISODE IS OUT OF RANGE AND MAY CRASH UPON STARTING!\nCHECK YOUR WADS AND PK3 FILES!");
return;
}
EpisodeInfo episode = optMenu.gameinfo.episodes[menu.selectedEpisode];
if (episode.description != "") {
String header = episode.header;
if (header == "") {
header = episode.name;
}
optMenu.SetInfoText(header, episode.description);
} else {
optMenu.SetInfoText("$MNU_HEADER_OTHER", "$MNU_STORY_OTHER");
}
Expand Down

0 comments on commit 391b76f

Please sign in to comment.