Updated field filter. Update room id -> hash -> seed
This commit is contained in:
parent
f631595cca
commit
908252d5d9
2 changed files with 26 additions and 7 deletions
|
|
@ -363,11 +363,28 @@
|
||||||
};
|
};
|
||||||
const byName = () => {
|
const byName = () => {
|
||||||
const q = m.inner.querySelector("#rq").value.trim().toLowerCase();
|
const q = m.inner.querySelector("#rq").value.trim().toLowerCase();
|
||||||
const hit = App.init.citizens.find((c) => c.name.toLowerCase() === q);
|
|
||||||
out.innerHTML = hit
|
if (!q) {
|
||||||
? ""
|
out.innerHTML = '<p class="dim small">— Введіть ім\'я або прізвище.</p>';
|
||||||
: '<p class="dim small">— Записів не знайдено. Перевірте написання.</p>';
|
return;
|
||||||
if (hit) draw([hit]);
|
}
|
||||||
|
|
||||||
|
// Розбиваємо введений запит на слова
|
||||||
|
const words = q.split(/\s+/);
|
||||||
|
|
||||||
|
// Фільтруємо: кожне введене слово має збігатися з початком якогось слова в імені громадянина
|
||||||
|
const hits = App.init.citizens.filter((c) => {
|
||||||
|
const nameWords = c.name.toLowerCase().split(/\s+/);
|
||||||
|
return words.every((w) => nameWords.some((nw) => nw.startsWith(w)));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hits.length) {
|
||||||
|
out.innerHTML = '<p class="dim small">— Записів не знайдено. Спробуйте інший початок.</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
out.innerHTML = "";
|
||||||
|
draw(hits);
|
||||||
};
|
};
|
||||||
const byFilter = () => {
|
const byFilter = () => {
|
||||||
const v = (id) => m.inner.querySelector(id).value;
|
const v = (id) => m.inner.querySelector(id).value;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ const http = require('http');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
const crypto = require('crypto');
|
||||||
const { WebSocketServer } = require('ws');
|
const { WebSocketServer } = require('ws');
|
||||||
const { generateCase, checkAccusation, md5 } = require('./casegen');
|
const { generateCase, checkAccusation, md5 } = require('./casegen');
|
||||||
const { unitBuilding } = require('./casegen/district');
|
const { unitBuilding } = require('./casegen/district');
|
||||||
|
|
@ -39,8 +40,9 @@ function seedRand(seed) {
|
||||||
|
|
||||||
function getSession(code) {
|
function getSession(code) {
|
||||||
if (sessions[code]) return sessions[code];
|
if (sessions[code]) return sessions[code];
|
||||||
const cs = generateCase(code);
|
const hashedCode = crypto.createHash('sha512').update(code).digest('hex');
|
||||||
const rng = seedRand([...code].reduce((a, c) => a * 31 + c.charCodeAt(0), 0)); // детермінований rand
|
const cs = generateCase(hashedCode);
|
||||||
|
const rng = seedRand([...hashedCode].reduce((a, c) => a * 31 + c.charCodeAt(0), 0));
|
||||||
const stn = cs.district.buildings.find(b => b.id === 'station');
|
const stn = cs.district.buildings.find(b => b.id === 'station');
|
||||||
const s = {
|
const s = {
|
||||||
code, cs,
|
code, cs,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue