Skip to content

Commit 0218305

Browse files
Added few functions regarding game data
1 parent 210cff6 commit 0218305

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

lib/cadet/accounts/game_states.ex

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
defmodule Cadet.GameStates do
22
import Ecto.Repo
33

4+
# currently in this module no error handling function
5+
# has been implemented yet
6+
47
# simply return the game states of the user
58
def user_game_states(user) do
69
user.game_states
@@ -17,41 +20,41 @@ defmodule Cadet.GameStates do
1720
end
1821

1922
def update_collectibles(pic_nickname, pic_name, user) do
20-
# to do
2123
changeset =
2224
Ecto.Changeset.cast(user, %{game_states: %{collectibles: Map.put(user_collectibles(user), pic_nickname, pic_name),
2325
save_data: user_save_data(user)}},[:game_states])
2426
Cadet.Repo.update!(changeset)
25-
# really simple error handling action, to be further implemented
26-
'''
27-
with {:ok, _} <- Repo.update(changeset) do
28-
{:ok, nil}
29-
else
30-
{:error, _} ->
31-
{:error, {:internal_server_error, "Please try again later."}}
32-
end
33-
'''
34-
end
35-
36-
# should be idle since we are not going to delete students' collectibles
37-
# but provide the function delete_collectibles here for future extension
38-
def delete_all_collectibles(user) do
27+
end
28+
29+
def update_save_data(action_sequence, start_location, user) do
3930
changeset =
40-
Ecto.Changeset.cast(user, %{game_states: %{collectibles: %{}, save_data: user_save_data(user)}},[:game_states])
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])
4136
Cadet.Repo.update!(changeset)
4237
end
4338

44-
'''
45-
# to implement when needed
46-
47-
def update_save_data() do
48-
... # to do the actual implementation
39+
# functions below are for debugging and testing purposes
40+
def clear_up(user) do
41+
changeset =
42+
Ecto.Changeset.cast(user, %{game_states: %{collectibles: %{},
43+
save_data: %{action_sequence: [], start_location: ""}}},[:game_states])
44+
Cadet.Repo.update!(changeset)
4945
end
5046

51-
def delete_all_save_data() do
52-
... # to do the actual implementation
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)
5351
end
5452

55-
'''
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])
57+
Cadet.Repo.update!(changeset)
58+
end
5659

5760
end

0 commit comments

Comments
 (0)