Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Datastructure thoughts #13

Open
inooid opened this issue Apr 2, 2016 · 4 comments
Open

Datastructure thoughts #13

inooid opened this issue Apr 2, 2016 · 4 comments

Comments

@inooid
Copy link
Owner

inooid commented Apr 2, 2016

Structure 1:

{
  board: {
    you: [null, null, null, null, null, null, null],
    opponent: [null, null, null, null, null, null, null]
  },
  player: {
    you: {
      name: 'Inooid'
      hero: 'Mage'
      health: 30,
      mana: 1,
      weapon: {
        portait: 'imgurl'
        damage: 2,
        durability: 8,
        callback: fn
      },
      heropower: {
        portait: '',
        mana: 2,
        fireOff: fn
      }
    }
    opponent: {
      name: 'Inooid'
      hero: 'Mage'
      health: 30,
      mana: 1,
      weapon: null,
      heropower: {
        portait: '',
        mana: 2,
        fireOff: fn
      }
    }
  },
  decks: {
    you: [],
    opponent: {
      count: 30
    }
  },
  hand: {
    you: [],
    opponent: []
  },
  history: [],
  turn:
}

Structure 2:

{
  you: {
    player: {
      name: 'Inooid'
      health: 30,
      mana: 1,
      armor: 0,
      damage: 0,
      weapon: null,
      hero: null
    },
    deck: [],
    hand: [],
    board: [null, null, null, null, null, null, null]
  },
  opponent: {
    player: {
      name: 'Kanopi',
      health: 30,
      mana: 1,
      weapon: null,
      hero: {
        heroClass: 'Warlock'
        portrait: ''
        power: {
          mana: 2,
          portrait: 'images/heroes/portraits/warlock.png',
          callback: function() {  }
        }
      }
      heropower: {
        mana: 2,
        portait:
      }
    }
  },
  turn: 'you'
}

My preference goes to structure 2, but if there's any other way of doing it, I am open to suggestions!

@inooid
Copy link
Owner Author

inooid commented Jun 25, 2016

Thanks to Liquidor for this. His thoughts on the state: http://pastebin.com/raw/UA9jgGrH

@Bebersohl
Copy link

@inooid Have you considered trying to normalize the state shape like in the redux docs? The flatter state shape might make it easier to work with.

Something like this:

{
  playersById: {
    'you':{
      id: 'you',
      name: 'Inooid'
      health: 30,
      mana: 1,
      armor: 0,
      damage: 0,
      weapon: weaponId1,
      hero: heroId1
      deck: [cardId, cardId, ...]
      board: [minionId, minionId, ...]
    },
    'opponent':{
      id: 'opponent',
      name: 'Kanopi',
      health: 30,
      mana: 1,
      weapon: weaponId2,
      hero: 'heroId1'
      heropower: 'heropowerId1'
    }
  },
  turn: 'you',
  heroesById: {
    'heroId1':{
      heroClass: 'Warlock'
      portrait: ''
      power: powerId
    },
    'heroId2':{{
      heroClass: 'Warlock'
      portrait: ''
      power: powerId
    }
  },
  weaponsById: {
    ...
  },
  heropowersById: {
    ...
  }
  minionsById: {
    ...
  }
}

@inooid
Copy link
Owner Author

inooid commented Dec 16, 2016

@Bebersohl Thanks for your input! This issue is slightly outdated, but you've touched some valid points. I will reconsider the overall state as soon as I have some more time to work on this. 👍

Appreciate your input a lot!

@Bebersohl
Copy link

Bebersohl commented Dec 16, 2016 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants