until it compiles...
This commit is contained in:
564
main.js
564
main.js
@@ -5343,26 +5343,30 @@ var $author$project$Main$State = F6(
|
||||
function (navKey, route, error, menuOpen, selection, activeMode) {
|
||||
return {activeMode: activeMode, error: error, menuOpen: menuOpen, navKey: navKey, route: route, selection: selection};
|
||||
});
|
||||
var $author$project$Main$Player = F4(
|
||||
var $author$project$Api$Player = F4(
|
||||
function (id, name, debt, wealth) {
|
||||
return {debt: debt, id: id, name: name, wealth: wealth};
|
||||
});
|
||||
var $author$project$Main$Wealth = F4(
|
||||
var $author$project$Api$Wealth = F4(
|
||||
function (cp, sp, gp, pp) {
|
||||
return {cp: cp, gp: gp, pp: pp, sp: sp};
|
||||
});
|
||||
var $author$project$Main$blankPlayer = A4(
|
||||
$author$project$Main$Player,
|
||||
var $author$project$Api$blankPlayer = A4(
|
||||
$author$project$Api$Player,
|
||||
0,
|
||||
'Loading',
|
||||
'Loot-a-lot',
|
||||
0,
|
||||
A4($author$project$Main$Wealth, 0, 0, 0, 0));
|
||||
A4($author$project$Api$Wealth, 0, 0, 0, 0));
|
||||
var $author$project$Main$ApiMsg = function (a) {
|
||||
return {$: 'ApiMsg', a: a};
|
||||
};
|
||||
var $author$project$Api$OfGroup = {$: 'OfGroup'};
|
||||
var $author$project$Api$OfShop = {$: 'OfShop'};
|
||||
var $elm$core$Platform$Cmd$batch = _Platform_batch;
|
||||
var $author$project$Main$GotLoot = F2(
|
||||
var $author$project$Api$GotLoot = F2(
|
||||
function (a, b) {
|
||||
return {$: 'GotLoot', a: a, b: b};
|
||||
});
|
||||
var $author$project$Main$OfGroup = {$: 'OfGroup'};
|
||||
var $elm$json$Json$Decode$decodeString = _Json_runOnString;
|
||||
var $elm$http$Http$BadStatus_ = F2(
|
||||
function (a, b) {
|
||||
@@ -6150,7 +6154,7 @@ var $elm$http$Http$get = function (r) {
|
||||
return $elm$http$Http$request(
|
||||
{body: $elm$http$Http$emptyBody, expect: r.expect, headers: _List_Nil, method: 'GET', timeout: $elm$core$Maybe$Nothing, tracker: $elm$core$Maybe$Nothing, url: r.url});
|
||||
};
|
||||
var $author$project$Main$Item = F3(
|
||||
var $author$project$Api$Item = F3(
|
||||
function (id, name, base_price) {
|
||||
return {base_price: base_price, id: id, name: name};
|
||||
});
|
||||
@@ -6158,105 +6162,112 @@ var $elm$json$Json$Decode$field = _Json_decodeField;
|
||||
var $elm$json$Json$Decode$int = _Json_decodeInt;
|
||||
var $elm$json$Json$Decode$map3 = _Json_map3;
|
||||
var $elm$json$Json$Decode$string = _Json_decodeString;
|
||||
var $author$project$Main$itemDecoder = A4(
|
||||
var $author$project$Api$itemDecoder = A4(
|
||||
$elm$json$Json$Decode$map3,
|
||||
$author$project$Main$Item,
|
||||
$author$project$Api$Item,
|
||||
A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int),
|
||||
A2($elm$json$Json$Decode$field, 'name', $elm$json$Json$Decode$string),
|
||||
A2($elm$json$Json$Decode$field, 'base_price', $elm$json$Json$Decode$int));
|
||||
var $elm$json$Json$Decode$list = _Json_decodeList;
|
||||
var $author$project$Main$lootDecoder = $elm$json$Json$Decode$list($author$project$Main$itemDecoder);
|
||||
var $author$project$Main$valueDecoder = function (thenDecoder) {
|
||||
var $author$project$Api$lootDecoder = $elm$json$Json$Decode$list($author$project$Api$itemDecoder);
|
||||
var $author$project$Api$valueDecoder = function (thenDecoder) {
|
||||
return A2($elm$json$Json$Decode$field, 'value', thenDecoder);
|
||||
};
|
||||
var $author$project$Main$fetchGroupLoot = $elm$http$Http$get(
|
||||
var $author$project$Api$fetchLoot = function (dest) {
|
||||
var url = function () {
|
||||
switch (dest.$) {
|
||||
case 'OfPlayer':
|
||||
var id = dest.a;
|
||||
return 'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(id) + '/loot');
|
||||
case 'OfShop':
|
||||
return 'http://localhost:8088/api/items';
|
||||
default:
|
||||
return 'http://localhost:8088/api/players/0/loot';
|
||||
}
|
||||
}();
|
||||
return $elm$http$Http$get(
|
||||
{
|
||||
expect: A2(
|
||||
$elm$http$Http$expectJson,
|
||||
$author$project$Main$GotLoot($author$project$Main$OfGroup),
|
||||
$author$project$Main$valueDecoder($author$project$Main$lootDecoder)),
|
||||
url: 'http://localhost:8088/api/players/0/loot'
|
||||
$author$project$Api$GotLoot(dest),
|
||||
$author$project$Api$valueDecoder($author$project$Api$lootDecoder)),
|
||||
url: url
|
||||
});
|
||||
var $author$project$Main$OfShop = {$: 'OfShop'};
|
||||
var $author$project$Main$fetchShopInventory = $elm$http$Http$get(
|
||||
{
|
||||
expect: A2(
|
||||
$elm$http$Http$expectJson,
|
||||
$author$project$Main$GotLoot($author$project$Main$OfShop),
|
||||
$author$project$Main$valueDecoder($author$project$Main$lootDecoder)),
|
||||
url: 'http://localhost:8088/api/items'
|
||||
});
|
||||
var $author$project$Main$GotClaims = F2(
|
||||
};
|
||||
var $author$project$Api$OfPlayer = function (a) {
|
||||
return {$: 'OfPlayer', a: a};
|
||||
};
|
||||
var $author$project$Api$GotClaims = F2(
|
||||
function (a, b) {
|
||||
return {$: 'GotClaims', a: a, b: b};
|
||||
});
|
||||
var $author$project$Main$Claim = F3(
|
||||
var $author$project$Api$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(
|
||||
var $author$project$Api$claimDecoder = A4(
|
||||
$elm$json$Json$Decode$map3,
|
||||
$author$project$Main$Claim,
|
||||
$author$project$Api$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) {
|
||||
var $author$project$Api$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))),
|
||||
$author$project$Api$GotClaims(playerId),
|
||||
$author$project$Api$valueDecoder(
|
||||
$elm$json$Json$Decode$list($author$project$Api$claimDecoder))),
|
||||
url: 'http://localhost:8088/api/claims'
|
||||
});
|
||||
};
|
||||
var $author$project$Main$OfPlayer = {$: 'OfPlayer'};
|
||||
var $author$project$Main$fetchLoot = function (id) {
|
||||
return $elm$http$Http$get(
|
||||
{
|
||||
expect: A2(
|
||||
$elm$http$Http$expectJson,
|
||||
$author$project$Main$GotLoot($author$project$Main$OfPlayer),
|
||||
$author$project$Main$valueDecoder($author$project$Main$lootDecoder)),
|
||||
url: 'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(id) + '/loot')
|
||||
});
|
||||
};
|
||||
var $author$project$Main$GotPlayer = function (a) {
|
||||
var $author$project$Api$GotPlayer = function (a) {
|
||||
return {$: 'GotPlayer', a: a};
|
||||
};
|
||||
var $elm$json$Json$Decode$map4 = _Json_map4;
|
||||
var $author$project$Main$wealthDecoder = A5(
|
||||
var $author$project$Api$wealthDecoder = A5(
|
||||
$elm$json$Json$Decode$map4,
|
||||
$author$project$Main$Wealth,
|
||||
$author$project$Api$Wealth,
|
||||
A2($elm$json$Json$Decode$field, 'cp', $elm$json$Json$Decode$int),
|
||||
A2($elm$json$Json$Decode$field, 'sp', $elm$json$Json$Decode$int),
|
||||
A2($elm$json$Json$Decode$field, 'gp', $elm$json$Json$Decode$int),
|
||||
A2($elm$json$Json$Decode$field, 'pp', $elm$json$Json$Decode$int));
|
||||
var $author$project$Main$playerDecoder = A5(
|
||||
var $author$project$Api$playerDecoder = A5(
|
||||
$elm$json$Json$Decode$map4,
|
||||
$author$project$Main$Player,
|
||||
$author$project$Api$Player,
|
||||
A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int),
|
||||
A2($elm$json$Json$Decode$field, 'name', $elm$json$Json$Decode$string),
|
||||
A2($elm$json$Json$Decode$field, 'debt', $elm$json$Json$Decode$int),
|
||||
$author$project$Main$wealthDecoder);
|
||||
var $author$project$Main$fetchPlayer = function (id) {
|
||||
$author$project$Api$wealthDecoder);
|
||||
var $author$project$Api$fetchPlayer = function (id) {
|
||||
return $elm$http$Http$get(
|
||||
{
|
||||
expect: A2(
|
||||
$elm$http$Http$expectJson,
|
||||
$author$project$Main$GotPlayer,
|
||||
$author$project$Main$valueDecoder($author$project$Main$playerDecoder)),
|
||||
$author$project$Api$GotPlayer,
|
||||
$author$project$Api$valueDecoder($author$project$Api$playerDecoder)),
|
||||
url: 'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(id) + '/')
|
||||
});
|
||||
};
|
||||
var $elm$core$Platform$Cmd$map = _Platform_map;
|
||||
var $author$project$Main$initPlayer = function (id) {
|
||||
return $elm$core$Platform$Cmd$batch(
|
||||
_List_fromArray(
|
||||
[
|
||||
$author$project$Main$fetchPlayer(id),
|
||||
$author$project$Main$fetchLoot(id),
|
||||
$author$project$Main$fetchClaims(id)
|
||||
A2(
|
||||
$elm$core$Platform$Cmd$map,
|
||||
$author$project$Main$ApiMsg,
|
||||
$author$project$Api$fetchPlayer(id)),
|
||||
A2(
|
||||
$elm$core$Platform$Cmd$map,
|
||||
$author$project$Main$ApiMsg,
|
||||
$author$project$Api$fetchLoot(
|
||||
$author$project$Api$OfPlayer(id))),
|
||||
A2(
|
||||
$elm$core$Platform$Cmd$map,
|
||||
$author$project$Main$ApiMsg,
|
||||
$author$project$Api$fetchClaims(id))
|
||||
]));
|
||||
};
|
||||
var $author$project$Main$fetchInitialData = function (playerId) {
|
||||
@@ -6264,8 +6275,14 @@ var $author$project$Main$fetchInitialData = function (playerId) {
|
||||
_List_fromArray(
|
||||
[
|
||||
$author$project$Main$initPlayer(playerId),
|
||||
$author$project$Main$fetchShopInventory,
|
||||
$author$project$Main$fetchGroupLoot
|
||||
A2(
|
||||
$elm$core$Platform$Cmd$map,
|
||||
$author$project$Main$ApiMsg,
|
||||
$author$project$Api$fetchLoot($author$project$Api$OfShop)),
|
||||
A2(
|
||||
$elm$core$Platform$Cmd$map,
|
||||
$author$project$Main$ApiMsg,
|
||||
$author$project$Api$fetchLoot($author$project$Api$OfGroup))
|
||||
]));
|
||||
};
|
||||
var $elm$url$Url$Parser$State = F5(
|
||||
@@ -6516,7 +6533,7 @@ var $author$project$Main$init = F3(
|
||||
A7(
|
||||
$author$project$Main$Model,
|
||||
A6($author$project$Main$State, key, route, '', false, $elm$core$Maybe$Nothing, $elm$core$Maybe$Nothing),
|
||||
$author$project$Main$blankPlayer,
|
||||
$author$project$Api$blankPlayer,
|
||||
_List_Nil,
|
||||
$elm$core$Maybe$Nothing,
|
||||
$elm$core$Maybe$Nothing,
|
||||
@@ -6529,110 +6546,10 @@ var $elm$core$Platform$Sub$none = $elm$core$Platform$Sub$batch(_List_Nil);
|
||||
var $author$project$Main$subscriptions = function (_v0) {
|
||||
return $elm$core$Platform$Sub$none;
|
||||
};
|
||||
var $author$project$Main$Add = {$: 'Add'};
|
||||
var $author$project$Main$GotActionResult = function (a) {
|
||||
return {$: 'GotActionResult', a: a};
|
||||
};
|
||||
var $author$project$Modes$Add = {$: 'Add'};
|
||||
var $author$project$Main$ModeSwitched = function (a) {
|
||||
return {$: 'ModeSwitched', a: a};
|
||||
};
|
||||
var $author$project$Main$ApiResponse = F4(
|
||||
function (value, notification, updates, errors) {
|
||||
return {errors: errors, notification: notification, updates: updates, value: value};
|
||||
});
|
||||
var $elm$json$Json$Decode$oneOf = _Json_oneOf;
|
||||
var $elm$json$Json$Decode$maybe = function (decoder) {
|
||||
return $elm$json$Json$Decode$oneOf(
|
||||
_List_fromArray(
|
||||
[
|
||||
A2($elm$json$Json$Decode$map, $elm$core$Maybe$Just, decoder),
|
||||
$elm$json$Json$Decode$succeed($elm$core$Maybe$Nothing)
|
||||
]));
|
||||
};
|
||||
var $author$project$Main$ClaimAdded = function (a) {
|
||||
return {$: 'ClaimAdded', a: a};
|
||||
};
|
||||
var $author$project$Main$ClaimRemoved = function (a) {
|
||||
return {$: 'ClaimRemoved', a: a};
|
||||
};
|
||||
var $author$project$Main$ItemAdded = function (a) {
|
||||
return {$: 'ItemAdded', a: a};
|
||||
};
|
||||
var $author$project$Main$ItemRemoved = function (a) {
|
||||
return {$: 'ItemRemoved', a: a};
|
||||
};
|
||||
var $author$project$Main$WealthUpdated = function (a) {
|
||||
return {$: 'WealthUpdated', a: a};
|
||||
};
|
||||
var $elm$json$Json$Decode$andThen = _Json_andThen;
|
||||
var $author$project$Main$updatesDecoder = $elm$json$Json$Decode$oneOf(
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ItemRemoved',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Main$ItemRemoved(i));
|
||||
},
|
||||
$author$project$Main$itemDecoder)),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ItemAdded',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Main$ItemAdded(i));
|
||||
},
|
||||
$author$project$Main$itemDecoder)),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'Wealth',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Main$WealthUpdated(i));
|
||||
},
|
||||
$author$project$Main$wealthDecoder)),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ClaimRemoved',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Main$ClaimRemoved(i));
|
||||
},
|
||||
$elm$json$Json$Decode$succeed(_Utils_Tuple0))),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ClaimAdded',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Main$ClaimAdded(i));
|
||||
},
|
||||
$elm$json$Json$Decode$succeed(_Utils_Tuple0)))
|
||||
]));
|
||||
var $author$project$Main$apiResponseDecoder = A5(
|
||||
$elm$json$Json$Decode$map4,
|
||||
$author$project$Main$ApiResponse,
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2($elm$json$Json$Decode$field, 'value', $elm$json$Json$Decode$string)),
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2($elm$json$Json$Decode$field, 'notification', $elm$json$Json$Decode$string)),
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'updates',
|
||||
$elm$json$Json$Decode$list($author$project$Main$updatesDecoder))),
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2($elm$json$Json$Decode$field, 'errors', $elm$json$Json$Decode$string)));
|
||||
var $elm$core$List$filter = F2(
|
||||
function (isGood, list) {
|
||||
return A3(
|
||||
@@ -6691,7 +6608,7 @@ var $author$project$Main$applyUpdate = F2(
|
||||
player: _Utils_update(
|
||||
player,
|
||||
{
|
||||
wealth: A4($author$project$Main$Wealth, wealth.cp + diff.cp, wealth.sp + diff.sp, wealth.gp + diff.gp, wealth.pp + diff.pp)
|
||||
wealth: A4($author$project$Api$Wealth, wealth.cp + diff.cp, wealth.sp + diff.sp, wealth.gp + diff.gp, wealth.pp + diff.pp)
|
||||
})
|
||||
});
|
||||
case 'ClaimAdded':
|
||||
@@ -6700,29 +6617,6 @@ var $author$project$Main$applyUpdate = F2(
|
||||
return model;
|
||||
}
|
||||
});
|
||||
var $elm$core$Set$Set_elm_builtin = function (a) {
|
||||
return {$: 'Set_elm_builtin', a: a};
|
||||
};
|
||||
var $elm$core$Set$empty = $elm$core$Set$Set_elm_builtin($elm$core$Dict$empty);
|
||||
var $elm$core$Set$insert = F2(
|
||||
function (key, _v0) {
|
||||
var dict = _v0.a;
|
||||
return $elm$core$Set$Set_elm_builtin(
|
||||
A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict));
|
||||
});
|
||||
var $elm$core$Set$fromList = function (list) {
|
||||
return A3($elm$core$List$foldl, $elm$core$Set$insert, $elm$core$Set$empty, list);
|
||||
};
|
||||
var $elm$core$Debug$log = _Debug_log;
|
||||
var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil);
|
||||
var $author$project$Main$printError = function (error) {
|
||||
if (error.$ === 'NetworkError') {
|
||||
return 'Le serveur ne répond pas';
|
||||
} else {
|
||||
return 'Erreur inconnue';
|
||||
}
|
||||
};
|
||||
var $elm$browser$Browser$Navigation$pushUrl = _Browser_pushUrl;
|
||||
var $elm$json$Json$Encode$int = _Json_wrap;
|
||||
var $elm$core$Maybe$map = F2(
|
||||
function (f, maybe) {
|
||||
@@ -6873,52 +6767,154 @@ var $author$project$Main$buildPayload = F2(
|
||||
]));
|
||||
}
|
||||
});
|
||||
var $elm$core$Set$Set_elm_builtin = function (a) {
|
||||
return {$: 'Set_elm_builtin', a: a};
|
||||
};
|
||||
var $elm$core$Set$empty = $elm$core$Set$Set_elm_builtin($elm$core$Dict$empty);
|
||||
var $elm$core$Set$insert = F2(
|
||||
function (key, _v0) {
|
||||
var dict = _v0.a;
|
||||
return $elm$core$Set$Set_elm_builtin(
|
||||
A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict));
|
||||
});
|
||||
var $elm$core$Set$fromList = function (list) {
|
||||
return A3($elm$core$List$foldl, $elm$core$Set$insert, $elm$core$Set$empty, list);
|
||||
};
|
||||
var $elm$core$Debug$log = _Debug_log;
|
||||
var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil);
|
||||
var $elm$browser$Browser$Navigation$pushUrl = _Browser_pushUrl;
|
||||
var $author$project$Api$GotActionResult = function (a) {
|
||||
return {$: 'GotActionResult', a: a};
|
||||
};
|
||||
var $author$project$Api$Response = F4(
|
||||
function (value, notification, updates, errors) {
|
||||
return {errors: errors, notification: notification, updates: updates, value: value};
|
||||
});
|
||||
var $elm$json$Json$Decode$oneOf = _Json_oneOf;
|
||||
var $elm$json$Json$Decode$maybe = function (decoder) {
|
||||
return $elm$json$Json$Decode$oneOf(
|
||||
_List_fromArray(
|
||||
[
|
||||
A2($elm$json$Json$Decode$map, $elm$core$Maybe$Just, decoder),
|
||||
$elm$json$Json$Decode$succeed($elm$core$Maybe$Nothing)
|
||||
]));
|
||||
};
|
||||
var $author$project$Api$ClaimAdded = function (a) {
|
||||
return {$: 'ClaimAdded', a: a};
|
||||
};
|
||||
var $author$project$Api$ClaimRemoved = function (a) {
|
||||
return {$: 'ClaimRemoved', a: a};
|
||||
};
|
||||
var $author$project$Api$ItemAdded = function (a) {
|
||||
return {$: 'ItemAdded', a: a};
|
||||
};
|
||||
var $author$project$Api$ItemRemoved = function (a) {
|
||||
return {$: 'ItemRemoved', a: a};
|
||||
};
|
||||
var $author$project$Api$WealthUpdated = function (a) {
|
||||
return {$: 'WealthUpdated', a: a};
|
||||
};
|
||||
var $elm$json$Json$Decode$andThen = _Json_andThen;
|
||||
var $author$project$Api$updatesDecoder = $elm$json$Json$Decode$oneOf(
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ItemRemoved',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Api$ItemRemoved(i));
|
||||
},
|
||||
$author$project$Api$itemDecoder)),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ItemAdded',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Api$ItemAdded(i));
|
||||
},
|
||||
$author$project$Api$itemDecoder)),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'Wealth',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Api$WealthUpdated(i));
|
||||
},
|
||||
$author$project$Api$wealthDecoder)),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ClaimRemoved',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Api$ClaimRemoved(i));
|
||||
},
|
||||
$elm$json$Json$Decode$succeed(_Utils_Tuple0))),
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'ClaimAdded',
|
||||
A2(
|
||||
$elm$json$Json$Decode$andThen,
|
||||
function (i) {
|
||||
return $elm$json$Json$Decode$succeed(
|
||||
$author$project$Api$ClaimAdded(i));
|
||||
},
|
||||
$elm$json$Json$Decode$succeed(_Utils_Tuple0)))
|
||||
]));
|
||||
var $author$project$Api$apiResponseDecoder = A5(
|
||||
$elm$json$Json$Decode$map4,
|
||||
$author$project$Api$Response,
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2($elm$json$Json$Decode$field, 'value', $elm$json$Json$Decode$string)),
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2($elm$json$Json$Decode$field, 'notification', $elm$json$Json$Decode$string)),
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2(
|
||||
$elm$json$Json$Decode$field,
|
||||
'updates',
|
||||
$elm$json$Json$Decode$list($author$project$Api$updatesDecoder))),
|
||||
$elm$json$Json$Decode$maybe(
|
||||
A2($elm$json$Json$Decode$field, 'errors', $elm$json$Json$Decode$string)));
|
||||
var $elm$http$Http$jsonBody = function (value) {
|
||||
return A2(
|
||||
_Http_pair,
|
||||
'application/json',
|
||||
A2($elm$json$Json$Encode$encode, 0, value));
|
||||
};
|
||||
var $author$project$Main$sendRequest = F2(
|
||||
function (activeMode, model) {
|
||||
if (activeMode.$ === 'Nothing') {
|
||||
return $elm$core$Platform$Cmd$none;
|
||||
} else {
|
||||
var mode = activeMode.a;
|
||||
var _v1 = function () {
|
||||
var $author$project$Api$sendRequest = F3(
|
||||
function (mode, id, payload) {
|
||||
var _v0 = function () {
|
||||
switch (mode.$) {
|
||||
case 'Add':
|
||||
return _Utils_Tuple2(
|
||||
'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(model.player.id) + '/loot'),
|
||||
'POST');
|
||||
return _Utils_Tuple2('http://localhost:8088/api/players/' + (id + '/loot'), 'POST');
|
||||
case 'Buy':
|
||||
return _Utils_Tuple2(
|
||||
'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(model.player.id) + '/loot'),
|
||||
'PUT');
|
||||
return _Utils_Tuple2('http://localhost:8088/api/players/' + (id + '/loot'), 'PUT');
|
||||
case 'Sell':
|
||||
return _Utils_Tuple2(
|
||||
'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(model.player.id) + '/loot'),
|
||||
'DELETE');
|
||||
return _Utils_Tuple2('http://localhost:8088/api/players/' + (id + '/loot'), 'DELETE');
|
||||
default:
|
||||
return _Utils_Tuple2(
|
||||
'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(model.player.id) + '/claims'),
|
||||
'POST');
|
||||
return _Utils_Tuple2('http://localhost:8088/api/players/' + (id + '/claims'), 'POST');
|
||||
}
|
||||
}();
|
||||
var endpoint = _v1.a;
|
||||
var method = _v1.b;
|
||||
var endpoint = _v0.a;
|
||||
var method = _v0.b;
|
||||
return $elm$http$Http$request(
|
||||
{
|
||||
body: $elm$http$Http$jsonBody(
|
||||
A2($author$project$Main$buildPayload, mode, model)),
|
||||
expect: A2($elm$http$Http$expectJson, $author$project$Main$GotActionResult, $author$project$Main$apiResponseDecoder),
|
||||
body: $elm$http$Http$jsonBody(payload),
|
||||
expect: A2($elm$http$Http$expectJson, $author$project$Api$GotActionResult, $author$project$Api$apiResponseDecoder),
|
||||
headers: _List_Nil,
|
||||
method: method,
|
||||
timeout: $elm$core$Maybe$Nothing,
|
||||
tracker: $elm$core$Maybe$Nothing,
|
||||
url: endpoint
|
||||
});
|
||||
}
|
||||
});
|
||||
var $author$project$Main$setError = F2(
|
||||
function (error, model) {
|
||||
@@ -7005,8 +7001,22 @@ var $elm$url$Url$toString = function (url) {
|
||||
_Utils_ap(http, url.host)),
|
||||
url.path)));
|
||||
};
|
||||
var $author$project$Api$undoLastAction = function (id) {
|
||||
return $elm$http$Http$request(
|
||||
{
|
||||
body: $elm$http$Http$emptyBody,
|
||||
expect: A2($elm$http$Http$expectJson, $author$project$Api$GotActionResult, $author$project$Api$apiResponseDecoder),
|
||||
headers: _List_Nil,
|
||||
method: 'DELETE',
|
||||
timeout: $elm$core$Maybe$Nothing,
|
||||
tracker: $elm$core$Maybe$Nothing,
|
||||
url: 'http://localhost:8088/api/players/' + ($elm$core$String$fromInt(id) + '/events/last')
|
||||
});
|
||||
};
|
||||
var $author$project$Main$update = F2(
|
||||
function (msg, model) {
|
||||
update:
|
||||
while (true) {
|
||||
switch (msg.$) {
|
||||
case 'LinkClicked':
|
||||
var urlRequest = msg.a;
|
||||
@@ -7035,7 +7045,7 @@ var $author$project$Main$update = F2(
|
||||
function () {
|
||||
if (page.$ === 'NewLoot') {
|
||||
return $author$project$Main$ModeSwitched(
|
||||
$elm$core$Maybe$Just($author$project$Main$Add));
|
||||
$elm$core$Maybe$Just($author$project$Modes$Add));
|
||||
} else {
|
||||
var other = page;
|
||||
return $author$project$Main$ModeSwitched($elm$core$Maybe$Nothing);
|
||||
@@ -7058,10 +7068,39 @@ var $author$project$Main$update = F2(
|
||||
return _Utils_Tuple2(
|
||||
_Utils_update(
|
||||
model,
|
||||
{player: $author$project$Main$blankPlayer}),
|
||||
{player: $author$project$Api$blankPlayer}),
|
||||
$author$project$Main$initPlayer(newId));
|
||||
case 'ApiMsg':
|
||||
var apiMsg = msg.a;
|
||||
switch (apiMsg.$) {
|
||||
case 'GotActionResult':
|
||||
var response = apiMsg.a;
|
||||
if (response.$ === 'Ok') {
|
||||
var result = response.a;
|
||||
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(
|
||||
$author$project$Main$update,
|
||||
$author$project$Main$ModeSwitched($elm$core$Maybe$Nothing),
|
||||
A2(
|
||||
$author$project$Main$setError,
|
||||
errors,
|
||||
A2(
|
||||
$author$project$Main$setNotification,
|
||||
notification,
|
||||
A3($elm$core$List$foldl, $author$project$Main$applyUpdate, model, updates))));
|
||||
} else {
|
||||
var r = response.a;
|
||||
return _Utils_Tuple2(
|
||||
A2(
|
||||
$author$project$Main$setError,
|
||||
$elm$core$Debug$toString(r),
|
||||
model),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
}
|
||||
case 'GotPlayer':
|
||||
var result = msg.a;
|
||||
var result = apiMsg.a;
|
||||
if (result.$ === 'Ok') {
|
||||
var player = result.a;
|
||||
return _Utils_Tuple2(
|
||||
@@ -7074,13 +7113,13 @@ var $author$project$Main$update = F2(
|
||||
return _Utils_Tuple2(
|
||||
A2(
|
||||
$author$project$Main$setError,
|
||||
'Fetching player... ' + $author$project$Main$printError(error),
|
||||
'Fetching player... ' + $elm$core$Debug$toString(error),
|
||||
model),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
}
|
||||
case 'GotClaims':
|
||||
var id = msg.a;
|
||||
var result = msg.b;
|
||||
var id = apiMsg.a;
|
||||
var result = apiMsg.b;
|
||||
if (result.$ === 'Ok') {
|
||||
var claims = result.a;
|
||||
return _Utils_Tuple2(
|
||||
@@ -7104,9 +7143,9 @@ var $author$project$Main$update = F2(
|
||||
model),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
}
|
||||
case 'GotLoot':
|
||||
var dest = msg.a;
|
||||
var result = msg.b;
|
||||
default:
|
||||
var dest = apiMsg.a;
|
||||
var result = apiMsg.b;
|
||||
if (result.$ === 'Ok') {
|
||||
var loot = result.a;
|
||||
return _Utils_Tuple2(
|
||||
@@ -7138,10 +7177,11 @@ var $author$project$Main$update = F2(
|
||||
return _Utils_Tuple2(
|
||||
A2(
|
||||
$author$project$Main$setError,
|
||||
'Fetching loot... ' + $author$project$Main$printError(error),
|
||||
'Fetching loot... ' + $elm$core$Debug$toString(error),
|
||||
model),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
}
|
||||
}
|
||||
case 'LootViewItemSwitched':
|
||||
var id = msg.a;
|
||||
var state = model.state;
|
||||
@@ -7175,7 +7215,7 @@ var $author$project$Main$update = F2(
|
||||
return $elm$core$Maybe$Nothing;
|
||||
} else {
|
||||
if (newMode.a.$ === 'Grab') {
|
||||
var _v9 = newMode.a;
|
||||
var _v11 = newMode.a;
|
||||
return $elm$core$Maybe$Just(
|
||||
$elm$core$Set$fromList(
|
||||
A2(
|
||||
@@ -7194,50 +7234,33 @@ var $author$project$Main$update = F2(
|
||||
}),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
case 'ConfirmAction':
|
||||
var currentMode = model.state.activeMode;
|
||||
return _Utils_Tuple2(
|
||||
model,
|
||||
A2($author$project$Main$sendRequest, currentMode, model));
|
||||
case 'UndoLastAction':
|
||||
var playerId = $elm$core$String$fromInt(model.player.id);
|
||||
return _Utils_Tuple2(
|
||||
model,
|
||||
$elm$http$Http$request(
|
||||
{
|
||||
body: $elm$http$Http$emptyBody,
|
||||
expect: A2($elm$http$Http$expectJson, $author$project$Main$GotActionResult, $author$project$Main$apiResponseDecoder),
|
||||
headers: _List_Nil,
|
||||
method: 'DELETE',
|
||||
timeout: $elm$core$Maybe$Nothing,
|
||||
tracker: $elm$core$Maybe$Nothing,
|
||||
url: 'http://localhost:8088/api/players/' + (playerId + '/events/last')
|
||||
}));
|
||||
case 'GotActionResult':
|
||||
var response = msg.a;
|
||||
if (response.$ === 'Ok') {
|
||||
var result = response.a;
|
||||
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(
|
||||
$author$project$Main$update,
|
||||
$author$project$Main$ModeSwitched($elm$core$Maybe$Nothing),
|
||||
A2(
|
||||
$author$project$Main$setError,
|
||||
errors,
|
||||
A2(
|
||||
$author$project$Main$setNotification,
|
||||
notification,
|
||||
A3($elm$core$List$foldl, $author$project$Main$applyUpdate, model, updates))));
|
||||
var _v12 = model.state.activeMode;
|
||||
if (_v12.$ === 'Nothing') {
|
||||
var $temp$msg = $author$project$Main$ModeSwitched($elm$core$Maybe$Nothing),
|
||||
$temp$model = model;
|
||||
msg = $temp$msg;
|
||||
model = $temp$model;
|
||||
continue update;
|
||||
} else {
|
||||
var r = response.a;
|
||||
var mode = _v12.a;
|
||||
return _Utils_Tuple2(
|
||||
model,
|
||||
A2(
|
||||
$author$project$Main$setError,
|
||||
$elm$core$Debug$toString(r),
|
||||
model),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
$elm$core$Platform$Cmd$map,
|
||||
$author$project$Main$ApiMsg,
|
||||
A3(
|
||||
$author$project$Api$sendRequest,
|
||||
mode,
|
||||
$elm$core$String$fromInt(model.player.id),
|
||||
A2($author$project$Main$buildPayload, mode, model))));
|
||||
}
|
||||
case 'UndoLastAction':
|
||||
return _Utils_Tuple2(
|
||||
model,
|
||||
A2(
|
||||
$elm$core$Platform$Cmd$map,
|
||||
$author$project$Main$ApiMsg,
|
||||
$author$project$Api$undoLastAction(model.player.id)));
|
||||
default:
|
||||
return _Utils_Tuple2(
|
||||
_Utils_update(
|
||||
@@ -7245,6 +7268,7 @@ var $author$project$Main$update = F2(
|
||||
{notification: $elm$core$Maybe$Nothing}),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
}
|
||||
}
|
||||
});
|
||||
var $author$project$Main$UndoLastAction = {$: 'UndoLastAction'};
|
||||
var $elm$html$Html$button = _VirtualDom_node('button');
|
||||
@@ -7330,9 +7354,9 @@ var $author$project$Main$controlsWhenModeActive = function (mode) {
|
||||
'danger')
|
||||
]);
|
||||
};
|
||||
var $author$project$Main$Buy = {$: 'Buy'};
|
||||
var $author$project$Main$Grab = {$: 'Grab'};
|
||||
var $author$project$Main$Sell = {$: 'Sell'};
|
||||
var $author$project$Modes$Buy = {$: 'Buy'};
|
||||
var $author$project$Modes$Grab = {$: 'Grab'};
|
||||
var $author$project$Modes$Sell = {$: 'Sell'};
|
||||
var $author$project$Main$controlsWhenRoute = function (route) {
|
||||
switch (route.$) {
|
||||
case 'PlayerChest':
|
||||
@@ -7341,7 +7365,7 @@ var $author$project$Main$controlsWhenRoute = function (route) {
|
||||
A4(
|
||||
$author$project$Main$actionButton,
|
||||
$author$project$Main$ModeSwitched(
|
||||
$elm$core$Maybe$Just($author$project$Main$Sell)),
|
||||
$elm$core$Maybe$Just($author$project$Modes$Sell)),
|
||||
'Vendre',
|
||||
'coins',
|
||||
'danger')
|
||||
@@ -7352,7 +7376,7 @@ var $author$project$Main$controlsWhenRoute = function (route) {
|
||||
A4(
|
||||
$author$project$Main$actionButton,
|
||||
$author$project$Main$ModeSwitched(
|
||||
$elm$core$Maybe$Just($author$project$Main$Grab)),
|
||||
$elm$core$Maybe$Just($author$project$Modes$Grab)),
|
||||
'Demander',
|
||||
'praying-hands',
|
||||
'primary')
|
||||
@@ -7363,7 +7387,7 @@ var $author$project$Main$controlsWhenRoute = function (route) {
|
||||
A4(
|
||||
$author$project$Main$actionButton,
|
||||
$author$project$Main$ModeSwitched(
|
||||
$elm$core$Maybe$Just($author$project$Main$Buy)),
|
||||
$elm$core$Maybe$Just($author$project$Modes$Buy)),
|
||||
'Acheter',
|
||||
'coins',
|
||||
'success')
|
||||
@@ -7374,7 +7398,7 @@ var $author$project$Main$controlsWhenRoute = function (route) {
|
||||
A4(
|
||||
$author$project$Main$actionButton,
|
||||
$author$project$Main$ModeSwitched(
|
||||
$elm$core$Maybe$Just($author$project$Main$Add)),
|
||||
$elm$core$Maybe$Just($author$project$Modes$Add)),
|
||||
'Nouveau loot',
|
||||
'plus',
|
||||
'primary')
|
||||
@@ -7443,7 +7467,7 @@ var $author$project$Main$renderIfClaimed = F2(
|
||||
var $author$project$Main$LootViewItemSwitched = function (a) {
|
||||
return {$: 'LootViewItemSwitched', a: a};
|
||||
};
|
||||
var $author$project$Main$canSelectIn = function (mode) {
|
||||
var $author$project$Modes$canSelectIn = function (mode) {
|
||||
switch (mode.$) {
|
||||
case 'Sell':
|
||||
return true;
|
||||
@@ -7545,7 +7569,7 @@ var $author$project$Main$rowControlsForMode = F3(
|
||||
A2(
|
||||
$elm$core$List$cons,
|
||||
itemInfo,
|
||||
$author$project$Main$canSelectIn(mode) ? _List_fromArray(
|
||||
$author$project$Modes$canSelectIn(mode) ? _List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$html$Html$input,
|
||||
|
||||
98
src/Api.elm
98
src/Api.elm
@@ -2,9 +2,11 @@ module Api exposing (..)
|
||||
|
||||
import Http
|
||||
import Json.Decode as D
|
||||
import Json.Decode exposing (Decoder, int, string)
|
||||
import Json.Decode exposing (Decoder, int, string, field, succeed)
|
||||
import Json.Encode as E
|
||||
|
||||
import Modes exposing (ViewMode)
|
||||
|
||||
type alias HttpResult a = (Result Http.Error a)
|
||||
|
||||
type alias Response =
|
||||
@@ -28,6 +30,51 @@ type Msg
|
||||
| GotLoot ToChest (HttpResult Loot)
|
||||
| GotActionResult (HttpResult Response)
|
||||
|
||||
|
||||
---
|
||||
-- MODELS
|
||||
---
|
||||
|
||||
-- Player
|
||||
|
||||
type alias Player =
|
||||
{ id: Int
|
||||
, name: String
|
||||
, debt: Int
|
||||
, wealth: Wealth
|
||||
}
|
||||
|
||||
blankPlayer =
|
||||
Player 0 "Loot-a-lot" 0 (Wealth 0 0 0 0)
|
||||
|
||||
|
||||
type alias Wealth =
|
||||
{ cp: Int
|
||||
, sp: Int
|
||||
, gp: Int
|
||||
, pp: Int
|
||||
}
|
||||
|
||||
-- Loot
|
||||
|
||||
type alias Loot = List Item
|
||||
|
||||
type alias Item =
|
||||
{ id: Int
|
||||
, name: String
|
||||
, base_price: Int
|
||||
}
|
||||
|
||||
-- Claims
|
||||
|
||||
type alias Claims = List Claim
|
||||
|
||||
type alias Claim =
|
||||
{ id: Int
|
||||
, player_id: Int
|
||||
, loot_id: Int
|
||||
}
|
||||
|
||||
-- PLAYERS
|
||||
--
|
||||
|
||||
@@ -35,7 +82,7 @@ fetchPlayer : Int -> Cmd Msg
|
||||
fetchPlayer id =
|
||||
Http.get
|
||||
{ url = "http://localhost:8088/api/players/" ++ (String.fromInt id) ++ "/"
|
||||
, expect = Http.expectJson Main.GotPlayer (valueDecoder playerDecoder )
|
||||
, expect = Http.expectJson GotPlayer (valueDecoder playerDecoder )
|
||||
}
|
||||
|
||||
playerDecoder : Decoder Player
|
||||
@@ -72,13 +119,13 @@ lootDecoder : Decoder Loot
|
||||
lootDecoder =
|
||||
Json.Decode.list itemDecoder
|
||||
|
||||
fetchLoot : Main.ToChest -> Cmd Msg
|
||||
fetchLoot : ToChest -> Cmd Msg
|
||||
fetchLoot dest =
|
||||
let
|
||||
url = case dest of
|
||||
Main.OfPlayer id -> "http://localhost:8088/api/players/" ++ (String.fromInt id) ++ "/loot"
|
||||
Main.OfShop -> "http://localhost:8088/api/items"
|
||||
Main.OfGroup -> "http://localhost:8088/api/players/0/loot"
|
||||
OfPlayer id -> "http://localhost:8088/api/players/" ++ (String.fromInt id) ++ "/loot"
|
||||
OfShop -> "http://localhost:8088/api/items"
|
||||
OfGroup -> "http://localhost:8088/api/players/0/loot"
|
||||
in
|
||||
Http.get
|
||||
{ url = url
|
||||
@@ -109,7 +156,7 @@ valueDecoder thenDecoder =
|
||||
-- TODO: update server to produce better json
|
||||
-- like an object with list of updates of the same type
|
||||
-- { ItemRemoved : [..], Wealth : [ .. ], .. }
|
||||
updatesDecoder : Decoder DbUpdate
|
||||
updatesDecoder : Decoder Update
|
||||
updatesDecoder =
|
||||
-- We expect one update but do not know it's kind
|
||||
Json.Decode.oneOf
|
||||
@@ -121,9 +168,9 @@ updatesDecoder =
|
||||
]
|
||||
|
||||
|
||||
apiResponseDecoder : Decoder ApiResponse
|
||||
apiResponseDecoder : Decoder Response
|
||||
apiResponseDecoder =
|
||||
Json.Decode.map4 ApiResponse
|
||||
Json.Decode.map4 Response
|
||||
(D.maybe (field "value" string))
|
||||
(Json.Decode.maybe (field "notification" string))
|
||||
(Json.Decode.maybe (field "updates" (Json.Decode.list updatesDecoder)))
|
||||
@@ -139,35 +186,40 @@ undoLastAction id = Http.request
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
sendRequest : Maybe ViewMode -> Model -> Cmd Msg
|
||||
sendRequest activeMode model =
|
||||
case activeMode of
|
||||
Nothing -> Cmd.none
|
||||
Just mode ->
|
||||
sendRequest : ViewMode -> String -> E.Value -> Cmd Msg
|
||||
sendRequest mode id payload =
|
||||
let
|
||||
(endpoint, method) = case mode of
|
||||
Add ->
|
||||
( "http://localhost:8088/api/players/" ++ (String.fromInt model.player.id) ++ "/loot"
|
||||
Modes.Add ->
|
||||
( "http://localhost:8088/api/players/" ++ id ++ "/loot"
|
||||
, "POST"
|
||||
)
|
||||
Buy ->
|
||||
( "http://localhost:8088/api/players/" ++ (String.fromInt model.player.id) ++ "/loot"
|
||||
Modes.Buy ->
|
||||
( "http://localhost:8088/api/players/" ++ id ++ "/loot"
|
||||
, "PUT"
|
||||
)
|
||||
Sell ->
|
||||
( "http://localhost:8088/api/players/" ++ (String.fromInt model.player.id) ++ "/loot"
|
||||
Modes.Sell ->
|
||||
( "http://localhost:8088/api/players/" ++ id ++ "/loot"
|
||||
, "DELETE"
|
||||
)
|
||||
Grab ->
|
||||
( "http://localhost:8088/api/players/" ++ (String.fromInt model.player.id) ++ "/claims"
|
||||
Modes.Grab ->
|
||||
( "http://localhost:8088/api/players/" ++ id ++ "/claims"
|
||||
, "POST")
|
||||
in
|
||||
Http.request
|
||||
{ method = method
|
||||
, headers = []
|
||||
, url = endpoint
|
||||
, body = Http.jsonBody <| buildPayload mode model
|
||||
, body = Http.jsonBody payload
|
||||
, expect = Http.expectJson GotActionResult apiResponseDecoder
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
|
||||
printError : Http.Error -> String
|
||||
printError error =
|
||||
case error of
|
||||
Http.NetworkError -> "Le serveur ne répond pas"
|
||||
_ -> "Erreur inconnue"
|
||||
|
||||
154
src/Main.elm
154
src/Main.elm
@@ -9,8 +9,10 @@ import Html.Events exposing (..)
|
||||
import Svg.Attributes
|
||||
import Url.Parser as P exposing (Parser, (</>), oneOf, s)
|
||||
import Set exposing (Set)
|
||||
import Json.Encode as E
|
||||
|
||||
import Api
|
||||
import Api exposing (Player, Loot, Wealth, Item, Claim, Claims)
|
||||
import Modes exposing (ViewMode)
|
||||
|
||||
-- Main
|
||||
|
||||
@@ -57,7 +59,7 @@ init flags url key =
|
||||
in
|
||||
( Model
|
||||
(State key route "" False Nothing Nothing)
|
||||
blankPlayer
|
||||
Api.blankPlayer
|
||||
[]
|
||||
Nothing
|
||||
Nothing
|
||||
@@ -74,57 +76,13 @@ fetchInitialData playerId =
|
||||
, Cmd.map ApiMsg <| Api.fetchLoot Api.OfGroup
|
||||
]
|
||||
|
||||
---
|
||||
-- MODELS
|
||||
---
|
||||
|
||||
-- Player
|
||||
|
||||
type alias Player =
|
||||
{ id: Int
|
||||
, name: String
|
||||
, debt: Int
|
||||
, wealth: Wealth
|
||||
}
|
||||
|
||||
blankPlayer =
|
||||
Player 0 "Loot-a-lot" 0 (Wealth 0 0 0 0)
|
||||
|
||||
|
||||
initPlayer id =
|
||||
Cmd.batch
|
||||
[ Cmd.map ApiMsg <| Api.fetchPlayer id
|
||||
, Cmd.map ApiMsg <| Api.fetchLoot (OfPlayer id)
|
||||
, Cmd.map ApiMsg <| Api.fetchLoot (Api.OfPlayer id)
|
||||
, Cmd.map ApiMsg <| Api.fetchClaims id
|
||||
]
|
||||
|
||||
type alias Wealth =
|
||||
{ cp: Int
|
||||
, sp: Int
|
||||
, gp: Int
|
||||
, pp: Int
|
||||
}
|
||||
|
||||
-- Loot
|
||||
|
||||
type alias Loot = List Item
|
||||
|
||||
type alias Item =
|
||||
{ id: Int
|
||||
, name: String
|
||||
, base_price: Int
|
||||
}
|
||||
|
||||
-- Claims
|
||||
|
||||
type alias Claims = List Claim
|
||||
|
||||
type alias Claim =
|
||||
{ id: Int
|
||||
, player_id: Int
|
||||
, loot_id: Int
|
||||
}
|
||||
|
||||
-- UPDATE
|
||||
|
||||
type Msg
|
||||
@@ -160,7 +118,7 @@ update msg model =
|
||||
{ model | state = { state | route = page }}
|
||||
|> update (case page of
|
||||
-- Directly enter add mode on NewLoot view
|
||||
NewLoot -> ModeSwitched (Just Add)
|
||||
NewLoot -> ModeSwitched (Just Modes.Add)
|
||||
other -> ModeSwitched Nothing
|
||||
)
|
||||
|
||||
@@ -168,10 +126,10 @@ update msg model =
|
||||
( setError "Invalid route" model, Cmd.none )
|
||||
|
||||
PlayerChanged newId ->
|
||||
( { model | player = blankPlayer }, initPlayer newId )
|
||||
( { model | player = Api.blankPlayer }, initPlayer newId )
|
||||
|
||||
ApiMsg apiMsg -> case apiMsg of
|
||||
GotActionResult response ->
|
||||
Api.GotActionResult response ->
|
||||
case response of
|
||||
Ok result ->
|
||||
let
|
||||
@@ -185,23 +143,23 @@ update msg model =
|
||||
|> update (ModeSwitched Nothing)
|
||||
Err r -> (setError (Debug.toString r) model, Cmd.none)
|
||||
|
||||
GotPlayer result ->
|
||||
Api.GotPlayer result ->
|
||||
case result of
|
||||
Ok player ->
|
||||
( { model | player = player }
|
||||
, Cmd.none
|
||||
)
|
||||
Err error ->
|
||||
( setError ("Fetching player... " ++ printError error) model
|
||||
( setError ("Fetching player... " ++ Debug.toString error) model
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
GotClaims id result ->
|
||||
Api.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 ->
|
||||
Api.GotLoot dest result ->
|
||||
case result of
|
||||
Ok loot ->
|
||||
( case dest of
|
||||
@@ -211,7 +169,7 @@ update msg model =
|
||||
, Cmd.none
|
||||
)
|
||||
Err error ->
|
||||
( setError ("Fetching loot... " ++ printError error) model
|
||||
( setError ("Fetching loot... " ++ Debug.toString error) model
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
@@ -235,7 +193,7 @@ update msg model =
|
||||
Nothing ->
|
||||
Nothing
|
||||
|
||||
Just Grab -> -- Currently claimed object are initially selected
|
||||
Just Modes.Grab -> -- Currently claimed object are initially selected
|
||||
Just ( Set.fromList <| List.map (\c -> c.loot_id) model.claims)
|
||||
|
||||
Just others ->
|
||||
@@ -244,13 +202,14 @@ update msg model =
|
||||
, Cmd.none )
|
||||
|
||||
ConfirmAction ->
|
||||
let
|
||||
currentMode = model.state.activeMode
|
||||
in
|
||||
(model, Cmd.map ApiMsg Api.sendRequest currentMode model)
|
||||
case model.state.activeMode of
|
||||
Nothing ->
|
||||
update (ModeSwitched Nothing) model
|
||||
Just mode ->
|
||||
(model, Cmd.map ApiMsg <| Api.sendRequest mode (String.fromInt model.player.id) (buildPayload mode model))
|
||||
|
||||
UndoLastAction ->
|
||||
(model, Cmd.map ApiMsg Api.undoLastAction model.player.id)
|
||||
(model, Cmd.map ApiMsg <| Api.undoLastAction model.player.id)
|
||||
|
||||
ClearNotification ->
|
||||
( { model | notification = Nothing }, Cmd.none )
|
||||
@@ -262,10 +221,10 @@ setNotification notification model =
|
||||
targetItemsFor : ViewMode -> Model -> List Item
|
||||
targetItemsFor mode model =
|
||||
case mode of
|
||||
Add -> []
|
||||
Buy -> Maybe.withDefault [] model.merchantItems
|
||||
Sell ->Maybe.withDefault [] model.loot
|
||||
Grab -> Maybe.withDefault [] model.groupLoot
|
||||
Modes.Add -> []
|
||||
Modes.Buy -> Maybe.withDefault [] model.merchantItems
|
||||
Modes.Sell ->Maybe.withDefault [] model.loot
|
||||
Modes.Grab -> Maybe.withDefault [] model.groupLoot
|
||||
|
||||
buildPayload : ViewMode -> Model -> E.Value
|
||||
buildPayload mode model =
|
||||
@@ -274,40 +233,33 @@ buildPayload mode model =
|
||||
|> List.filter (itemInSelection model.state.selection)
|
||||
in
|
||||
case mode of
|
||||
Buy -> E.object
|
||||
Modes.Buy -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.list identity [E.int i.id, E.null]))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
Sell -> E.object
|
||||
Modes.Sell -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.list identity [E.int i.id, E.null]))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
Grab -> E.object
|
||||
Modes.Grab -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.int i.id))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
Add -> E.object
|
||||
Modes.Add -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.int i.id))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
|
||||
type DbUpdate
|
||||
= ItemRemoved Item
|
||||
| ItemAdded Item
|
||||
| WealthUpdated Wealth
|
||||
| ClaimAdded ()
|
||||
| ClaimRemoved ()
|
||||
|
||||
-- DbUpdates always refer to the active player's loot
|
||||
applyUpdate : DbUpdate -> Model -> Model
|
||||
applyUpdate : Api.Update -> Model -> Model
|
||||
applyUpdate u model =
|
||||
case u of
|
||||
ItemRemoved item -> { model | loot = Just
|
||||
Api.ItemRemoved item -> { model | loot = Just
|
||||
<| List.filter (\i -> i.id /= item.id)
|
||||
<| Maybe.withDefault [] model.loot }
|
||||
ItemAdded item -> { model | loot = Just
|
||||
Api.ItemAdded item -> { model | loot = Just
|
||||
<| item :: Maybe.withDefault [] model.loot }
|
||||
WealthUpdated diff ->
|
||||
Api.WealthUpdated diff ->
|
||||
let
|
||||
player = model.player
|
||||
wealth = player.wealth
|
||||
@@ -319,8 +271,8 @@ applyUpdate u model =
|
||||
(wealth.gp + diff.gp)
|
||||
(wealth.pp + diff.pp)
|
||||
)}}
|
||||
ClaimAdded _ -> model
|
||||
ClaimRemoved _ -> model
|
||||
Api.ClaimAdded _ -> model
|
||||
Api.ClaimRemoved _ -> model
|
||||
|
||||
|
||||
-- ERRORS
|
||||
@@ -334,12 +286,6 @@ setError error model =
|
||||
{ state | error = error }}
|
||||
|
||||
|
||||
printError : Http.Error -> String
|
||||
printError error =
|
||||
case error of
|
||||
Http.NetworkError -> "Le serveur ne répond pas"
|
||||
_ -> "Erreur inconnue"
|
||||
|
||||
-- STATE Utils
|
||||
|
||||
switchSelectionState : Int -> Maybe Selection -> Maybe Selection
|
||||
@@ -362,20 +308,6 @@ subscriptions _ =
|
||||
-- VIEWS
|
||||
---
|
||||
|
||||
type ViewMode
|
||||
= Sell
|
||||
| Buy
|
||||
| Grab
|
||||
| Add
|
||||
|
||||
canSelectIn : ViewMode -> Bool
|
||||
canSelectIn mode =
|
||||
case mode of
|
||||
Sell -> True
|
||||
Buy -> True
|
||||
Grab -> True
|
||||
Add -> False
|
||||
|
||||
actionButton msg t icon color =
|
||||
button [ class <| "button level-item is-" ++ color
|
||||
, onClick msg ]
|
||||
@@ -392,10 +324,10 @@ controlsWhenModeActive mode =
|
||||
controlsWhenRoute : Route -> List (Html Msg)
|
||||
controlsWhenRoute route =
|
||||
case route of
|
||||
PlayerChest -> [actionButton (ModeSwitched (Just Sell)) "Vendre" "coins" "danger"]
|
||||
GroupLoot -> [actionButton (ModeSwitched (Just Grab)) "Demander" "praying-hands" "primary"]
|
||||
Merchant -> [actionButton (ModeSwitched (Just Buy)) "Acheter" "coins" "success"]
|
||||
NewLoot -> [actionButton (ModeSwitched (Just Add)) "Nouveau loot" "plus" "primary"]
|
||||
PlayerChest -> [actionButton (ModeSwitched (Just Modes.Sell)) "Vendre" "coins" "danger"]
|
||||
GroupLoot -> [actionButton (ModeSwitched (Just Modes.Grab)) "Demander" "praying-hands" "primary"]
|
||||
Merchant -> [actionButton (ModeSwitched (Just Modes.Buy)) "Acheter" "coins" "success"]
|
||||
NewLoot -> [actionButton (ModeSwitched (Just Modes.Add)) "Nouveau loot" "plus" "primary"]
|
||||
|
||||
view : Model -> Browser.Document Msg
|
||||
view model =
|
||||
@@ -487,14 +419,14 @@ rowControlsForMode : ViewMode -> (Item -> Bool) -> Item -> Html Msg
|
||||
rowControlsForMode mode isSelected item =
|
||||
let
|
||||
itemInfo = case mode of
|
||||
Buy -> p [class "level-item"] [ text (String.fromInt item.base_price ++ "po")]
|
||||
Sell -> p [class "level-item"] [ text (String.fromFloat (toFloat item.base_price / 2) ++ "po")]
|
||||
Grab -> p [class "level-item"] [ text "Grab" ]
|
||||
Add -> p [class "level-item"] [ text "New !" ]
|
||||
Modes.Buy -> p [class "level-item"] [ text (String.fromInt item.base_price ++ "po")]
|
||||
Modes.Sell -> p [class "level-item"] [ text (String.fromFloat (toFloat item.base_price / 2) ++ "po")]
|
||||
Modes.Grab -> p [class "level-item"] [ text "Grab" ]
|
||||
Modes.Add -> p [class "level-item"] [ text "New !" ]
|
||||
in
|
||||
div [ class "level-right" ]
|
||||
<| itemInfo
|
||||
:: if canSelectIn mode then
|
||||
:: if Modes.canSelectIn mode then
|
||||
[input [ class "checkbox level-item"
|
||||
, type_ "checkbox"
|
||||
, checked <| isSelected item
|
||||
|
||||
Reference in New Issue
Block a user