Skip to content

Commit 3f2bcb3

Browse files
Update game_states.ex
1 parent 6b42190 commit 3f2bcb3

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

lib/cadet/accounts/game_states.ex

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,29 @@ defmodule Cadet.GameStates do
44
# currently in this module no error handling function
55
# has been implemented yet
66

7-
# simply return the game states of the user
87
def user_game_states(user) do
98
user.game_states
109
end
1110

12-
# simply return the collectibles of the user, within a single map
1311
def user_collectibles(user) do
1412
user.game_states["collectibles"]
1513
end
1614

17-
# simply return the collectibles of the user, within a single map
1815
def user_save_data(user) do
19-
user.game_states["save_data"]
16+
user.game_states["completed_quests"]
2017
end
2118

22-
def update_collectibles(pic_nickname, pic_name, user) do
19+
def update(user, new_game_states) do
2320
changeset =
24-
Ecto.Changeset.cast(user, %{game_states: %{collectibles: Map.put(user_collectibles(user), pic_nickname, pic_name),
25-
save_data: user_save_data(user)}},[:game_states])
26-
Cadet.Repo.update!(changeset)
27-
end
28-
29-
def update_save_data(action_sequence, start_location, user) do
30-
changeset =
31-
Ecto.Changeset.cast(user, %{game_states: %{collectibles: user_collectibles(user),
32-
save_data: %{
33-
action_sequence: action_sequence,
34-
start_location: start_location
35-
}}},[:game_states])
21+
Ecto.Changeset.cast(user, %{game_states:
22+
new_game_states},[:game_states])
3623
Cadet.Repo.update!(changeset)
3724
end
3825

39-
# functions below are for debugging and testing purposes
40-
def clear_up(user) do
26+
def clear(user) do
4127
changeset =
4228
Ecto.Changeset.cast(user, %{game_states: %{collectibles: %{},
43-
save_data: %{action_sequence: [], start_location: ""}}},[:game_states])
44-
Cadet.Repo.update!(changeset)
45-
end
46-
47-
def delete_all_collectibles(user) do
48-
changeset =
49-
Ecto.Changeset.cast(user, %{game_states: %{collectibles: %{}, save_data: user_save_data(user)}},[:game_states])
50-
Cadet.Repo.update!(changeset)
51-
end
52-
53-
def delete_save_data(user) do
54-
changeset =
55-
Ecto.Changeset.cast(user, %{game_states: %{collectibles: user_collectibles(user),
56-
save_data: %{action_sequence: [], start_location: ""}}},[:game_states])
29+
completed_quests: []}},[:game_states])
5730
Cadet.Repo.update!(changeset)
5831
end
59-
6032
end

0 commit comments

Comments
 (0)