Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
BiscuitCookies committed Jan 11, 2023
2 parents 6ac056e + 8b038c5 commit 9077dd9
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 42 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ A parser for scripts used in Paradox Development Studios games, written in Haske
Currently only Europa Universalis IV and Hearts of Iron IV are supported,
but there are plans for other games as well.

This script read the game files and outputs text formatted into wiki tables and templates
Examples of what it currently outputs on the HoI4 wiki
https://hoi4.paradoxwikis.com/Ethiopian_national_focus_tree/scriptoutput for national focuses
https://hoi4.paradoxwikis.com/Swiss_events/scriptoutput for events

## Building

The easiest way to get it running is to use
Expand Down
2 changes: 1 addition & 1 deletion pdxparse.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

name: pdxparse

version: 0.8.6.3
version: 0.8.6.4
synopsis: A parser for scripts used in Paradox Development Studios games
description: This program extracts script and localization files from
games by Paradox Development Studios to the format
Expand Down
51 changes: 29 additions & 22 deletions src/HOI4/Decisions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import HOI4.Common -- everything
-- | Empty decision category. Starts off Nothing/empty everywhere, except id and name
-- (which should get filled in immediately).
newDecisionCat :: Text -> Maybe Text -> Maybe Text -> FilePath -> HOI4Decisioncat
newDecisionCat id locid locdesc = HOI4Decisioncat id locid locdesc Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
newDecisionCat id locid locdesc = HOI4Decisioncat id locid locdesc "decision_category_generic" Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing

-- | Take the decisions categories scripts from game data and parse them into decision
-- data structures.
Expand Down Expand Up @@ -112,7 +112,7 @@ decisioncatAddSection ddeccat stmt
= return $ (`decisioncatAddSection'` stmt) <$> ddeccat
where
decisioncatAddSection' decc stmt = case stmt of
[pdx| icon = $txt |] -> decc { decc_icon = Just txt }
[pdx| icon = $txt |] -> decc { decc_icon = txt }
[pdx| visible = %rhs |] -> case rhs of
CompoundRhs [] -> decc -- empty, treat as if it wasn't there
CompoundRhs scr -> decc { decc_visible = Just scr } -- can check from and root if target_root_trigger is true (or allowed if it's not present)
Expand Down Expand Up @@ -174,14 +174,13 @@ ppdecisioncat decc gfx = setCurrentFile (decc_path decc) $ do
let name = decc_name decc
nameD = Doc.strictText name
name_loc <- getGameL10n name
let picture = decc_picture decc
picture_pp <- maybe (return "")
(\pict ->
let pictc = if not $ "GFX_decision_cat_" `T.isPrefixOf` pict then "GFX_decision_cat_" <> pict else pict in
return $ HM.findWithDefault pictc pictc gfx)
picture
let icon = decc_icon decc
icon_pp <- (\iconc ->
let iconcat = if not $ "GFX_decision_category_" `T.isPrefixOf` iconc then "GFX_decision_category_" <> iconc else iconc in
return $ HM.findWithDefault "decision_category_generic" iconcat gfx)
icon
return . mconcat $
["== ", Doc.strictText picture_pp , "<!-- ", nameD, " --> ", Doc.strictText name_loc," ==", PP.line
["== [[File:", Doc.strictText icon_pp, ".png]]" , "<!-- ", nameD, " --> ", Doc.strictText name_loc," ==", PP.line
," version = ", Doc.strictText version, PP.line
,maybe mempty
(\txt -> mconcat [ Doc.strictText $ italicText $ Doc.nl2br txt, PP.line])
Expand Down Expand Up @@ -478,7 +477,7 @@ ppdecision dec gfx = setCurrentFile (dec_path dec) $ do
icon_pp'd <- case dec_icon dec of
Just (HOI4DecisionIconSimple txt) ->
let icond = if not $ "GFX_decision_" `T.isPrefixOf` txt then "GFX_decision_" <> txt else txt in
return $ HM.findWithDefault icond icond gfx
return $ HM.findWithDefault "decision_generic_decision" icond gfx
_ -> return "Check script"
let days_remove = dec_days_remove dec
days_re_enable = dec_days_re_enable dec
Expand Down Expand Up @@ -699,26 +698,34 @@ ppDecisionSource (HOI4DecSrcOnAction act weight) = do
,("on_wargoal_expire","<!-- on_wargoal_expire -->On wargoal expired")
,("on_weekly","<!-- on_weekly -->On every week")
]
ppDecisionSource (HOI4DecSrcNFComplete id loc) = do
nfloc <- getGameL10n loc
ppDecisionSource (HOI4DecSrcNFComplete id loc icon) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault "goal_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
return $ Doc.strictText $ mconcat ["Completing the national focus "
, "<!-- "
, iconnf
, " <!-- "
, id
, " -->"
, iquotes't nfloc
, iquotes't loc
]
ppDecisionSource (HOI4DecSrcNFSelect id loc) = do
nfloc <- getGameL10n loc
ppDecisionSource (HOI4DecSrcNFSelect id loc icon) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault "goal_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
return $ Doc.strictText $ mconcat ["Selecting the national focus "
, "<!-- "
, iconnf
, " <!-- "
, id
, " -->"
, iquotes't nfloc
, iquotes't loc
]
ppDecisionSource (HOI4DecSrcIdeaOnAdd id loc icon categ) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault icon icon gfx in
let iconname = HM.findWithDefault "idea_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
catloc <- getGameL10n categ
return $ Doc.strictText $ mconcat ["When the "
Expand All @@ -734,7 +741,7 @@ ppDecisionSource (HOI4DecSrcIdeaOnAdd id loc icon categ) = do
ppDecisionSource (HOI4DecSrcIdeaOnRemove id loc icon categ) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault icon icon gfx in
let iconname = HM.findWithDefault "idea_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
catloc <- getGameL10n categ
return $ Doc.strictText $ mconcat ["When the "
Expand Down Expand Up @@ -846,8 +853,8 @@ findActivatedDecisionsInNationalFocus hm nf = addDecisionTriggers hm (concatMap
where
findInFocus :: HOI4NationalFocus -> [(Text, HOI4DecisionSource)]
findInFocus f =
addDecisionSource (const (HOI4DecSrcNFComplete (nf_id f) (nf_name_loc f))) (maybe [] findInStmts (nf_completion_reward f)) ++
addDecisionSource (const (HOI4DecSrcNFSelect (nf_id f) (nf_name_loc f))) (maybe [] findInStmts (nf_select_effect f))
addDecisionSource (const (HOI4DecSrcNFComplete (nf_id f) (nf_name_loc f) (nf_icon f))) (maybe [] findInStmts (nf_completion_reward f)) ++
addDecisionSource (const (HOI4DecSrcNFSelect (nf_id f) (nf_name_loc f) (nf_icon f))) (maybe [] findInStmts (nf_select_effect f))

findActivatedDecisionsInIdeas :: HOI4DecisionTriggers -> [HOI4Idea] -> HOI4DecisionTriggers
findActivatedDecisionsInIdeas hm idea = addDecisionTriggers hm (concatMap findInIdea idea)
Expand Down
8 changes: 4 additions & 4 deletions src/HOI4/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ ppEventSource (HOI4EvtSrcOnAction act weight) = do
ppEventSource (HOI4EvtSrcNFComplete id loc icon) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault icon icon gfx in
let iconname = HM.findWithDefault "goal_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
return $ Doc.strictText $ mconcat ["Completing the national focus "
, iconnf
Expand All @@ -661,7 +661,7 @@ ppEventSource (HOI4EvtSrcNFComplete id loc icon) = do
ppEventSource (HOI4EvtSrcNFSelect id loc icon) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault icon icon gfx in
let iconname = HM.findWithDefault "goal_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
return $ Doc.strictText $ mconcat ["Selecting the national focus "
, iconnf
Expand All @@ -673,7 +673,7 @@ ppEventSource (HOI4EvtSrcNFSelect id loc icon) = do
ppEventSource (HOI4EvtSrcIdeaOnAdd id loc icon categ) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault icon icon gfx in
let iconname = HM.findWithDefault "idea_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
catloc <- getGameL10n categ
return $ Doc.strictText $ mconcat ["When the "
Expand All @@ -689,7 +689,7 @@ ppEventSource (HOI4EvtSrcIdeaOnAdd id loc icon categ) = do
ppEventSource (HOI4EvtSrcIdeaOnRemove id loc icon categ) = do
gfx <- getInterfaceGFX
iconnf <-
let iconname = HM.findWithDefault icon icon gfx in
let iconname = HM.findWithDefault "idea_unknown" icon gfx in
return $ "[[File:" <> iconname <> ".png|28px]]"
catloc <- getGameL10n categ
return $ Doc.strictText $ mconcat ["When the "
Expand Down
6 changes: 3 additions & 3 deletions src/HOI4/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ focusProgress msg stmt@[pdx| $lhs = @compa |] = do
Nothing -> preStatement stmt -- unknown national focus
Just nnf -> do
let nfKey = nf_id nnf
nfIcon = HM.findWithDefault "GFX_goal_unknown" (nf_icon nnf) gfx
nfIcon = HM.findWithDefault "goal_unknown" (nf_icon nnf) gfx
nf_loc <- getGameL10n nfKey
msgToPP (msg nfIcon nfKey nf_loc compare)
where
Expand Down Expand Up @@ -1991,7 +1991,7 @@ handleFocus msg stmt@[pdx| $lhs = $nf |] = do
Nothing -> preStatement stmt -- unknown national focus
Just nnf -> do
let nfKey = nf_id nnf
nfIcon = HM.findWithDefault "GFX_goal_unknown" (nf_icon nnf) gfx
nfIcon = HM.findWithDefault "goal_unknown" (nf_icon nnf) gfx
nf_loc <- getGameL10n nfKey
msgToPP (msg nfIcon nfKey nf_loc)
handleFocus _ stmt = preStatement stmt
Expand Down Expand Up @@ -2028,7 +2028,7 @@ focusUncomplete msg stmt@[pdx| $lhs = @scr |] = do
Nothing -> return $ preMessage stmt -- unknown national focus
Just nnf -> do
let nfKey = nf_id nnf
nfIcon = HM.findWithDefault "GFX_goal_unknown" (nf_icon nnf) gfx
nfIcon = HM.findWithDefault "goal_unknown" (nf_icon nnf) gfx
nf_loc <- getGameL10n nfKey
return $ msg nfIcon nfKey nf_loc (uf_uncomplete_children uf)
focusUncomplete _ stmt = preStatement stmt
Expand Down
2 changes: 1 addition & 1 deletion src/HOI4/NationalFocus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ ppNationalFocus gfx nf = setCurrentFile (nf_path nf) $ do
,"}}"
,PP.line])
(field nf)
icon_pp = HM.findWithDefault "GFX_goal_unknown" (nf_icon nf) gfx
icon_pp = HM.findWithDefault "goal_unknown" (nf_icon nf) gfx
prerequisite_pp <- ppPrereq $ catMaybes $ nf_prerequisite nf
allowBranch_pp <- ppAllowBranch $ nf_allow_branch nf
mutuallyExclusive_pp <- ppMutuallyExclusive $ nf_mutually_exclusive nf
Expand Down
2 changes: 1 addition & 1 deletion src/HOI4/SpecialHandlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ handleIdea addIdea ide = do
Just iidea -> do
let ideaKey = id_id iidea
ideaname = id_name iidea
ideaIcon = HM.findWithDefault "GFX_idea_unknown" (id_picture iidea) gfx
ideaIcon = HM.findWithDefault "idea_unknown" (id_picture iidea) gfx
idea_loc <- getGameL10n ideaname
category <- if id_category iidea == "country" then getGameL10n "FE_COUNTRY_SPIRIT" else getGameL10n $ id_category iidea
effectbox <- modmessage iidea idea_loc ideaKey ideaIcon
Expand Down
20 changes: 10 additions & 10 deletions src/HOI4/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ type HOI4EventTriggers = HashMap Text [HOI4EventSource]
type HOI4DecisionWeight = Maybe (Integer, Integer) -- Rational reduces the number, which we don't want

data HOI4DecisionSource =
HOI4DecSrcImmediate Text -- Immediate effect of an decision (arg is decision ID)
| HOI4DecSrcOption Text Text -- Effect of choosing an decision option (args are decision ID and option ID)
| HOI4DecSrcDecComplete Text Text -- Effect of completing a decision (args are id and localized decision text)
| HOI4DecSrcDecRemove Text Text -- Effect of taking a timed decision and letting it finish (args are id and localized decision text)
| HOI4DecSrcDecCancel Text Text -- Effect of taking a decision and it being canceled (args are id and localized decision text)
| HOI4DecSrcDecTimeout Text Text -- Effect of taking a decision/mission and letting it timeout (args are id and localized decision text)
| HOI4DecSrcOnAction Text HOI4DecisionWeight -- An effect from on_actions (args are the trigger and weight)
| HOI4DecSrcNFComplete Text Text -- Effect of completing a national focus
| HOI4DecSrcNFSelect Text Text -- Effect of selecting a national focus
HOI4DecSrcImmediate Text -- Immediate effect of an decision (arg is decision ID)
| HOI4DecSrcOption Text Text -- Effect of choosing an decision option (args are decision ID and option ID)
| HOI4DecSrcDecComplete Text Text -- Effect of completing a decision (args are id and localized decision text)
| HOI4DecSrcDecRemove Text Text -- Effect of taking a timed decision and letting it finish (args are id and localized decision text)
| HOI4DecSrcDecCancel Text Text -- Effect of taking a decision and it being canceled (args are id and localized decision text)
| HOI4DecSrcDecTimeout Text Text -- Effect of taking a decision/mission and letting it timeout (args are id and localized decision text)
| HOI4DecSrcOnAction Text HOI4DecisionWeight -- An effect from on_actions (args are the trigger and weight)
| HOI4DecSrcNFComplete Text Text Text -- Effect of completing a national focus
| HOI4DecSrcNFSelect Text Text Text -- Effect of selecting a national focus
| HOI4DecSrcIdeaOnAdd Text Text Text Text -- Effect of adding an idea
| HOI4DecSrcIdeaOnRemove Text Text Text Text -- Effect of removing an idea
| HOI4DecSrcCharacterOnAdd Text Text -- Effect of adding an advisor
Expand Down Expand Up @@ -351,7 +351,7 @@ data HOI4Decisioncat = HOI4Decisioncat
{ decc_name :: Text -- ^ Decision category ID
, decc_name_loc :: Maybe Text -- ^ Localized decision category name
, decc_desc_loc :: Maybe Text
, decc_icon :: Maybe Text
, decc_icon :: Text
, decc_picture :: Maybe Text
, decc_custom_icon :: Maybe GenericScript
, decc_visible :: Maybe GenericScript
Expand Down

0 comments on commit 9077dd9

Please sign in to comment.