Compare commits
9 Commits
master
...
persistanc
Author | SHA1 | Date |
---|---|---|
|
70564b5f03 | 2 years ago |
|
e60ed56936 | 2 years ago |
|
0b20d7745c | 2 years ago |
|
e1f661f44d | 2 years ago |
|
7186a5e76b | 2 years ago |
|
b228d1b486 | 2 years ago |
|
0d5ffbb323 | 2 years ago |
|
7514a5168d | 2 years ago |
|
e0db3f5eb9 | 2 years ago |
Before Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 44 KiB |
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AutoImportSettings">
|
||||||
|
<option name="autoReloadType" value="NONE" />
|
||||||
|
</component>
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="c1d3a00b-b752-49c3-9cf2-bbd65379556a" name="Changes" comment="" />
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectId" id="2N679bs9cUF2LZx6uhUfUbDiBup" />
|
||||||
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"RunOnceActivity.cidr.known.project.marker": "true",
|
||||||
|
"cidr.known.project.marker": "true",
|
||||||
|
"last_opened_file_path": "D:/ShakeAndCraft/ShakeAndCraft/ShakeAndCraft"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="c1d3a00b-b752-49c3-9cf2-bbd65379556a" name="Changes" comment="" />
|
||||||
|
<created>1678972527401</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1678972527401</updated>
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,62 +0,0 @@
|
|||||||
package com.example.shakecraft
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.fragment.app.activityViewModels
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import com.example.shakecraft.model.Tool
|
|
||||||
import com.example.shakecraft.view.adapter.AdapterInventory
|
|
||||||
import com.example.shakecraft.viewmodel.MainViewModel
|
|
||||||
|
|
||||||
|
|
||||||
class InventoryFragment() : Fragment( ), AdapterInventory.OnItemLongClickListener {
|
|
||||||
private lateinit var recyclerView: RecyclerView
|
|
||||||
val viewModel : MainViewModel by activityViewModels<MainViewModel>()
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemLongClick(position: Int) {
|
|
||||||
if (viewModel.currentPlayer.value!!.items[position] is Tool) {
|
|
||||||
val text = if (viewModel.equipeItem(viewModel.currentPlayer.value!!.items[position]) ) " was well equipped" else " has been well unequipped"
|
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
viewModel.currentPlayer.value!!.items[position].type.name + text,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
setUpRecyclerView(view?.parent as ViewGroup, this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
override fun onCreateView(
|
|
||||||
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
|
||||||
savedInstanceState: Bundle?
|
|
||||||
): View? {
|
|
||||||
val view = inflater.inflate(R.layout.fragment_inventory, container, false)
|
|
||||||
|
|
||||||
// Initialize views
|
|
||||||
setUpRecyclerView(view, this)
|
|
||||||
|
|
||||||
return view
|
|
||||||
}
|
|
||||||
private fun setUpRecyclerView(view: View,listener: AdapterInventory.OnItemLongClickListener ) {
|
|
||||||
recyclerView = view.findViewById(R.id.recyclerviewInventory)
|
|
||||||
with(recyclerView) {
|
|
||||||
layoutManager = LinearLayoutManager(view.context)
|
|
||||||
adapter = viewModel.currentPlayer.value?.let {
|
|
||||||
AdapterInventory(viewModel.currentPlayer.value!!.items, listener ,
|
|
||||||
it
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.shakecraft
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import com.example.shakecraft.data.DataBase
|
||||||
|
|
||||||
|
class PlayerApplication: Application(){
|
||||||
|
val database: DataBase by lazy { DataBase.getInstance(this) }
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.example.shakecraft
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.asLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.example.shakecraft.data.PlayerDao
|
||||||
|
import com.example.shakecraft.model.Player
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class PlayerViewModel(private val playerDao: PlayerDao): ViewModel() {
|
||||||
|
val player:LiveData<Player> = playerDao.getPlayer()
|
||||||
|
.asLiveData()
|
||||||
|
fun updatePlayer(
|
||||||
|
Id: Int,
|
||||||
|
pseudo: String,
|
||||||
|
level: Int,
|
||||||
|
xp: Int,
|
||||||
|
image: Int,
|
||||||
|
rank: String,
|
||||||
|
){
|
||||||
|
val updatePlayer= getUpdatePlayerEntry(Id, pseudo, level, xp, image, rank)
|
||||||
|
updatePlayer(updatePlayer)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updatePlayer(player: Player) {
|
||||||
|
viewModelScope.launch{
|
||||||
|
playerDao.update(player)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getUpdatePlayerEntry(
|
||||||
|
Id: Int,
|
||||||
|
pseudo: String,
|
||||||
|
level: Int,
|
||||||
|
xp: Int,
|
||||||
|
image: Int,
|
||||||
|
rank: String,
|
||||||
|
): Player {
|
||||||
|
return Player(
|
||||||
|
id= Id,
|
||||||
|
pseudo= pseudo,
|
||||||
|
level= level,
|
||||||
|
xp= xp,
|
||||||
|
image= image,
|
||||||
|
rank= rank,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlayerViewModelFactory(private val playerDao: PlayerDao): ViewModelProvider.Factory{
|
||||||
|
fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
|
if (modelClass.isAssignableFrom(PlayerViewModel::class.java)){
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return PlayerViewModel(playerDao) as T
|
||||||
|
}
|
||||||
|
throw IllegalArgumentException("Unknown ViewModel class")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.example.shakecraft.data
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import com.example.shakecraft.model.Player
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
@Database(entities = [Player::class],version = 1)
|
||||||
|
abstract class DataBase: RoomDatabase() {
|
||||||
|
abstract fun playerDao(): PlayerDao
|
||||||
|
|
||||||
|
companion object{
|
||||||
|
private var INSTANCE : DataBase? = null
|
||||||
|
fun getInstance(context: Context): DataBase{
|
||||||
|
return INSTANCE ?: synchronized(this){
|
||||||
|
val instance = Room.databaseBuilder(
|
||||||
|
context.applicationContext,
|
||||||
|
DataBase::class.java,
|
||||||
|
"player_database"
|
||||||
|
)
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
|
.build()
|
||||||
|
INSTANCE = instance
|
||||||
|
instance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.example.shakecraft.data
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.example.shakecraft.model.Player
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface PlayerDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Player")
|
||||||
|
fun getPlayer(): Flow<Player>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(player: Player)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
suspend fun update(player: Player)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun delete(player: Player)
|
||||||
|
}
|
@ -1,19 +0,0 @@
|
|||||||
package com.example.shakecraft.data
|
|
||||||
|
|
||||||
data class WeatherResponse(
|
|
||||||
val weather: List<Weather>,
|
|
||||||
val info: Info
|
|
||||||
)
|
|
||||||
|
|
||||||
data class Weather(
|
|
||||||
val id: Int,
|
|
||||||
val main: String,
|
|
||||||
val description: String,
|
|
||||||
val icon: String
|
|
||||||
)
|
|
||||||
|
|
||||||
data class Info(
|
|
||||||
val temp: Double,
|
|
||||||
val feelsLike: Double,
|
|
||||||
val humidity: Int
|
|
||||||
)
|
|
@ -1,15 +0,0 @@
|
|||||||
package com.example.shakecraft.data.dao
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.example.shakecraft.model.Item
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface ItemDao {
|
|
||||||
@Query("SELECT * FROM item")
|
|
||||||
suspend fun getAllItems(): List<Item>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun insertItem(item: Item)
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.example.shakecraft.data.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.example.shakecraft.model.Player
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface PlayerDao {
|
|
||||||
@Query("SELECT * FROM player")
|
|
||||||
suspend fun getAllPlayers(): List<Player>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun insertPlayer(player: Player)
|
|
||||||
}
|
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.example.shakecraft.fragment
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.example.shakecraft.MainActivity
|
||||||
|
import com.example.shakecraft.R
|
||||||
|
import com.example.shakecraft.model.Player
|
||||||
|
import com.example.shakecraft.view.adapter.AdapterInventory
|
||||||
|
|
||||||
|
|
||||||
|
class InventoryFragment() : Fragment( ) {
|
||||||
|
|
||||||
|
private lateinit var recyclerView: RecyclerView
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
}
|
||||||
|
override fun onCreateView(
|
||||||
|
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
val currentPlayer = (activity as MainActivity).currentPlayer
|
||||||
|
val view = inflater.inflate(R.layout.fragment_inventory, container, false)
|
||||||
|
|
||||||
|
// Initialize views
|
||||||
|
setUpRecyclerView(view, currentPlayer)
|
||||||
|
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
private fun setUpRecyclerView(view: View, currentPlayer: Player) {
|
||||||
|
recyclerView = view.findViewById(R.id.recyclerviewInventory)
|
||||||
|
with(recyclerView) {
|
||||||
|
layoutManager = LinearLayoutManager(view.context)
|
||||||
|
adapter = AdapterInventory(currentPlayer.inventory.items)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,19 @@
|
|||||||
package com.example.shakecraft.model
|
package com.example.shakecraft.model
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
class Boss (
|
data class Boss (
|
||||||
var name: String,
|
var name: String,
|
||||||
var life: Double,
|
var life: Int,
|
||||||
var maxlife: Int,
|
var maxlife: Int,
|
||||||
var image: Int,
|
var image: Int,
|
||||||
var xpReward: Int,
|
var xpReward: Int,
|
||||||
val possibleLoot: List<Pair<Item, Double>>,
|
val possibleLoot: List<Pair<Item, Double>>,
|
||||||
){
|
){
|
||||||
|
|
||||||
fun takeDamage(strength: Double) {
|
fun takeDamage(strength: Int) {
|
||||||
this.life -= strength
|
this.life -= strength
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,31 +1,35 @@
|
|||||||
package com.example.shakecraft.model
|
package com.example.shakecraft.model
|
||||||
import com.example.shakecraft.R
|
import com.example.shakecraft.R
|
||||||
|
|
||||||
|
class ItemManager {
|
||||||
|
companion object {
|
||||||
|
enum class ITEMS(val itemtype: ItemType){
|
||||||
|
|
||||||
enum class ITEMS(val itemtype: ItemType){
|
// Craftable items and resources
|
||||||
|
BEECH_LOG(ItemType(name = "Beech Log", image = R.drawable.log2, rarity = 1, xpReward = 10)),
|
||||||
|
WOODEN_STICK(ItemType(name = "Wooden Stick", image = R.drawable.wooden_stick, rarity = 1, xpReward = 0)),
|
||||||
|
WOODEN_PLANK(ItemType(name = "Wooden Plank", image = R.drawable.wooden_plank, rarity = 1, xpReward = 0)),
|
||||||
|
WOODEN_BALL(ItemType(name = "Wooden Ball", image = R.drawable.wooden_ball, rarity = 1, xpReward = 0)),
|
||||||
|
WIZARD_STAFF(ItemType(name = "Wizard Staff", image = R.drawable.wizard_staff, rarity = 3, xpReward = 0)),
|
||||||
|
|
||||||
// Craftable items and resources
|
DIAMOND(ItemType(name = "Diamond", image = R.drawable.diamond, rarity = 3, xpReward = 30)),
|
||||||
BEECH_LOG(ItemType(name = "Beech Log", image = R.drawable.log2, rarity = 1, xpReward = 10)),
|
DIAMOND_AXE(ItemType(name = "Diamond Axe", image = R.drawable.diamond_axe, rarity = 3, xpReward = 0)),
|
||||||
WOODEN_STICK(ItemType(name = "Wooden Stick", image = R.drawable.wooden_stick, rarity = 1, xpReward = 0)),
|
|
||||||
WOODEN_PLANK(ItemType(name = "Wooden Plank", image = R.drawable.wooden_plank, rarity = 1, xpReward = 0)),
|
|
||||||
WOODEN_BALL(ItemType(name = "Wooden Ball", image = R.drawable.wooden_ball, rarity = 1, xpReward = 0)),
|
|
||||||
WIZARD_STAFF(ItemType(name = "Wizard Staff", image = R.drawable.wizard_staff, rarity = 3, xpReward = 0)),
|
|
||||||
|
|
||||||
DIAMOND(ItemType(name = "Diamond", image = R.drawable.diamond, rarity = 3, xpReward = 30)),
|
BRONZE_ORE(ItemType(name = "Bronze Ore", image = R.drawable.bronze_ore, rarity = 2, xpReward = 20)),
|
||||||
DIAMOND_AXE(ItemType(name = "Diamond Axe", image = R.drawable.diamond_axe, rarity = 3, xpReward = 0)),
|
BRONZE_INGOT(ItemType(name = "Bronze Ingot", image = R.drawable.bronze_ingot, rarity = 1, xpReward = 0)),
|
||||||
|
BRONZE_SWORD(ItemType(name = "Bronze Sword", image = R.drawable.bronze_sword, rarity = 2, xpReward = 0)),
|
||||||
|
|
||||||
BRONZE_ORE(ItemType(name = "Bronze Ore", image = R.drawable.bronze_ore, rarity = 2, xpReward = 20)),
|
IRON_ORE(ItemType(name = "Iron Ore", image = R.drawable.iron_ore, rarity = 2, xpReward = 25)),
|
||||||
BRONZE_INGOT(ItemType(name = "Bronze Ingot", image = R.drawable.bronze_ingot, rarity = 1, xpReward = 0)),
|
IRON_INGOT(ItemType(name = "Iron Ingot", image = R.drawable.iron_ingot, rarity = 1, xpReward = 0)),
|
||||||
BRONZE_SWORD(ItemType(name = "Bronze Sword", image = R.drawable.bronze_sword, rarity = 2, xpReward = 0)),
|
OPEN_TREASURE(ItemType(name = "Open Treasure", image = R.drawable.open_treasure, rarity = 3, xpReward = 50)),
|
||||||
|
|
||||||
IRON_ORE(ItemType(name = "Iron Ore", image = R.drawable.iron_ore, rarity = 2, xpReward = 25)),
|
|
||||||
IRON_INGOT(ItemType(name = "Iron Ingot", image = R.drawable.iron_ingot, rarity = 1, xpReward = 0)),
|
|
||||||
|
|
||||||
|
|
||||||
// Lootable items
|
|
||||||
MONSTER_BONES(ItemType(name = "Monster Bones", image = R.drawable.monster_bones, rarity = 1, xpReward = 10)),
|
|
||||||
MONSTER_EYE(ItemType(name = "Monster Eye", image = R.drawable.monster_eyes, rarity = 2, xpReward = 20)),
|
|
||||||
TREASURE_KEY(ItemType(name = "Treasure Key", image = R.drawable.treasure_key, rarity = 2, xpReward = 20)),
|
|
||||||
|
|
||||||
|
// Lootable items
|
||||||
|
MONSTER_BONES(ItemType(name = "Monster Bones", image = R.drawable.monster_bones, rarity = 1, xpReward = 10)),
|
||||||
|
MONSTER_EYE(ItemType(name = "Monster Eye", image = R.drawable.monster_eyes, rarity = 2, xpReward = 20)),
|
||||||
|
TREASURE_KEY(ItemType(name = "Treasure Key", image = R.drawable.treasure_key, rarity = 2, xpReward = 20)),
|
||||||
|
TREASURE(ItemType(name = "Treasure", image = R.drawable.treasure, rarity = 3, xpReward = 20)),
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.example.shakecraft.model
|
package com.example.shakecraft.model
|
||||||
|
|
||||||
class ItemType (val name : String,val image : Int,val rarity : Int, val xpReward : Int){
|
|
||||||
|
|
||||||
|
class ItemType (val name : String,val image : Int,val rarity : Int, val xpReward : Int){
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +0,0 @@
|
|||||||
package com.example.shakecraft.model
|
|
||||||
|
|
||||||
class Tool(type : ItemType, stack: Int,val damage : Int) : Item(type, stack) {
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.example.shakecraft.services
|
|
||||||
import com.example.shakecraft.data.WeatherResponse
|
|
||||||
import retrofit2.http.GET
|
|
||||||
import retrofit2.http.Query
|
|
||||||
|
|
||||||
interface OpenWeatherMapService {
|
|
||||||
@GET("weather")
|
|
||||||
suspend fun getCurrentWeather(
|
|
||||||
@Query("q") cityName: String,
|
|
||||||
@Query("appid") apiKey: String
|
|
||||||
): WeatherResponse
|
|
||||||
}
|
|
@ -0,0 +1,3 @@
|
|||||||
|
package com.example.shakecraft.view.viewholder
|
||||||
|
class ViewHolderInventory(inflate: Any?) {
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
package com.example.shakecraft.viewmodel
|
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import com.example.shakecraft.data.Stub
|
|
||||||
import com.example.shakecraft.model.Boss
|
|
||||||
import com.example.shakecraft.model.Item
|
|
||||||
import com.example.shakecraft.model.Recipe
|
|
||||||
|
|
||||||
class MainViewModel : ViewModel() {
|
|
||||||
|
|
||||||
var currentPlayer = MutableLiveData(Stub().load())
|
|
||||||
|
|
||||||
|
|
||||||
lateinit var currentBoss : Boss
|
|
||||||
val isBossInitialized get() = this::currentBoss.isInitialized
|
|
||||||
|
|
||||||
fun craft(recipe : Recipe, count : Int = 1){
|
|
||||||
currentPlayer.value?.craft(recipe, count)
|
|
||||||
this.currentPlayer.value = currentPlayer.value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addItem(item: Item) {
|
|
||||||
currentPlayer.value?.addItem(item)
|
|
||||||
this.currentPlayer.value = currentPlayer.value
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun gainXp(xpReward: Int) {
|
|
||||||
currentPlayer.value?.gainXp(xpReward)
|
|
||||||
this.currentPlayer.value = currentPlayer.value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun equipeItem(item: Item): Boolean {
|
|
||||||
currentPlayer.value?.equipeItem(item)
|
|
||||||
this.currentPlayer.value = currentPlayer.value
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
Before Width: | Height: | Size: 639 B |
Before Width: | Height: | Size: 929 B |
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<solid android:color="@color/black_800"/>
|
|
||||||
<corners
|
|
||||||
android:topLeftRadius="5dp"
|
|
||||||
android:topRightRadius="5dp"
|
|
||||||
android:bottomLeftRadius="5dp"
|
|
||||||
android:bottomRightRadius="5dp"/>
|
|
||||||
<stroke android:width="1dp"
|
|
||||||
android:color="@color/grey_100" />
|
|
||||||
</shape>
|
|
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 79 KiB |
@ -1,450 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@color/black_800"
|
|
||||||
tools:context=".MainActivity">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView2"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:paddingBottom="10dp"
|
|
||||||
android:text="@string/home_title"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:id="@+id/constraintLayout"
|
|
||||||
android:layout_width="250dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="15dp"
|
|
||||||
android:background="@drawable/rounded_border_button"
|
|
||||||
android:paddingLeft="15dp"
|
|
||||||
android:paddingRight="15dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView2">
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/profil_container"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent">
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginVertical="10dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/imageView2"
|
|
||||||
android:layout_width="60dp"
|
|
||||||
android:layout_height="95dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:contentDescription="@string/landscape"
|
|
||||||
android:src="@drawable/background" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/playerImage"
|
|
||||||
android:layout_width="50dp"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:contentDescription="Landscape" />
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="15dp"
|
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/pseudoEditText"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Pseudo"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView6"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Lvl."
|
|
||||||
android:textColor="@color/grey_300" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/levelTextView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="2"
|
|
||||||
android:textColor="@color/grey_300" />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/levelProgressBar"
|
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="5dp"
|
|
||||||
android:layout_marginHorizontal="10dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:max="100"
|
|
||||||
android:progress="20"
|
|
||||||
android:progressDrawable="@drawable/custom_level_progressbar" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/xpTextView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="349"
|
|
||||||
android:textColor="@color/white" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView7"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="/"
|
|
||||||
android:textColor="@color/white" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/maxXpTextView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textColor="@color/white" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView6"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingRight="10dp"
|
|
||||||
android:text="Rank"
|
|
||||||
android:textColor="@color/grey_300" />
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/rankTextView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Beginner"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
</LinearLayout>
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:paddingBottom="15dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/profil_container"
|
|
||||||
tools:layout_editor_absoluteX="15dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/equipedItemAttack"
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="30dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:background="@drawable/background_equiped_item"
|
|
||||||
android:contentDescription="Landscape"
|
|
||||||
android:tooltipText="Equiped Weapon" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/equipedItemFishing"
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="30dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:background="@drawable/background_equiped_item"
|
|
||||||
android:contentDescription="Landscape"
|
|
||||||
android:tooltipText="Equiped Fishing Rod" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/equipedItemCollect"
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="30dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:background="@drawable/background_equiped_item"
|
|
||||||
android:contentDescription="Landscape"
|
|
||||||
android:tooltipText="Equiped Tool" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/equipedItemArmor"
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="30dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:background="@drawable/background_equiped_item"
|
|
||||||
android:contentDescription="Landscape"
|
|
||||||
android:tooltipText="Equiped Armor" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:id="@+id/scroll_activties"
|
|
||||||
android:layout_width="220dp"
|
|
||||||
android:layout_height="200dp"
|
|
||||||
android:layout_marginStart="20dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/constraintLayout"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView2">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:id="@+id/buttonForge"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:layout_marginHorizontal="15dp"
|
|
||||||
android:layout_marginVertical="10dp"
|
|
||||||
android:background="@drawable/rounded_border_button"
|
|
||||||
android:clickable="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/constraintLayout">
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/imageView2"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="50dp"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:src="@drawable/ic_anvil" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView4"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Ancient Forge"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView5"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Craft ever more powerful tools."
|
|
||||||
android:textColor="@color/grey_300"
|
|
||||||
android:textSize="11sp" />
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:id="@+id/buttonCollect"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:layout_marginHorizontal="15dp"
|
|
||||||
android:layout_marginVertical="10dp"
|
|
||||||
android:background="@drawable/rounded_border_button"
|
|
||||||
android:clickable="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/buttonForge">
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/imageView2"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:src="@drawable/ic_tree" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView4"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Pleasant Forest"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView5"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Collect ressources to became powerfull."
|
|
||||||
android:textColor="@color/grey_300"
|
|
||||||
android:textSize="11sp" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:id="@+id/buttonBoss"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:layout_marginHorizontal="15dp"
|
|
||||||
android:layout_marginVertical="10dp"
|
|
||||||
android:background="@drawable/rounded_border_button"
|
|
||||||
android:clickable="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/buttonCollect">
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/imageView2"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:src="@drawable/ic_key" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView4"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Dungeon"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView5"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Defeat boss to gain Mystic rewards."
|
|
||||||
android:textColor="@color/grey_300"
|
|
||||||
android:textSize="11sp" />
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/event_container"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="200dp"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingBottom="20dp"
|
|
||||||
android:visibility="visible"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/scroll_activties"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView2">
|
|
||||||
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/event_message"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:clickable="true"
|
|
||||||
android:maxWidth="200dip"
|
|
||||||
android:scaleType="centerCrop"
|
|
||||||
android:src="@drawable/event_message"
|
|
||||||
android:visibility="visible">
|
|
||||||
|
|
||||||
|
|
||||||
</ImageView>
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/buttonFishing"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:clickable="true"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:maxWidth="200dip"
|
|
||||||
android:scaleType="centerCrop"
|
|
||||||
android:src="@drawable/fishing_event">
|
|
||||||
|
|
||||||
|
|
||||||
</ImageView>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
Loading…
Reference in new issue