HopsonCommunity / TextAdventure

A text adventure made by a couple of members on the Hopson Community Server.
MIT License
5 stars 9 forks source link

Set default value of assets::sprites instead of a branch #17

Closed Hazurl closed 6 years ago

Jackojc commented 6 years ago

why not make it a default dict and leave it empty

Hazurl commented 6 years ago

because the key 'sprites' is the only one that store an array

Jackojc commented 6 years ago

it doesnt have to use an array technically. we could do something like:

"hello.png" : {
    "filepath" : "assets/hello.png"
    "pos" : [0, 0],
    "scale" : {
        "type" : "percentage",  # "pixels"
        "scale" : [2, 2]
    }
}
Hazurl commented 6 years ago

I prefer to make an array, as you don't want to collide with background nor music keys, and you probably want to loop through only the sprites...

Jackojc commented 6 years ago

for the love of consistency hazurl

Hazurl commented 6 years ago

so you want :

self.assets = {
    'music' : music_name,
    'bacground' : backgournd_name,
    'tree' :   { 'file' : 'assets/tree.png', 'position' : (10, 10), 'scale' : 2},
    'player' : { 'file' : 'assets/player.png', 'position' : (100, 10), 'scale' : 1},
    'farmer' : { 'file' : 'assets/farmer.png', 'position' : (200, 10), 'scale' : 1}
}

instead of

self.assets = {
    'music' : music_name,
    'bacground' : backgournd_name,
    'sprites' : [ 
        { 'file' : 'assets/tree.png', 'position' : (10, 10), 'scale' : 2},
        { 'file' : 'assets/player.png', 'position' : (100, 10), 'scale' : 1},
        { 'file' : 'assets/farmer.png', 'position' : (200, 10), 'scale' : 1},
    ]
}

?

Jackojc commented 6 years ago

more like:

self.assets = {
    'music' : {
        "ambience" : {"file" : "music/bg1.wav", "loop" : false}
    },

    'bacground' : {
        "bg1" : {"file" : "bg/bg1.jpg", "style" : "stretched"},
        "bg2" : {"file" : "bg/bg2.jpg", "style" : "centered"},
    },

    'sprites' : {
        "tree" : { 'file' : 'assets/tree.png', 'position' : (10, 10), 'scale' : 2},
        "player" : { 'file' : 'assets/player.png', 'position' : (100, 10), 'scale' : 1},
        "farmer" : { 'file' : 'assets/farmer.png', 'position' : (200, 10), 'scale' : 1},
    }
}
Jackojc commented 6 years ago

forgot to clarify but basically, imagine we create some kind of asset manager so that we can cache certain assets instead of unloading and reloading every scene. this is how youd prefetch them then you can just reference them like self.assets.backgrounds["bg1"] anywhere in the game.

Hazurl commented 6 years ago

1) 2 backgrounds ? 2) why a dictionnary on 'music' and 'background', there is only one value for each, atleast that how the json is. 3) if you use the 'file' key in key of your cache you can recover the sprite without loading it every scene. 4) we could use a dictionary in 'sprites' instead of an array, but where do you get that key ? json_doc::assets As you can see the json is an array, all I do is reflect the json.

Hazurl commented 6 years ago

Still a lot to talk about...