Compare commits
2 Commits
a61c721a2c
...
52b66eed97
| Author | SHA1 | Date | |
|---|---|---|---|
| 52b66eed97 | |||
| 2032473b26 |
237
main.js
237
main.js
@@ -5334,9 +5334,9 @@ var $elm$core$Task$perform = F2(
|
|||||||
A2($elm$core$Task$map, toMessage, task)));
|
A2($elm$core$Task$map, toMessage, task)));
|
||||||
});
|
});
|
||||||
var $elm$browser$Browser$application = _Browser_application;
|
var $elm$browser$Browser$application = _Browser_application;
|
||||||
var $author$project$Main$Model = F5(
|
var $author$project$Main$Model = F7(
|
||||||
function (state, player, loot, groupLoot, merchantItems) {
|
function (state, player, claims, notification, loot, groupLoot, merchantItems) {
|
||||||
return {groupLoot: groupLoot, loot: loot, merchantItems: merchantItems, player: player, state: state};
|
return {claims: claims, groupLoot: groupLoot, loot: loot, merchantItems: merchantItems, notification: notification, player: player, state: state};
|
||||||
});
|
});
|
||||||
var $author$project$Main$PlayerChest = {$: 'PlayerChest'};
|
var $author$project$Main$PlayerChest = {$: 'PlayerChest'};
|
||||||
var $author$project$Main$State = F6(
|
var $author$project$Main$State = F6(
|
||||||
@@ -6186,6 +6186,31 @@ var $author$project$Main$fetchShopInventory = $elm$http$Http$get(
|
|||||||
$author$project$Main$valueDecoder($author$project$Main$lootDecoder)),
|
$author$project$Main$valueDecoder($author$project$Main$lootDecoder)),
|
||||||
url: 'http://localhost:8088/api/items'
|
url: 'http://localhost:8088/api/items'
|
||||||
});
|
});
|
||||||
|
var $author$project$Main$GotClaims = F2(
|
||||||
|
function (a, b) {
|
||||||
|
return {$: 'GotClaims', a: a, b: b};
|
||||||
|
});
|
||||||
|
var $author$project$Main$Claim = F3(
|
||||||
|
function (id, player_id, loot_id) {
|
||||||
|
return {id: id, loot_id: loot_id, player_id: player_id};
|
||||||
|
});
|
||||||
|
var $author$project$Main$claimDecoder = A4(
|
||||||
|
$elm$json$Json$Decode$map3,
|
||||||
|
$author$project$Main$Claim,
|
||||||
|
A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int),
|
||||||
|
A2($elm$json$Json$Decode$field, 'player_id', $elm$json$Json$Decode$int),
|
||||||
|
A2($elm$json$Json$Decode$field, 'loot_id', $elm$json$Json$Decode$int));
|
||||||
|
var $author$project$Main$fetchClaims = function (playerId) {
|
||||||
|
return $elm$http$Http$get(
|
||||||
|
{
|
||||||
|
expect: A2(
|
||||||
|
$elm$http$Http$expectJson,
|
||||||
|
$author$project$Main$GotClaims(playerId),
|
||||||
|
$author$project$Main$valueDecoder(
|
||||||
|
$elm$json$Json$Decode$list($author$project$Main$claimDecoder))),
|
||||||
|
url: 'http://localhost:8088/api/claims'
|
||||||
|
});
|
||||||
|
};
|
||||||
var $author$project$Main$OfPlayer = {$: 'OfPlayer'};
|
var $author$project$Main$OfPlayer = {$: 'OfPlayer'};
|
||||||
var $author$project$Main$fetchLoot = function (id) {
|
var $author$project$Main$fetchLoot = function (id) {
|
||||||
return $elm$http$Http$get(
|
return $elm$http$Http$get(
|
||||||
@@ -6230,7 +6255,8 @@ var $author$project$Main$initPlayer = function (id) {
|
|||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
$author$project$Main$fetchPlayer(id),
|
$author$project$Main$fetchPlayer(id),
|
||||||
$author$project$Main$fetchLoot(id)
|
$author$project$Main$fetchLoot(id),
|
||||||
|
$author$project$Main$fetchClaims(id)
|
||||||
]));
|
]));
|
||||||
};
|
};
|
||||||
var $author$project$Main$fetchInitialData = function (playerId) {
|
var $author$project$Main$fetchInitialData = function (playerId) {
|
||||||
@@ -6487,10 +6513,12 @@ var $author$project$Main$init = F3(
|
|||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
return _Utils_Tuple2(
|
return _Utils_Tuple2(
|
||||||
A5(
|
A7(
|
||||||
$author$project$Main$Model,
|
$author$project$Main$Model,
|
||||||
A6($author$project$Main$State, key, route, '', false, $elm$core$Maybe$Nothing, $elm$core$Maybe$Nothing),
|
A6($author$project$Main$State, key, route, '', false, $elm$core$Maybe$Nothing, $elm$core$Maybe$Nothing),
|
||||||
$author$project$Main$blankPlayer,
|
$author$project$Main$blankPlayer,
|
||||||
|
_List_Nil,
|
||||||
|
$elm$core$Maybe$Nothing,
|
||||||
$elm$core$Maybe$Nothing,
|
$elm$core$Maybe$Nothing,
|
||||||
$elm$core$Maybe$Nothing,
|
$elm$core$Maybe$Nothing,
|
||||||
$elm$core$Maybe$Nothing),
|
$elm$core$Maybe$Nothing),
|
||||||
@@ -6903,6 +6931,12 @@ var $author$project$Main$setError = F2(
|
|||||||
{error: error})
|
{error: error})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
var $author$project$Main$setNotification = F2(
|
||||||
|
function (notification, model) {
|
||||||
|
return _Utils_update(
|
||||||
|
model,
|
||||||
|
{notification: notification});
|
||||||
|
});
|
||||||
var $elm$core$Set$remove = F2(
|
var $elm$core$Set$remove = F2(
|
||||||
function (key, _v0) {
|
function (key, _v0) {
|
||||||
var dict = _v0.a;
|
var dict = _v0.a;
|
||||||
@@ -7044,6 +7078,32 @@ var $author$project$Main$update = F2(
|
|||||||
model),
|
model),
|
||||||
$elm$core$Platform$Cmd$none);
|
$elm$core$Platform$Cmd$none);
|
||||||
}
|
}
|
||||||
|
case 'GotClaims':
|
||||||
|
var id = msg.a;
|
||||||
|
var result = msg.b;
|
||||||
|
if (result.$ === 'Ok') {
|
||||||
|
var claims = result.a;
|
||||||
|
return _Utils_Tuple2(
|
||||||
|
_Utils_update(
|
||||||
|
model,
|
||||||
|
{
|
||||||
|
claims: A2(
|
||||||
|
$elm$core$List$filter,
|
||||||
|
function (c) {
|
||||||
|
return _Utils_eq(c.player_id, id);
|
||||||
|
},
|
||||||
|
claims)
|
||||||
|
}),
|
||||||
|
$elm$core$Platform$Cmd$none);
|
||||||
|
} else {
|
||||||
|
var error = result.a;
|
||||||
|
return _Utils_Tuple2(
|
||||||
|
A2(
|
||||||
|
$author$project$Main$setError,
|
||||||
|
'Fetching claims...' + $elm$core$Debug$toString(error),
|
||||||
|
model),
|
||||||
|
$elm$core$Platform$Cmd$none);
|
||||||
|
}
|
||||||
case 'GotLoot':
|
case 'GotLoot':
|
||||||
var dest = msg.a;
|
var dest = msg.a;
|
||||||
var result = msg.b;
|
var result = msg.b;
|
||||||
@@ -7115,11 +7175,15 @@ var $author$project$Main$update = F2(
|
|||||||
return $elm$core$Maybe$Nothing;
|
return $elm$core$Maybe$Nothing;
|
||||||
} else {
|
} else {
|
||||||
if (newMode.a.$ === 'Grab') {
|
if (newMode.a.$ === 'Grab') {
|
||||||
var _v8 = newMode.a;
|
var _v9 = newMode.a;
|
||||||
return $elm$core$Maybe$Just(
|
return $elm$core$Maybe$Just(
|
||||||
$elm$core$Set$fromList(
|
$elm$core$Set$fromList(
|
||||||
_List_fromArray(
|
A2(
|
||||||
[34, 38])));
|
$elm$core$List$map,
|
||||||
|
function (c) {
|
||||||
|
return c.loot_id;
|
||||||
|
},
|
||||||
|
model.claims)));
|
||||||
} else {
|
} else {
|
||||||
var others = newMode.a;
|
var others = newMode.a;
|
||||||
return $elm$core$Maybe$Just($elm$core$Set$empty);
|
return $elm$core$Maybe$Just($elm$core$Set$empty);
|
||||||
@@ -7148,15 +7212,23 @@ var $author$project$Main$update = F2(
|
|||||||
tracker: $elm$core$Maybe$Nothing,
|
tracker: $elm$core$Maybe$Nothing,
|
||||||
url: 'http://localhost:8088/api/players/' + (playerId + '/events/last')
|
url: 'http://localhost:8088/api/players/' + (playerId + '/events/last')
|
||||||
}));
|
}));
|
||||||
default:
|
case 'GotActionResult':
|
||||||
var response = msg.a;
|
var response = msg.a;
|
||||||
if (response.$ === 'Ok') {
|
if (response.$ === 'Ok') {
|
||||||
var result = response.a;
|
var result = response.a;
|
||||||
var updates = A2($elm$core$Maybe$withDefault, _List_Nil, result.updates);
|
var updates = A2($elm$core$Maybe$withDefault, _List_Nil, result.updates);
|
||||||
|
var notification = result.notification;
|
||||||
|
var errors = A2($elm$core$Maybe$withDefault, '', result.errors);
|
||||||
return A2(
|
return A2(
|
||||||
$author$project$Main$update,
|
$author$project$Main$update,
|
||||||
$author$project$Main$ModeSwitched($elm$core$Maybe$Nothing),
|
$author$project$Main$ModeSwitched($elm$core$Maybe$Nothing),
|
||||||
A3($elm$core$List$foldl, $author$project$Main$applyUpdate, model, updates));
|
A2(
|
||||||
|
$author$project$Main$setError,
|
||||||
|
errors,
|
||||||
|
A2(
|
||||||
|
$author$project$Main$setNotification,
|
||||||
|
notification,
|
||||||
|
A3($elm$core$List$foldl, $author$project$Main$applyUpdate, model, updates))));
|
||||||
} else {
|
} else {
|
||||||
var r = response.a;
|
var r = response.a;
|
||||||
return _Utils_Tuple2(
|
return _Utils_Tuple2(
|
||||||
@@ -7166,6 +7238,12 @@ var $author$project$Main$update = F2(
|
|||||||
model),
|
model),
|
||||||
$elm$core$Platform$Cmd$none);
|
$elm$core$Platform$Cmd$none);
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return _Utils_Tuple2(
|
||||||
|
_Utils_update(
|
||||||
|
model,
|
||||||
|
{notification: $elm$core$Maybe$Nothing}),
|
||||||
|
$elm$core$Platform$Cmd$none);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var $author$project$Main$UndoLastAction = {$: 'UndoLastAction'};
|
var $author$project$Main$UndoLastAction = {$: 'UndoLastAction'};
|
||||||
@@ -7304,16 +7382,64 @@ var $author$project$Main$controlsWhenRoute = function (route) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var $elm$html$Html$hr = _VirtualDom_node('hr');
|
var $elm$html$Html$hr = _VirtualDom_node('hr');
|
||||||
var $author$project$Main$renderId = function (item) {
|
var $elm$core$List$any = F2(
|
||||||
return A2(
|
function (isOkay, list) {
|
||||||
$elm$html$Html$p,
|
any:
|
||||||
_List_Nil,
|
while (true) {
|
||||||
_List_fromArray(
|
if (!list.b) {
|
||||||
[
|
return false;
|
||||||
$elm$html$Html$text(
|
} else {
|
||||||
$elm$core$String$fromInt(item.id))
|
var x = list.a;
|
||||||
]));
|
var xs = list.b;
|
||||||
};
|
if (isOkay(x)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
var $temp$isOkay = isOkay,
|
||||||
|
$temp$list = xs;
|
||||||
|
isOkay = $temp$isOkay;
|
||||||
|
list = $temp$list;
|
||||||
|
continue any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var $author$project$Main$itemInClaims = F2(
|
||||||
|
function (claims, item) {
|
||||||
|
return A2(
|
||||||
|
$elm$core$List$any,
|
||||||
|
function (c) {
|
||||||
|
return _Utils_eq(c.loot_id, item.id);
|
||||||
|
},
|
||||||
|
claims);
|
||||||
|
});
|
||||||
|
var $author$project$Main$renderIcon = F2(
|
||||||
|
function (name, size) {
|
||||||
|
return A2(
|
||||||
|
$elm$html$Html$span,
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
$elm$html$Html$Attributes$class('icon is-medium')
|
||||||
|
]),
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
A2(
|
||||||
|
$elm$html$Html$i,
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
$elm$html$Html$Attributes$class(name + (' fa-' + size))
|
||||||
|
]),
|
||||||
|
_List_Nil)
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
var $author$project$Main$renderIfClaimed = F2(
|
||||||
|
function (isClaimed, item) {
|
||||||
|
var _v0 = isClaimed(item);
|
||||||
|
if (_v0) {
|
||||||
|
return A2($author$project$Main$renderIcon, 'fas fa-praying-hands', '1x');
|
||||||
|
} else {
|
||||||
|
return $elm$html$Html$text('');
|
||||||
|
}
|
||||||
|
});
|
||||||
var $author$project$Main$LootViewItemSwitched = function (a) {
|
var $author$project$Main$LootViewItemSwitched = function (a) {
|
||||||
return {$: 'LootViewItemSwitched', a: a};
|
return {$: 'LootViewItemSwitched', a: a};
|
||||||
};
|
};
|
||||||
@@ -7563,7 +7689,7 @@ var $author$project$Main$stackedIcon = function (name) {
|
|||||||
$elm$html$Html$span,
|
$elm$html$Html$span,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
$elm$html$Html$Attributes$class('icon is-large has-text-dark')
|
$elm$html$Html$Attributes$class('icon is-medium')
|
||||||
]),
|
]),
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
[
|
[
|
||||||
@@ -7589,7 +7715,7 @@ var $author$project$Main$stackedIcon = function (name) {
|
|||||||
$elm$html$Html$Attributes$class(name + ' fa-inverse fa-stack-1x')
|
$elm$html$Html$Attributes$class(name + ' fa-inverse fa-stack-1x')
|
||||||
]),
|
]),
|
||||||
_List_Nil),
|
_List_Nil),
|
||||||
$elm$html$Html$text(name)
|
$elm$html$Html$text('')
|
||||||
]))
|
]))
|
||||||
]));
|
]));
|
||||||
};
|
};
|
||||||
@@ -7717,6 +7843,17 @@ var $author$project$Main$viewDebugSection = function (model) {
|
|||||||
$elm$html$Html$text(
|
$elm$html$Html$text(
|
||||||
'Selection : ' + $elm$core$Debug$toString(model.state.selection))
|
'Selection : ' + $elm$core$Debug$toString(model.state.selection))
|
||||||
])),
|
])),
|
||||||
|
A2(
|
||||||
|
$elm$html$Html$p,
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
$elm$html$Html$Attributes$class('panel-block')
|
||||||
|
]),
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
$elm$html$Html$text(
|
||||||
|
'Claims : ' + $elm$core$Debug$toString(model.claims))
|
||||||
|
])),
|
||||||
A2($elm$html$Html$p, _List_Nil, $author$project$Main$debugSandbox)
|
A2($elm$html$Html$p, _List_Nil, $author$project$Main$debugSandbox)
|
||||||
]));
|
]));
|
||||||
};
|
};
|
||||||
@@ -7735,25 +7872,6 @@ var $elm$html$Html$Attributes$href = function (url) {
|
|||||||
_VirtualDom_noJavaScriptUri(url));
|
_VirtualDom_noJavaScriptUri(url));
|
||||||
};
|
};
|
||||||
var $elm$html$Html$nav = _VirtualDom_node('nav');
|
var $elm$html$Html$nav = _VirtualDom_node('nav');
|
||||||
var $author$project$Main$renderIcon = F2(
|
|
||||||
function (name, size) {
|
|
||||||
return A2(
|
|
||||||
$elm$html$Html$span,
|
|
||||||
_List_fromArray(
|
|
||||||
[
|
|
||||||
$elm$html$Html$Attributes$class('icon is-medium')
|
|
||||||
]),
|
|
||||||
_List_fromArray(
|
|
||||||
[
|
|
||||||
A2(
|
|
||||||
$elm$html$Html$i,
|
|
||||||
_List_fromArray(
|
|
||||||
[
|
|
||||||
$elm$html$Html$Attributes$class(name + (' fa-' + size))
|
|
||||||
]),
|
|
||||||
_List_Nil)
|
|
||||||
]));
|
|
||||||
});
|
|
||||||
var $author$project$Main$viewHeaderBar = function (model) {
|
var $author$project$Main$viewHeaderBar = function (model) {
|
||||||
return A2(
|
return A2(
|
||||||
$elm$html$Html$nav,
|
$elm$html$Html$nav,
|
||||||
@@ -7879,6 +7997,32 @@ var $author$project$Main$viewHeaderBar = function (model) {
|
|||||||
]))
|
]))
|
||||||
]));
|
]));
|
||||||
};
|
};
|
||||||
|
var $author$project$Main$ClearNotification = {$: 'ClearNotification'};
|
||||||
|
var $author$project$Main$viewNotification = function (notification) {
|
||||||
|
if (notification.$ === 'Just') {
|
||||||
|
var t = notification.a;
|
||||||
|
return A2(
|
||||||
|
$elm$html$Html$div,
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
$elm$html$Html$Attributes$class('notification is-success is-marginless')
|
||||||
|
]),
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
A2(
|
||||||
|
$elm$html$Html$button,
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
$elm$html$Html$Attributes$class('delete'),
|
||||||
|
$elm$html$Html$Events$onClick($author$project$Main$ClearNotification)
|
||||||
|
]),
|
||||||
|
_List_Nil),
|
||||||
|
$elm$html$Html$text(t)
|
||||||
|
]));
|
||||||
|
} else {
|
||||||
|
return $elm$html$Html$text('');
|
||||||
|
}
|
||||||
|
};
|
||||||
var $elm$core$String$cons = _String_cons;
|
var $elm$core$String$cons = _String_cons;
|
||||||
var $elm$core$String$fromChar = function (_char) {
|
var $elm$core$String$fromChar = function (_char) {
|
||||||
return A2($elm$core$String$cons, _char, '');
|
return A2($elm$core$String$cons, _char, '');
|
||||||
@@ -7973,8 +8117,8 @@ var $author$project$Main$viewWealth = function (wealth) {
|
|||||||
$elm$core$String$fromInt(wealth.cp))
|
$elm$core$String$fromInt(wealth.cp))
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
var $author$project$Main$viewPlayerBar = F2(
|
var $author$project$Main$viewPlayerBar = F3(
|
||||||
function (player, actionControls) {
|
function (player, notification, actionControls) {
|
||||||
return A2(
|
return A2(
|
||||||
$elm$html$Html$section,
|
$elm$html$Html$section,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
@@ -8043,6 +8187,7 @@ var $author$project$Main$viewPlayerBar = F2(
|
|||||||
]))
|
]))
|
||||||
]))
|
]))
|
||||||
]) : _List_Nil))),
|
]) : _List_Nil))),
|
||||||
|
$author$project$Main$viewNotification(notification),
|
||||||
A2(
|
A2(
|
||||||
$elm$html$Html$div,
|
$elm$html$Html$div,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
@@ -8099,7 +8244,9 @@ var $author$project$Main$view = function (model) {
|
|||||||
function () {
|
function () {
|
||||||
var _v4 = model.state.route;
|
var _v4 = model.state.route;
|
||||||
if (_v4.$ === 'GroupLoot') {
|
if (_v4.$ === 'GroupLoot') {
|
||||||
return $elm$core$Maybe$Just($author$project$Main$renderId);
|
return $elm$core$Maybe$Just(
|
||||||
|
$author$project$Main$renderIfClaimed(
|
||||||
|
$author$project$Main$itemInClaims(model.claims)));
|
||||||
} else {
|
} else {
|
||||||
return $elm$core$Maybe$Nothing;
|
return $elm$core$Maybe$Nothing;
|
||||||
}
|
}
|
||||||
@@ -8112,7 +8259,7 @@ var $author$project$Main$view = function (model) {
|
|||||||
body: _List_fromArray(
|
body: _List_fromArray(
|
||||||
[
|
[
|
||||||
$author$project$Main$viewHeaderBar(model),
|
$author$project$Main$viewHeaderBar(model),
|
||||||
A2($author$project$Main$viewPlayerBar, model.player, headerControls),
|
A3($author$project$Main$viewPlayerBar, model.player, model.notification, headerControls),
|
||||||
A2(
|
A2(
|
||||||
$elm$html$Html$article,
|
$elm$html$Html$article,
|
||||||
_List_fromArray(
|
_List_fromArray(
|
||||||
|
|||||||
93
src/Main.elm
93
src/Main.elm
@@ -44,6 +44,8 @@ type alias State =
|
|||||||
type alias Model =
|
type alias Model =
|
||||||
{ state : State
|
{ state : State
|
||||||
, player: Player
|
, player: Player
|
||||||
|
, claims : Claims
|
||||||
|
, notification : Maybe String
|
||||||
, loot: Maybe Loot
|
, loot: Maybe Loot
|
||||||
, groupLoot : Maybe Loot
|
, groupLoot : Maybe Loot
|
||||||
, merchantItems : Maybe Loot
|
, merchantItems : Maybe Loot
|
||||||
@@ -56,7 +58,7 @@ init flags url key =
|
|||||||
Just r -> r
|
Just r -> r
|
||||||
Nothing -> PlayerChest
|
Nothing -> PlayerChest
|
||||||
in
|
in
|
||||||
( Model (State key route "" False Nothing Nothing) blankPlayer Nothing Nothing Nothing, fetchInitialData 0)
|
( Model (State key route "" False Nothing Nothing) blankPlayer [] Nothing Nothing Nothing Nothing, fetchInitialData 0)
|
||||||
|
|
||||||
|
|
||||||
fetchInitialData : Int -> Cmd Msg
|
fetchInitialData : Int -> Cmd Msg
|
||||||
@@ -78,7 +80,7 @@ blankPlayer =
|
|||||||
Player 0 "Loading" 0 (Wealth 0 0 0 0)
|
Player 0 "Loading" 0 (Wealth 0 0 0 0)
|
||||||
|
|
||||||
initPlayer id =
|
initPlayer id =
|
||||||
Cmd.batch [fetchPlayer id, fetchLoot id]
|
Cmd.batch [fetchPlayer id, fetchLoot id, fetchClaims id]
|
||||||
|
|
||||||
fetchPlayer : Int -> Cmd Msg
|
fetchPlayer : Int -> Cmd Msg
|
||||||
fetchPlayer id =
|
fetchPlayer id =
|
||||||
@@ -148,6 +150,28 @@ type ToChest
|
|||||||
= OfPlayer
|
= OfPlayer
|
||||||
| OfGroup
|
| OfGroup
|
||||||
| OfShop
|
| OfShop
|
||||||
|
|
||||||
|
type alias Claims = List Claim
|
||||||
|
|
||||||
|
type alias Claim =
|
||||||
|
{ id: Int
|
||||||
|
, player_id: Int
|
||||||
|
, loot_id: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
claimDecoder =
|
||||||
|
Json.Decode.map3 Claim
|
||||||
|
(field "id" int)
|
||||||
|
(field "player_id" int)
|
||||||
|
(field "loot_id" int)
|
||||||
|
|
||||||
|
fetchClaims : Int -> Cmd Msg
|
||||||
|
fetchClaims playerId =
|
||||||
|
Http.get
|
||||||
|
{ url = "http://localhost:8088/api/claims"
|
||||||
|
, expect = valueDecoder (Json.Decode.list claimDecoder)
|
||||||
|
|> Http.expectJson (GotClaims playerId)
|
||||||
|
}
|
||||||
-- API Response
|
-- API Response
|
||||||
--
|
--
|
||||||
valueDecoder : Decoder a -> Decoder a
|
valueDecoder : Decoder a -> Decoder a
|
||||||
@@ -170,12 +194,14 @@ type Msg
|
|||||||
| UrlChanged Url.Url
|
| UrlChanged Url.Url
|
||||||
| PlayerChanged Int
|
| PlayerChanged Int
|
||||||
| GotPlayer (HttpResult Player)
|
| GotPlayer (HttpResult Player)
|
||||||
|
| GotClaims Int (HttpResult Claims)
|
||||||
| GotLoot ToChest (HttpResult Loot)
|
| GotLoot ToChest (HttpResult Loot)
|
||||||
|
| GotActionResult (HttpResult ApiResponse)
|
||||||
| LootViewItemSwitched Int
|
| LootViewItemSwitched Int
|
||||||
| ModeSwitched (Maybe ViewMode)
|
| ModeSwitched (Maybe ViewMode)
|
||||||
| ConfirmAction
|
| ConfirmAction
|
||||||
| UndoLastAction
|
| UndoLastAction
|
||||||
| GotActionResult (HttpResult ApiResponse)
|
| ClearNotification
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
@@ -220,6 +246,11 @@ update msg model =
|
|||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
GotClaims id result ->
|
||||||
|
case result of
|
||||||
|
Ok claims -> ( { model | claims = List.filter (\c -> c.player_id == id) claims}, Cmd.none )
|
||||||
|
Err error -> ( setError ("Fetching claims..." ++ Debug.toString error) model, Cmd.none)
|
||||||
|
|
||||||
GotLoot dest result ->
|
GotLoot dest result ->
|
||||||
case result of
|
case result of
|
||||||
Ok loot ->
|
Ok loot ->
|
||||||
@@ -250,9 +281,16 @@ update msg model =
|
|||||||
( { model | state =
|
( { model | state =
|
||||||
{ state | activeMode = newMode
|
{ state | activeMode = newMode
|
||||||
, selection = case newMode of
|
, selection = case newMode of
|
||||||
Nothing -> Nothing
|
Nothing ->
|
||||||
Just Grab -> Just (Set.fromList [34, 38])
|
Nothing
|
||||||
Just others -> Just Set.empty
|
|
||||||
|
Just Grab -> -- Currently claimed object are initially selected
|
||||||
|
Just ( Set.fromList
|
||||||
|
<| List.map (\c -> c.loot_id) model.claims
|
||||||
|
)
|
||||||
|
|
||||||
|
Just others ->
|
||||||
|
Just Set.empty
|
||||||
}}
|
}}
|
||||||
, Cmd.none )
|
, Cmd.none )
|
||||||
|
|
||||||
@@ -280,11 +318,20 @@ update msg model =
|
|||||||
Ok result ->
|
Ok result ->
|
||||||
let
|
let
|
||||||
updates = Maybe.withDefault [] result.updates
|
updates = Maybe.withDefault [] result.updates
|
||||||
|
notification = result.notification
|
||||||
|
errors = Maybe.withDefault "" result.errors
|
||||||
in
|
in
|
||||||
List.foldl applyUpdate model updates
|
List.foldl applyUpdate model updates
|
||||||
|
|> setNotification notification
|
||||||
|
|> setError errors
|
||||||
|> update (ModeSwitched Nothing)
|
|> update (ModeSwitched Nothing)
|
||||||
Err r -> (setError (Debug.toString r) model, Cmd.none)
|
Err r -> (setError (Debug.toString r) model, Cmd.none)
|
||||||
|
ClearNotification ->
|
||||||
|
( { model | notification = Nothing }, Cmd.none )
|
||||||
|
|
||||||
|
setNotification : Maybe String -> Model -> Model
|
||||||
|
setNotification notification model =
|
||||||
|
{ model | notification = notification }
|
||||||
|
|
||||||
targetItemsFor : ViewMode -> Model -> List Item
|
targetItemsFor : ViewMode -> Model -> List Item
|
||||||
targetItemsFor mode model =
|
targetItemsFor mode model =
|
||||||
@@ -511,7 +558,7 @@ view model =
|
|||||||
:: controlsWhenRoute model.state.route
|
:: controlsWhenRoute model.state.route
|
||||||
-- Claim controls for Group chest
|
-- Claim controls for Group chest
|
||||||
, case model.state.route of
|
, case model.state.route of
|
||||||
GroupLoot -> Just renderId
|
GroupLoot -> Just (renderIfClaimed <| itemInClaims model.claims)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -523,7 +570,7 @@ view model =
|
|||||||
{ title = "Loot-a-lot in ELM"
|
{ title = "Loot-a-lot in ELM"
|
||||||
, body =
|
, body =
|
||||||
[ viewHeaderBar model
|
[ viewHeaderBar model
|
||||||
, viewPlayerBar model.player headerControls
|
, viewPlayerBar model.player model.notification headerControls
|
||||||
, article [class "section container"]
|
, article [class "section container"]
|
||||||
[ p [class "heading"] [text header]
|
[ p [class "heading"] [text header]
|
||||||
, viewSearchBar
|
, viewSearchBar
|
||||||
@@ -534,6 +581,14 @@ view model =
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewNotification : Maybe String -> Html Msg
|
||||||
|
viewNotification notification =
|
||||||
|
case notification of
|
||||||
|
Just t -> div [ class "notification is-success is-marginless"]
|
||||||
|
[ button [class "delete", onClick ClearNotification ] []
|
||||||
|
, text t ]
|
||||||
|
Nothing -> text ""
|
||||||
|
|
||||||
-- LOOT Views
|
-- LOOT Views
|
||||||
|
|
||||||
itemInSelection : Maybe Selection -> Item -> Bool
|
itemInSelection : Maybe Selection -> Item -> Bool
|
||||||
@@ -541,8 +596,15 @@ itemInSelection selection item =
|
|||||||
Maybe.map (Set.member item.id) selection
|
Maybe.map (Set.member item.id) selection
|
||||||
|> Maybe.withDefault False
|
|> Maybe.withDefault False
|
||||||
|
|
||||||
renderId item =
|
itemInClaims : List Claim -> Item -> Bool
|
||||||
p [] [text <| String.fromInt item.id]
|
itemInClaims claims item =
|
||||||
|
List.any (\c -> c.loot_id == item.id) claims
|
||||||
|
|
||||||
|
renderIfClaimed : (Item -> Bool) -> Item -> Html Msg
|
||||||
|
renderIfClaimed isClaimed item =
|
||||||
|
case isClaimed item of
|
||||||
|
True -> renderIcon "fas fa-praying-hands" "1x"
|
||||||
|
False -> text ""
|
||||||
|
|
||||||
viewChest : (Item -> Bool) -> Maybe (Item -> Html Msg) -> Loot -> Html Msg
|
viewChest : (Item -> Bool) -> Maybe (Item -> Html Msg) -> Loot -> Html Msg
|
||||||
viewChest isSelected rowControls items =
|
viewChest isSelected rowControls items =
|
||||||
@@ -598,15 +660,17 @@ viewDebugSection model =
|
|||||||
, p [class "panel-block"] [text ("Route : " ++ Debug.toString model.state.route)]
|
, p [class "panel-block"] [text ("Route : " ++ Debug.toString model.state.route)]
|
||||||
, p [class "panel-block"] [text ("Active Mode : " ++ Debug.toString model.state.activeMode)]
|
, p [class "panel-block"] [text ("Active Mode : " ++ Debug.toString model.state.activeMode)]
|
||||||
, p [class "panel-block"] [text ("Selection : " ++ Debug.toString model.state.selection)]
|
, p [class "panel-block"] [text ("Selection : " ++ Debug.toString model.state.selection)]
|
||||||
|
, p [class "panel-block"] [text ("Claims : " ++ Debug.toString model.claims)]
|
||||||
, p [] debugSandbox
|
, p [] debugSandbox
|
||||||
]
|
]
|
||||||
|
|
||||||
stackedIcon name =
|
stackedIcon name =
|
||||||
span [class "icon is-large has-text-dark"]
|
span [class "icon is-medium"]
|
||||||
[ span [ class "fa-stack" ]
|
[ span [ class "fa-stack" ]
|
||||||
[ i [ class "fas fa-circle fa-stack-2x" ] []
|
[ i [ class "fas fa-circle fa-stack-2x" ] []
|
||||||
, i [ class (name ++ " fa-inverse fa-stack-1x") ] []
|
, i [ class (name ++ " fa-inverse fa-stack-1x") ] []
|
||||||
, text name ]
|
, text ""
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
debugSandbox =
|
debugSandbox =
|
||||||
@@ -678,8 +742,8 @@ viewHeaderBar model =
|
|||||||
|
|
||||||
-- PLAYER BAR
|
-- PLAYER BAR
|
||||||
|
|
||||||
viewPlayerBar : Player -> List (Html Msg)-> Html Msg
|
viewPlayerBar : Player -> Maybe String -> List (Html Msg)-> Html Msg
|
||||||
viewPlayerBar player actionControls =
|
viewPlayerBar player notification actionControls =
|
||||||
section [ class "level container is-mobile box" ]
|
section [ class "level container is-mobile box" ]
|
||||||
[ div [class "level-left"]
|
[ div [class "level-left"]
|
||||||
([div [ class "level-item" ]
|
([div [ class "level-item" ]
|
||||||
@@ -696,6 +760,7 @@ viewPlayerBar player actionControls =
|
|||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
, viewNotification notification
|
||||||
, div [class "level-right"] actionControls
|
, div [class "level-right"] actionControls
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user