Add game_ownership (schema v10) and tools/check_ownership.py, compare the local library with GetOwnedGames, expose owned/shared counts and filters, and show a shared-game badge on cards.
This commit is contained in:
1 parent
528fcb7474
commit
2ed00b7912
18 files changed
+255
-10
No files matched your search
+21
-3
@@ -555,6 +555,7 @@ def serialize(r, tags, genres, details):
|
||||
"complete": r["hltb_complete"] if "hltb_complete" in r.keys() else None,
|
||||
} if "hltb_main" in r.keys() and r["hltb_main"] else None,
|
||||
"installed": bool(r["installed"]),
|
||||
"owned": r["owned"] if "owned" in r.keys() else None,
|
||||
"status": r["status"],
|
||||
"rating": r["rating"],
|
||||
"favorite": bool(r["favorite"]),
|
||||
@@ -617,6 +618,11 @@ def game_filters(qs):
|
||||
where.append(f"""EXISTS (SELECT 1 FROM game_tags gt JOIN tag_names tn ON tn.tag_id=gt.tag_id
|
||||
WHERE gt.appid=g.appid AND tn.name IN ({placeholders}))""")
|
||||
params.extend(tags)
|
||||
ownership = q("ownership")
|
||||
if ownership == "owned":
|
||||
where.append("o.owned = 1")
|
||||
elif ownership == "shared":
|
||||
where.append("o.owned = 0")
|
||||
if q("status"):
|
||||
where.append("COALESCE(pe.status,'backlog') = ?")
|
||||
params.append(q("status"))
|
||||
@@ -1121,6 +1127,11 @@ class Handler(BaseHTTPRequestHandler):
|
||||
hltb_matched = con.execute(
|
||||
"""SELECT COUNT(*) FROM games WHERE LOWER(type)='game'
|
||||
AND hltb_match = 1""").fetchone()[0]
|
||||
ownership = con.execute(
|
||||
"""SELECT COALESCE(SUM(CASE WHEN o.owned=1 THEN 1 ELSE 0 END), 0) AS owned,
|
||||
COALESCE(SUM(CASE WHEN o.owned=0 THEN 1 ELSE 0 END), 0) AS shared
|
||||
FROM game_ownership o JOIN games g ON g.appid=o.appid
|
||||
WHERE LOWER(g.type)='game'""").fetchone()
|
||||
self._json({
|
||||
"total": total, "installed": installed, "played": played,
|
||||
"hours": round(minutes / 60), "cached": cached, "missing": missing,
|
||||
@@ -1129,6 +1140,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"genres": genres, "tags": tags, "statuses": statuses,
|
||||
"signals": signals, "hltb_checked": hltb_checked,
|
||||
"hltb_matched": hltb_matched,
|
||||
"owned": ownership["owned"], "shared": ownership["shared"],
|
||||
"steam_api": bool(steam_api.has_key() and steam_api.steam_id(con)),
|
||||
})
|
||||
finally:
|
||||
@@ -1144,6 +1156,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
LEFT JOIN game_install i ON i.appid=g.appid
|
||||
LEFT JOIN personal pe ON pe.appid=g.appid
|
||||
LEFT JOIN game_details d ON d.appid=g.appid
|
||||
LEFT JOIN game_ownership o ON o.appid=g.appid
|
||||
WHERE {' AND '.join(where)}"""
|
||||
con = connect()
|
||||
try:
|
||||
@@ -1153,7 +1166,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
g.estimated_hours, g.hltb_main, g.hltb_extra, g.hltb_complete,
|
||||
COALESCE(p.minutes,0) minutes, COALESCE(i.installed,0) installed,
|
||||
COALESCE(pe.status,'backlog') status, pe.rating,
|
||||
COALESCE(pe.favorite,0) favorite, pe.notes
|
||||
COALESCE(pe.favorite,0) favorite, pe.notes, o.owned
|
||||
{base} ORDER BY {order} LIMIT ? OFFSET ?""",
|
||||
[*params, per_page, (page - 1) * per_page]).fetchall()
|
||||
ids = [r["appid"] for r in rows]
|
||||
@@ -1231,6 +1244,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
LEFT JOIN game_install i ON i.appid=g.appid
|
||||
LEFT JOIN personal pe ON pe.appid=g.appid
|
||||
LEFT JOIN game_details d ON d.appid=g.appid
|
||||
LEFT JOIN game_ownership o ON o.appid=g.appid
|
||||
WHERE {' AND '.join(where)}"""
|
||||
con = connect()
|
||||
try:
|
||||
@@ -1239,7 +1253,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
g.estimated_hours, COALESCE(p.minutes,0) minutes, p.last_played,
|
||||
COALESCE(i.installed,0) installed, i.size_bytes,
|
||||
COALESCE(pe.status,'backlog') status, pe.rating,
|
||||
COALESCE(pe.favorite,0) favorite
|
||||
COALESCE(pe.favorite,0) favorite, o.owned
|
||||
{base} ORDER BY {order}""", params).fetchall()
|
||||
ids = [row["appid"] for row in rows]
|
||||
tags = game_tags_map(con, ids)
|
||||
@@ -1263,6 +1277,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"rating": row["rating"],
|
||||
"favorite": bool(row["favorite"]),
|
||||
"installed": bool(row["installed"]),
|
||||
"owned": row["owned"],
|
||||
"size_gb": round((row["size_bytes"] or 0) / (1024 ** 3), 2),
|
||||
"last_played": row["last_played"],
|
||||
"genres": genres.get(row["appid"], []),
|
||||
@@ -1305,11 +1320,13 @@ class Handler(BaseHTTPRequestHandler):
|
||||
COALESCE(p.minutes,0) minutes, p.last_played,
|
||||
COALESCE(i.installed,0) installed, i.size_bytes,
|
||||
COALESCE(pe.status,'backlog') status, pe.rating,
|
||||
COALESCE(pe.favorite,0) favorite, pe.notes
|
||||
COALESCE(pe.favorite,0) favorite, pe.notes,
|
||||
o.owned, o.checked_at AS ownership_checked_at
|
||||
FROM games g
|
||||
JOIN game_playtime p ON p.appid=g.appid
|
||||
LEFT JOIN game_install i ON i.appid=g.appid
|
||||
LEFT JOIN personal pe ON pe.appid=g.appid
|
||||
LEFT JOIN game_ownership o ON o.appid=g.appid
|
||||
WHERE g.appid = ?""", (appid,)).fetchone()
|
||||
if not r:
|
||||
self._error(404, "unknown appid")
|
||||
@@ -1325,6 +1342,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
item.update({
|
||||
"size_gb": round((r["size_bytes"] or 0) / (1024 ** 3), 1),
|
||||
"last_played": r["last_played"],
|
||||
"ownership_checked_at": r["ownership_checked_at"],
|
||||
"about": (d["about_ru"] or d["about"]) if d else None,
|
||||
"steam_url": f"https://store.steampowered.com/app/{appid}/",
|
||||
})
|
||||
|
||||
+8
-2
@@ -19,7 +19,7 @@ let coldStartManual = false;
|
||||
function defaultFilters() {
|
||||
return {
|
||||
status: "", genres: [], tags: [], installed: false, unplayed: false, favorite: false,
|
||||
duration: "", minHours: "", maxHours: "", minYear: "", maxYear: "",
|
||||
ownership: "", duration: "", minHours: "", maxHours: "", minYear: "", maxYear: "",
|
||||
minReview: "", maxReview: "",
|
||||
};
|
||||
}
|
||||
@@ -273,6 +273,9 @@ function cardHtml(g, mode = "library") {
|
||||
? `<span class="badge score">${g.score}</span>`
|
||||
: (g.review != null ? `<span class="badge review ${g.review < 85 ? "warn" : ""}">${g.review}%</span>` : "");
|
||||
const installed = g.installed ? `<span class="badge installed" title="установлена">●</span>` : "";
|
||||
const shared = g.owned === 0
|
||||
? `<span class="badge shared" title="Не в списке владения (возможно, семейная)">семейная</span>`
|
||||
: "";
|
||||
const selectBox = mode === "library" && state.selectionMode
|
||||
? `<label class="select-box" title="Выбрать игру"><input type="checkbox" value="${g.appid}" data-select="${g.appid}"${state.selected.has(g.appid) ? " checked" : ""} aria-label="Выбрать игру"></label>`
|
||||
: "";
|
||||
@@ -304,7 +307,7 @@ function cardHtml(g, mode = "library") {
|
||||
<img data-appid="${g.appid}" loading="lazy" width="300" height="450"
|
||||
src="${coverUrl(g.appid)}" alt="">
|
||||
<div class="fallback">${esc(initials(g.name))}</div>
|
||||
${review}${installed}${selectBox}
|
||||
${review}${installed}${shared}${selectBox}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title">${esc(g.name)}</h3>
|
||||
@@ -667,6 +670,7 @@ function syncFilterControls() {
|
||||
$("#search").value = state.q;
|
||||
$("#sort").value = state.sort;
|
||||
$("#fStatus").value = state.filters.status;
|
||||
$("#fOwnership").value = state.filters.ownership;
|
||||
$("#fDuration").value = state.filters.duration;
|
||||
$("#fInstalled").checked = !!state.filters.installed;
|
||||
$("#fUnplayed").checked = !!state.filters.unplayed;
|
||||
@@ -880,6 +884,7 @@ function filterParams() {
|
||||
if (state.filters.installed) p.set("installed", "1");
|
||||
if (state.filters.unplayed) p.set("unplayed", "1");
|
||||
if (state.filters.favorite) p.set("favorite", "1");
|
||||
if (state.filters.ownership) p.set("ownership", state.filters.ownership);
|
||||
if (state.filters.duration) p.set("duration", state.filters.duration);
|
||||
p.set("dir", state.dir);
|
||||
[
|
||||
@@ -1728,6 +1733,7 @@ $("#sort").addEventListener("change", (e) => {
|
||||
});
|
||||
|
||||
$("#fStatus").addEventListener("change", (e) => { state.filters.status = e.target.value; loadGames(true); });
|
||||
$("#fOwnership").addEventListener("change", (e) => { state.filters.ownership = e.target.value; loadGames(true); });
|
||||
$("#fDuration").addEventListener("change", (e) => { state.filters.duration = e.target.value; loadGames(true); });
|
||||
let rangeTimer = null;
|
||||
document.querySelectorAll("[data-filter]").forEach((input) => {
|
||||
|
||||
@@ -98,6 +98,15 @@ try {
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="field">
|
||||
<span>Владение</span>
|
||||
<select id="fOwnership">
|
||||
<option value="">любое</option>
|
||||
<option value="owned">личные</option>
|
||||
<option value="shared">не в списке владения</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<div class="field">
|
||||
<span>Жанры</span>
|
||||
<details class="multi-select" id="genreSelect">
|
||||
|
||||
@@ -681,6 +681,7 @@ html[data-theme="light"] .game-table tbody tr:hover { background: rgba(23, 32, 5
|
||||
.badge.review { top: 8px; left: 8px; color: #b8f5e9; }
|
||||
.badge.review.warn { color: #ffd59a; }
|
||||
.badge.installed { top: 8px; right: 8px; color: var(--accent-2); }
|
||||
.badge.shared { top: 34px; right: 8px; color: #f5b8c9; font-size: 10px; }
|
||||
.badge.score { top: 8px; left: 8px; color: #0a0d13; background: linear-gradient(135deg, var(--accent), #ffd59a); border: 0; }
|
||||
|
||||
.card-body { display: flex; flex-direction: column; gap: 7px; padding: 11px 12px 13px; }
|
||||
|
||||
Reference in new issue
Block a user