From c16537944a320a0c3893ae2ef89ece2c60cbaace Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Sun, 9 May 2021 13:45:20 +0200 Subject: [PATCH] Allow multiple achievement lists (for add-ons). --- language.version | 4 +- zscript/kbase/swwm_kbase.zsc | 15 ++-- zscript/utility/swwm_utility.zsc | 116 +++++++++++++++++-------------- 3 files changed, 69 insertions(+), 66 deletions(-) diff --git a/language.version b/language.version index 90265b13a..99efe7c71 100644 --- a/language.version +++ b/language.version @@ -1,3 +1,3 @@ [default] -SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r466 \cu(Sun 9 May 13:16:41 CEST 2021)\c-"; -SWWM_SHORTVER="\cw0.9.11b-pre r466 \cu(2021-05-09 13:16:41)\c-"; +SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r467 \cu(Sun 9 May 13:45:20 CEST 2021)\c-"; +SWWM_SHORTVER="\cw0.9.11b-pre r467 \cu(2021-05-09 13:45:20)\c-"; diff --git a/zscript/kbase/swwm_kbase.zsc b/zscript/kbase/swwm_kbase.zsc index 39a1df2af..6f6d4a952 100644 --- a/zscript/kbase/swwm_kbase.zsc +++ b/zscript/kbase/swwm_kbase.zsc @@ -2162,22 +2162,15 @@ Class DemolitionistMenu : GenericMenu int cur = clamp(b.progress.GetInt(),0,b.maxval); bfactor = cur/double(b.maxval); } - if ( adone && bdone ) - { - // alphabetic sort - String tag1 = StringTable.Localize("$SWWM_ACHIEVEMENT_"..a.basename.."_TAG"), - tag2 = StringTable.Localize("$SWWM_ACHIEVEMENT_"..b.basename.."_TAG"); - return tag1 > tag2; - } + // sort by base index + if ( adone && bdone ) return a.baseindex > b.baseindex; if ( !adone && !bdone ) { // progress sort? if ( afactor != bfactor ) return afactor < bfactor; - // alphabetic sort - String tag1 = StringTable.Localize("$SWWM_ACHIEVEMENT_"..a.basename.."_TAG"), - tag2 = StringTable.Localize("$SWWM_ACHIEVEMENT_"..b.basename.."_TAG"); - return tag1 > tag2; + // sort by base index + return a.baseindex > b.baseindex; } // state sort return bdone; diff --git a/zscript/utility/swwm_utility.zsc b/zscript/utility/swwm_utility.zsc index 72151ebfa..90c256f46 100644 --- a/zscript/utility/swwm_utility.zsc +++ b/zscript/utility/swwm_utility.zsc @@ -15,6 +15,7 @@ enum EDoExplosionFlags Class SWWMAchievement { + int baseindex; // order of the achievement in the list String basename; transient CVar state, progress; TextureID icon; @@ -38,65 +39,74 @@ Class SWWMUtility achievements.Clear(); let lmp = Wads.FindLump("achievements.lst"); if ( lmp == -1 ) ThrowAbortException("'achievements.lst' not found"); - String dat = Wads.ReadLump(lmp); - Array list; - dat.Split(list,"\n"); + String dat; + Array list, ln; bool hide = (filter&&(swwm_filterachievements==2)); - for ( int i=0; i ln; - list[i].Split(ln,",",0); - // game filtering - if ( !(gameinfo.gametype&GAME_DOOM) && (ln[3] ~== "doom") ) continue; - else if ( !(gameinfo.gametype&GAME_HERETIC) && (ln[3] ~== "heretic") ) continue; - else if ( !(gameinfo.gametype&GAME_HEXEN) && (ln[3] ~== "hexen") ) continue; - else if ( !(gameinfo.gametype&GAME_RAVEN) && (ln[3] ~== "raven") ) continue; - else if ( !(gameinfo.gametype&(GAME_DOOM|GAME_HERETIC)) && (ln[3] ~== "nothexen") ) continue; - let ac = new("SWWMAchievement"); - ac.basename = ln[0]; - ac.maxval = ln[1].ToInt(); - ac.state = CVar.FindCVar("swwm_achievement_"..ac.basename); - // if filtering, always hide the full completion achievement until it's unlocked - if ( filter && (ac.basename == "everything") && (ac.state.GetInt() <= 0) ) + dat = Wads.ReadLump(lmp); + list.Clear(); + dat.Split(list,"\n"); + for ( int i=0; i)(AllActorClasses[i]); - if ( !c || (c == 'SWWMCollectible') ) continue; - let def = GetDefaultByType(c); - // check that we can collect it in this IWAD - if ( !def.ValidGame() ) continue; - nc++; - } - ac.maxval = nc; + ac.Destroy(); + continue; } + if ( !ac.state ) ThrowAbortException("could not find cvar 'swwm_achievement_"..ac.basename.."'"); + if ( ac.maxval ) + { + ac.progress = CVar.FindCVar("swwm_progress_"..ac.basename); + if ( !ac.progress ) ThrowAbortException("could not find cvar 'swwm_progress_"..ac.basename.."'"); + // special case for maxval + if ( ac.basename == "allcoll" ) + { + int nc = 0; + for ( int i=0; i)(AllActorClasses[i]); + if ( !c || (c == 'SWWMCollectible') ) continue; + let def = GetDefaultByType(c); + // check that we can collect it in this IWAD + if ( !def.ValidGame() ) continue; + nc++; + } + ac.maxval = nc; + } + } + else ac.progress = null; + // hide away achievements at 0% + if ( hide && (ac.state.GetInt() <= 0) && (!ac.progress || (ac.progress.GetInt() <= 0)) ) + { + ac.Destroy(); + continue; + } + ac.hasformat = (ln[2]~=="yes"); + ac.icon = TexMan.CheckForTexture("graphics/Achievements/Achievement"..ac.basename..".png",TexMan.Type_Any); + // fallback icon if one is not found + if ( !ac.icon.IsValid() ) ac.icon = TexMan.CheckForTexture("graphics/Achievements/DefaultAchievement.png",TexMan.Type_Any); + achievements.Push(ac); + bidx++; } - else ac.progress = null; - // hide away achievements at 0% - if ( hide && (ac.state.GetInt() <= 0) && (!ac.progress || (ac.progress.GetInt() <= 0)) ) - { - ac.Destroy(); - continue; - } - ac.hasformat = (ln[2]~=="yes"); - ac.icon = TexMan.CheckForTexture("graphics/Achievements/Achievement"..ac.basename..".png",TexMan.Type_Any); - // fallback icon if one is not found - if ( !ac.icon.IsValid() ) ac.icon = TexMan.CheckForTexture("graphics/Achievements/DefaultAchievement.png",TexMan.Type_Any); - achievements.Push(ac); + lmp = Wads.FindLump("achievements.lst",lmp+1); } } // achievement helpers