• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.replica.replicaisland;
18 
19 public class InventoryComponent extends GameComponent {
20     private UpdateRecord mInventory;
21     private boolean mInventoryChanged;
22 
InventoryComponent()23     public InventoryComponent() {
24         super();
25         mInventory = new UpdateRecord();
26         reset();
27         setPhase(ComponentPhases.FRAME_END.ordinal());
28     }
29 
30     @Override
reset()31     public void reset() {
32         mInventoryChanged = true;
33         mInventory.reset();
34     }
35 
applyUpdate(UpdateRecord record)36     public void applyUpdate(UpdateRecord record) {
37         mInventory.add(record);
38         mInventoryChanged = true;
39     }
40 
41     @Override
update(float timeDelta, BaseObject parent)42     public void update(float timeDelta, BaseObject parent) {
43         if (mInventoryChanged) {
44             HudSystem hud = sSystemRegistry.hudSystem;
45             if (hud != null) {
46                 hud.updateInventory(mInventory);
47             }
48             mInventoryChanged = false;
49         }
50     }
51 
getRecord()52     public UpdateRecord getRecord() {
53         return mInventory;
54     }
55 
setChanged()56     public void setChanged() {
57         mInventoryChanged = true;
58     }
59 
60     public static class UpdateRecord extends BaseObject {
61         public int rubyCount;
62         public int coinCount;
63         public int diaryCount;
64 
UpdateRecord()65         public UpdateRecord() {
66             super();
67         }
68 
reset()69         public void reset() {
70             rubyCount = 0;
71             coinCount = 0;
72             diaryCount = 0;
73         }
74 
add(UpdateRecord other)75         public void add(UpdateRecord other) {
76             rubyCount += other.rubyCount;
77             coinCount += other.coinCount;
78             diaryCount += other.diaryCount;
79         }
80     }
81 }
82