Skip to content

Commit

Permalink
Rename Property constructors (fix #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
justgook committed Jan 22, 2020
1 parent a5f7564 commit 2f1f27a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
56 changes: 28 additions & 28 deletions src/Tiled/Extra/Property.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import Tiled.Properties
{-| Custom nested properties
-}
type Property
= PropBool Bool
| PropInt Int
| PropFloat Float
| PropString String
| PropColor String
| PropFile String
| PropCollection (Dict String Property)
= Bool Bool
| Int Int
| Float Float
| String String
| Color String
| File String
| Group (Dict String Property)


{-| Convert [`Tiled.Properties`](Tiled-Properties#Properties) to [`Tiled.Extra.Property`](Tiled-Extra-Property#Property) all properties that have `name.subName` or `name[subName]` is grouped as `PropCollection` with nested properties of `subName`.
{-| Convert [`Tiled.Properties`](Tiled-Properties#Properties) to [`Tiled.Extra.Property`](Tiled-Extra-Property#Property) all properties that have `name.subName` or `name[subName]` is grouped as `Group` with nested properties of `subName`.
Example:
Expand Down Expand Up @@ -72,7 +72,7 @@ get k prop =
at : List String -> Property -> Maybe Property
at path prop =
case ( path, prop ) of
( k :: rest, PropCollection dict ) ->
( k :: rest, Group dict ) ->
Dict.get k dict
|> Maybe.andThen (at rest)

Expand All @@ -83,24 +83,24 @@ at path prop =
Nothing


{-| Convert `PropCollection` to `List` of its values, or get list of single `Property`
{-| Convert `Group` to `List` of its values, or get list of single `Property`
-}
values : Property -> List Property
values property =
case property of
PropCollection dict ->
Group dict ->
Dict.values dict

p ->
[ p ]


{-| Convert `PropCollection` to List of key-value pairs
{-| Convert `Group` to List of key-value pairs
-}
toList : Property -> List ( String, Property )
toList property =
case property of
PropCollection dict ->
Group dict ->
Dict.toList dict

p ->
Expand All @@ -114,7 +114,7 @@ digIn acc list =
digIn (updateCrumbsInt (keyToPath key) value acc) rest

[] ->
PropCollection acc
Group acc


keyToPath : String -> List String
Expand All @@ -139,34 +139,34 @@ updateCrumbsInt path val props =
let
oldProps =
case Dict.get x props of
Just (PropCollection currentProps) ->
Just (Group currentProps) ->
currentProps

_ ->
Dict.empty
in
Dict.insert x (PropCollection (updateCrumbsInt xs val oldProps)) props
Dict.insert x (Group (updateCrumbsInt xs val oldProps)) props


prop2Prop v_ =
case v_ of
Tiled.Properties.PropBool v ->
PropBool v
Tiled.Properties.Bool v ->
Bool v

Tiled.Properties.PropInt v ->
PropInt v
Tiled.Properties.Int v ->
Int v

Tiled.Properties.PropFloat v ->
PropFloat v
Tiled.Properties.Float v ->
Float v

Tiled.Properties.PropString v ->
PropString v
Tiled.Properties.String v ->
String v

Tiled.Properties.PropColor v ->
PropColor v
Tiled.Properties.Color v ->
Color v

Tiled.Properties.PropFile v ->
PropFile v
Tiled.Properties.File v ->
File v


{-| -}
Expand Down
36 changes: 18 additions & 18 deletions src/Tiled/Properties.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ type alias Properties =
{-| Custom properties values
-}
type Property
= PropBool Bool
| PropInt Int
| PropFloat Float
| PropString String
| PropColor String
| PropFile String
= Bool Bool
| Int Int
| Float Float
| String String
| Color String
| File String


{-| -}
Expand Down Expand Up @@ -58,22 +58,22 @@ encode props =
Encode.object
(( "name", Encode.string key )
:: (case value of
PropBool v ->
Bool v ->
[ ( "type", Encode.string "bool" ), ( "value", Encode.bool v ) ]

PropInt v ->
Int v ->
[ ( "type", Encode.string "int" ), ( "value", Encode.int v ) ]

PropFloat v ->
Float v ->
[ ( "type", Encode.string "float" ), ( "value", Encode.float v ) ]

PropString v ->
String v ->
[ ( "type", Encode.string "string" ), ( "value", Encode.string v ) ]

PropColor v ->
Color v ->
[ ( "type", Encode.string "color" ), ( "value", Encode.string v ) ]

PropFile v ->
File v ->
[ ( "type", Encode.string "file" ), ( "value", Encode.string v ) ]
)
)
Expand All @@ -85,22 +85,22 @@ decodeProperty : String -> Decoder Property
decodeProperty typeString =
case typeString of
"bool" ->
Decode.map PropBool Decode.bool
Decode.map Bool Decode.bool

"color" ->
Decode.map PropColor Decode.string
Decode.map Color Decode.string

"float" ->
Decode.map PropFloat Decode.float
Decode.map Float Decode.float

"file" ->
Decode.map PropFile Decode.string
Decode.map File Decode.string

"int" ->
Decode.map PropInt Decode.int
Decode.map Int Decode.int

"string" ->
Decode.map PropString Decode.string
Decode.map String Decode.string

_ ->
Decode.fail <| "I can't decode the type " ++ typeString
12 changes: 6 additions & 6 deletions tests/Generate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ layer =
property : Fuzzer Property
property =
Fuzz.oneOf
[ Fuzz.map PropBool Fuzz.bool
, Fuzz.map PropInt Fuzz.int
, Fuzz.map PropFloat Fuzz.float
, Fuzz.map PropString Fuzz.string
, Fuzz.map PropColor Fuzz.string
, Fuzz.map PropFile Fuzz.string
[ Fuzz.map Bool Fuzz.bool
, Fuzz.map Int Fuzz.int
, Fuzz.map Float Fuzz.float
, Fuzz.map String Fuzz.string
, Fuzz.map Color Fuzz.string
, Fuzz.map File Fuzz.string
]


Expand Down

0 comments on commit 2f1f27a

Please sign in to comment.