Skip to content
Snippets Groups Projects
Commit 8fc10996 authored by stuebinm's avatar stuebinm
Browse files

config options: implement script-related options

parent bb5277dc
Branches
No related tags found
No related merge requests found
...@@ -38,6 +38,8 @@ data LintConfig f = LintConfig ...@@ -38,6 +38,8 @@ data LintConfig f = LintConfig
-- ^ Maximum warn level allowed before the lint fails -- ^ Maximum warn level allowed before the lint fails
, configDontCopyAssets :: HKD f Bool , configDontCopyAssets :: HKD f Bool
-- ^ Don't copy map assets (mostly useful for development) -- ^ Don't copy map assets (mostly useful for development)
, configAllowScripts :: HKD f Bool
-- ^ Allow defining custom scripts in maps
} deriving (Generic) } deriving (Generic)
type LintConfig' = LintConfig Identity type LintConfig' = LintConfig Identity
......
...@@ -15,7 +15,7 @@ import Tiled2 (HasProperties (adjustProperties, getProperties), ...@@ -15,7 +15,7 @@ import Tiled2 (HasProperties (adjustProperties, getProperties),
import Util (layerIsEmpty, prettyprint) import Util (layerIsEmpty, prettyprint)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import LintConfig (LintConfig (configAssemblyTag)) import LintConfig (LintConfig (..))
import LintWriter (LintWriter, adjust, askContext, askFileDepth, import LintWriter (LintWriter, adjust, askContext, askFileDepth,
complain, dependsOn, forbid, lintConfig, complain, dependsOn, forbid, lintConfig,
offersEntrypoint, suggest, warn) offersEntrypoint, suggest, warn)
...@@ -62,7 +62,18 @@ checkMap = do ...@@ -62,7 +62,18 @@ checkMap = do
-- longer function same as checkLayerProperty. -- longer function same as checkLayerProperty.
checkMapProperty :: Property -> LintWriter Tiledmap checkMapProperty :: Property -> LintWriter Tiledmap
checkMapProperty (Property name _value) = case name of checkMapProperty (Property name _value) = case name of
"script" -> isForbidden "script" -> do
-- this is kind of stupid, since if we also inject script this
-- will be overriden anyways, but it also doesn't really hurt I guess
-- TODO: perhaps include an explanation in the lint, or allow
-- exactly that one value?
lintConfig configAllowScripts >>= \case
False -> isForbidden
True -> pure ()
lintConfig configScriptInject >>= \case
Nothing -> pure ()
Just url -> setProperty "script" url
_ -> complain $ "unknown map property " <> prettyprint name _ -> complain $ "unknown map property " <> prettyprint name
where where
-- | this property is forbidden and should not be used -- | this property is forbidden and should not be used
......
...@@ -332,6 +332,11 @@ instance HasProperties Tileset where ...@@ -332,6 +332,11 @@ instance HasProperties Tileset where
adjustProperties f tileset = tileset adjustProperties f tileset = tileset
{ tilesetProperties = f (getProperties tileset) } { tilesetProperties = f (getProperties tileset) }
instance HasProperties Tiledmap where
getProperties = fromMaybe [] . tiledmapProperties
adjustProperties f tiledmap = tiledmap
{ tiledmapProperties = f (getProperties tiledmap) }
class HasName a where class HasName a where
getName :: a -> Text getName :: a -> Text
instance HasName Layer where instance HasName Layer where
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment