inooid / react-redux-card-game

A web version of Blizzard's Hearthstone game built with React, Redux and ImmutableJS
MIT License
107 stars 20 forks source link

Datastructure thoughts #13

Open inooid opened 8 years ago

inooid commented 8 years ago

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 commented 8 years ago

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

Bebersohl commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

Cool, let me know when you start working on this again. I would like to contribute.

Brandon

On Fri, Dec 16, 2016 at 11:10 AM, Boyd Dames notifications@github.com wrote:

@Bebersohl https://github.com/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!

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/inooid/react-redux-card-game/issues/13#issuecomment-267643770, or mute the thread https://github.com/notifications/unsubscribe-auth/AG5hhRJ7bct-sxItIqQVfHABrWm1gF10ks5rIsXpgaJpZM4H-SkI .