Skip to content

Commit

Permalink
add a flag to spoiler unit names (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlk authored Feb 11, 2025
1 parent 73cf712 commit bfc8030
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/modules/language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const langmap = {
Outdated: "Устаревшая",
Broken: "Сломанная",
"Black Holed": "Чёрная дыра",
"Spoiler Unit Names": "Названия споилированных единиц",

Key: "Ключ",
Value: "Значение",
Expand Down Expand Up @@ -315,6 +316,7 @@ const langmap = {
Outdated: "Desactualizado",
Broken: "Roto",
"Black Holed": "Arrojado a un agujero negro",
"Spoiler Unit Names": "Nombres de unidades de spoiler",

Key: "Clave",
Value: "Valor",
Expand Down Expand Up @@ -549,6 +551,7 @@ const langmap = {
Outdated: "시대에 뒤쳐진",
Broken: "고장난",
"Black Holed": "블랙홀",
"Spoiler Unit Names": "스플로러 유닛 이름",

"MPQ Hash": "MPQ 해시",
"MPQ Size": "MPQ 크기",
Expand Down Expand Up @@ -793,6 +796,7 @@ const langmap = {
Outdated: "過時",
Broken: "破壞",
"Black Holed": "已被黑洞吞噬",
"Spoiler Unit Names": "懷疑單位名稱",

Tags: "標籤",
Key: "鍵",
Expand Down
16 changes: 16 additions & 0 deletions app/pages/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ const Flags = (props: any) => {
const [outdated] = useApi(() => `/api/flags/${props.mapId}/outdated`);
const [broken] = useApi(() => `/api/flags/${props.mapId}/broken`);
const [blackholed] = useApi(() => `/api/flags/${props.mapId}/blackholed`);
const [spoiler_unit_names] = useApi(
() => `/api/flags/${props.mapId}/spoiler_unit_names`
);

const mutate = (mapId: string, key: string, value: boolean) => {
fetch(`/api/flags/${mapId}/${key}`, {
Expand Down Expand Up @@ -689,6 +692,19 @@ const Flags = (props: any) => {
<I18nSpan text="Black Holed" />
</label>
</div>
<div class={style.flag}>
<label for="checkbox_spoiler_unit_names">
<input
type="checkbox"
id="checkbox_spoiler_unit_names"
checked={spoiler_unit_names()}
onChange={(evt) => {
mutate(props.mapId, "spoiler_unit_names", evt.target.checked);
}}
/>
<I18nSpan text="Spoiler Unit Names" />
</label>
</div>
</div>
</Suspense>
);
Expand Down
4 changes: 4 additions & 0 deletions crates/bwmapserver/src/api/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async fn get_flag(
"outdated" => "select outdated from map where map.id = $1",
"broken" => "select broken from map where map.id = $1",
"blackholed" => "select blackholed from map where map.id = $1",
"spoiler_unit_names" => "select spoiler_unit_names from map where map.id = $1",
_ => return Ok(HttpResponse::NotFound().finish()),
};

Expand Down Expand Up @@ -85,6 +86,9 @@ async fn set_flag(
"blackholed" => {
"update map set blackholed = $1 where map.id = $2 and (map.uploaded_by = $3 or $3 = 4)"
}
"spoiler_unit_names" => {
"update map set spoiler_unit_names = $1 where map.id = $2 and (map.uploaded_by = $3 or $3 = 4)"
}
_ => return Ok(HttpResponse::NotFound().finish()),
};

Expand Down
15 changes: 10 additions & 5 deletions crates/bwmapserver/src/api/uiv2/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ async fn units(
bwcommon::get_db_id_from_web_id(&map_id, crate::util::SEED_MAP_ID)?
};

let chkblob = {
let (chkblob, spoiler_unit_names) = {
let con = pool.get().await?;
let row = con
.query_one(
"select length, ver, data
"select length, ver, data, spoiler_unit_names
from map
join chkblob on chkblob.hash = map.chkblob
where map.id = $1
Expand All @@ -43,7 +43,10 @@ async fn units(
let data = row.try_get::<_, Vec<u8>>("data")?;

bwcommon::ensure!(ver == 1);
zstd::bulk::decompress(data.as_slice(), length)?
(
zstd::bulk::decompress(data.as_slice(), length)?,
row.try_get::<_, bool>("spoiler_unit_names")?,
)
};

let info = ApiSpecificInfoForLogging {
Expand All @@ -59,8 +62,10 @@ async fn units(
if x.config[unit_id] == 0 && x.string_number[unit_id] != 0 {
v.push(json!({
"unit_id": unit_id,
"name": parsed_chk.get_string(x.string_number[unit_id] as usize)
.unwrap_or("couldn't decode string".to_owned()),
"name": if spoiler_unit_names { "SPOILER".to_owned() } else {
parsed_chk.get_string(x.string_number[unit_id] as usize)
.unwrap_or("couldn't decode string".to_owned())
},
}));
}
}
Expand Down
3 changes: 2 additions & 1 deletion postgres/00-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ psql -v ON_ERROR_STOP=1 --username "postgres" -d "bounding.net" <<-'EOSQL'
unfinished boolean DEFAULT false NOT NULL,
denorm_scenario text,
mapblob_size bigint NOT NULL,
blackholed boolean DEFAULT false NOT NULL
blackholed boolean DEFAULT false NOT NULL,
spoiler_unit_names bool DEFAULT false NOT NULL
);
Expand Down

0 comments on commit bfc8030

Please sign in to comment.