Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Base improvements #635

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2540,13 +2540,13 @@ class=
<div
class=
"form-el--required col col-1-2 el--block-label el--full-text">
<label>{tr('Keep Points')}</label>
<label>{tr('Capture Points')}</label>
<input name="points" type="text" />
</div>
<div
class=
"form-el--required col col-1-2 el--block-label el--full-text">
<label>{tr('Capture points')}</label>
<label>{tr('Keep points')}</label>
<input name="bonus" type="text" />
</div>
</div>
Expand Down Expand Up @@ -2894,7 +2894,7 @@ class=
<div
class=
"form-el--required col col-1-2 el--block-label el--full-text">
<label>{tr('Points')}</label>
<label>{tr('Capture Points')}</label>
<input
name="points"
type="text"
Expand All @@ -2903,7 +2903,7 @@ class=
/>
</div>
<div class="col col-1-2 el--block-label el--full-text">
<label>{tr('Bonus')}</label>
<label>{tr('Keep points')}</label>
<input
name="bonus"
type="text"
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/modals/CountryModalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class=
<div class="points-display">
<span class="points-number fb-numbers"></span>
<span class="points-label">{tr('PTS')}</span>
<span class="base-points completely-hidden">{tr('Capture')}</span>
</div>
<div class="bonus-display completely-hidden">
<span class="bonus-number fb-numbers"></span>
<span class="bonus-label">{tr('PTS')}</span>
<span class="base-bonus">{tr('Hold')}</span>
</div>
<div class="country-stats">
<dl>
Expand Down Expand Up @@ -241,6 +247,12 @@ class=
<div class="points-display">
<span class="points-number fb-numbers"></span>
<span class="points-label">{tr('PTS')}</span>
<span class="base-points completely-hidden">{tr('Capture')}</span>
</div>
<div class="bonus-display completely-hidden">
<span class="bonus-number fb-numbers"></span>
<span class="bonus-label">{tr('PTS')}</span>
<span class="base-bonus">{tr('Hold')}</span>
</div>
<div class="country-stats">
<dl>
Expand Down
2 changes: 1 addition & 1 deletion src/inc/gameboard/modules/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ActivityModuleController extends ModuleController {
$activity_ul = <ul class="activity-stream"></ul>;

list($all_activity, $config) = await \HH\Asio\va(
ActivityLog::genAllActivity(),
ActivityLog::genAllActivity(array('held')),
Configuration::gen('language'),
);
$language = $config->getValue();
Expand Down
6 changes: 6 additions & 0 deletions src/language/lang_en.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@
//Translations for inc/* and inc/gameboard/*
'captured' =>
'captured',
'held' =>
'held',
'Status' =>
'Status',
'Completed' =>
Expand Down Expand Up @@ -600,6 +602,10 @@
'INACTIVE',
'PTS' =>
'PTS',
'Capture' =>
'Capture',
'Hold' =>
'Hold',
'category' =>
'category',
'capture_' =>
Expand Down
25 changes: 23 additions & 2 deletions src/models/ActivityLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ private static function activitylogFromRow(
);
}

public static async function genHoldLog(
int $team_id,
int $level_id,
): Awaitable<void> {
$country_id = await Level::genCountryIdForLevel($level_id);
await self::genCreateActionLog(
"Team",
$team_id,
"held",
"Country",
$country_id,
);
}

public static async function genCreateActionLog(
string $subject_class,
int $subject_id,
Expand Down Expand Up @@ -278,14 +292,21 @@ private static function activitylogFromRow(
}

public static async function genAllActivity(
array<string> $exclude_actions = array(''),
bool $refresh = false,
): Awaitable<array<ActivityLog>> {
$mc_result = self::getMCRecords('ALL_ACTIVITY');
if (!$mc_result || count($mc_result) === 0 || $refresh) {
$excludes = new Vector();
foreach ($exclude_actions as $exclude) {
$excludes->add($exclude);
}

$db = await self::genDb();
$activity_log_lines = array();
$result = await $db->query(
'SELECT * FROM activity_log ORDER BY ts DESC LIMIT 100',
$result = await $db->queryf(
'SELECT * FROM activity_log WHERE action NOT IN (%Ls) ORDER BY ts DESC LIMIT 100',
$excludes
);
foreach ($result->mapRows() as $row) {
$activity_log = self::activitylogFromRow($row);
Expand Down
44 changes: 40 additions & 4 deletions src/models/Level.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,33 @@ private static function levelFromRow(Map<string, string> $row): Level {
public static async function importAll(
array<string, array<string, mixed>> $elements,
): Awaitable<bool> {
Utils::logMessage('Beginning import of '.count($elements).' levels');
foreach ($elements as $level) {
$title = must_have_string($level, 'title');
$type = must_have_string($level, 'type');
Utils::logMessage("> Importing $type level: $title");
$entity_iso_code = must_have_string($level, 'entity_iso_code');
$c = must_have_string($level, 'category');
$exist = await self::genAlreadyExist($type, $title, $entity_iso_code);
list($entity_exist, $category_exist) = await \HH\Asio\va(
Country::genCheckExists($entity_iso_code),
Category::genCheckExists($c),
); // TODO: Combine Awaits
if (!$exist && $entity_exist && $category_exist) {
if ($exist) {
Utils::logMessage('>> Level already exists');
} else if (!$entity_exist) {
Utils::logMessage(">> Country ($entity_iso_code) does not exist");
} else if (!$category_exist) {
Utils::logMessage(">> Category ($c) does not exist");
} else {
list($entity, $category) = await \HH\Asio\va(
Country::genCountry($entity_iso_code),
Category::genSingleCategoryByName($c),
); // TODO: Combine Awaits

// Handle previous versions
$level = self::correctForVersion($level);

$level_id = await self::genCreate(
$type,
$title,
Expand All @@ -178,13 +190,15 @@ private static function levelFromRow(Map<string, string> $row): Level {
must_have_int($level, 'penalty'),
);
if (array_key_exists('links', $level)) {
Utils::logMessage('>> Importing links');
$links = must_have_idx($level, 'links');
invariant(is_array($links), 'links must be of type array');
foreach ($links as $link) {
await Link::genCreate($link, $level_id); // TODO: Combine Awaits
}
}
if (array_key_exists('attachments', $level)) {
Utils::logMessage('>> Importing attachments');
$attachments = must_have_idx($level, 'attachments');
invariant(
is_array($attachments),
Expand All @@ -198,11 +212,29 @@ private static function levelFromRow(Map<string, string> $row): Level {
); // TODO: Combine Awaits
}
}
Utils::logMessage('>> Success');
}
}
return true;
}

private static function correctForVersion(
array<string, mixed> $level
): array<string, mixed> {
$version = (isset($level['version']) && !is_null($level['version'])) ? $level['version'] : 1;
// base versions < 2.0 had bonus & points reversed
if ($level['type'] === 'base' && $version < 2) {
Utils::logMessage('>> Base version is < 2. Correcting data.');
$capture_points = $level['bonus'];
$hold_points = $level['points'];
$level['points'] = $capture_points;
$level['bonus'] = $hold_points;
$level['bonus_fix'] = $hold_points;
}

return $level;
}

// Export levels.
public static async function exportAll(
): Awaitable<array<string, array<string, mixed>>> {
Expand Down Expand Up @@ -244,6 +276,7 @@ private static function levelFromRow(Map<string, string> $row): Level {
'penalty' => $level->getPenalty(),
'links' => $link_array,
'attachments' => $attachment_array,
'version' => 2.0
);
array_push($all_levels_data, $one_level);
}
Expand Down Expand Up @@ -1140,8 +1173,10 @@ private static function levelFromRow(Map<string, string> $row): Level {
$score =
await ScoreLog::genAllPreviousScore($level_id, $team_id, false);
if ($score) {
$points = $level->getPoints();
// If the team has already captured this base, only give the bonus
$points = $level->getBonus();
} else {
// Otherwise give capture points
$points = $level->getPoints() + $level->getBonus();
}

Expand All @@ -1153,7 +1188,7 @@ private static function levelFromRow(Map<string, string> $row): Level {
);

// Log the score...
await ScoreLog::genLogValidScore(
await ScoreLog::genLogBaseScore(
$level_id,
$team_id,
$points,
Expand Down Expand Up @@ -1232,7 +1267,8 @@ private static function levelFromRow(Map<string, string> $row): Level {
public static async function genBaseIP(int $base_id): Awaitable<string> {
$links = await Link::genAllLinks($base_id);
$link = $links[0];
$ip = explode(':', $link->getLink())[0];
$ip = preg_replace('$[a-zA-Z]+://$', '', $link->getLink());
$ip = explode(':', $ip)[0];

return $ip;
}
Expand Down
39 changes: 39 additions & 0 deletions src/models/ScoreLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,45 @@ private static function scorelogFromRow(Map<string, string> $row): ScoreLog {
return $captured;
}

// Log successful base capture or hold score.
public static async function genLogBaseScore(
int $level_id,
int $team_id,
int $points,
): Awaitable<bool> {
$completed_level = await MultiTeam::genCompletedLevel($level_id);
Utils::logMessage( "Teams who have completed level ($level_id): " . var_export($completed_level, true));
$captured = empty($completed_level) || end($completed_level)->getId() != $team_id;

$db = await self::genDb();
$result =
await $db->queryf(
'INSERT INTO scores_log (ts, level_id, team_id, points, type) SELECT NOW(), %d, %d, %d, %s FROM DUAL',
$level_id,
$team_id,
$points,
'base',
);

if ($captured === true) {
await ActivityLog::genCaptureLog($team_id, $level_id);
} else {
await ActivityLog::genHoldLog($team_id, $level_id);
}
self::invalidateMCRecords(); // Invalidate Memcached ScoreLog data.
ActivityLog::invalidateMCRecords('ALL_ACTIVITY'); // Invalidate Memcached ActivityLog data.
MultiTeam::invalidateMCRecords('ALL_TEAMS'); // Invalidate Memcached MultiTeam data.
MultiTeam::invalidateMCRecords('POINTS_BY_TYPE'); // Invalidate Memcached MultiTeam data.
MultiTeam::invalidateMCRecords('LEADERBOARD'); // Invalidate Memcached MultiTeam data.
$completed_level = await MultiTeam::genCompletedLevel($level_id);
if (count($completed_level) === 0) {
MultiTeam::invalidateMCRecords('TEAMS_FIRST_CAP'); // Invalidate Memcached MultiTeam data.
}
MultiTeam::invalidateMCRecords('TEAMS_BY_LEVEL'); // Invalidate Memcached MultiTeam data.

return $captured;
}

public static async function genScoreLogUpdate(
int $level_id,
int $team_id,
Expand Down
16 changes: 16 additions & 0 deletions src/static/css/scss/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@
}
}

/**
* --country modal
*/
.modal--country-capture {
// link display
.capture-links {
@include flexbox;
flex-wrap: wrap;

& > a,
& > input {
@include flex(1 0 100%);
}
}
}

/**
* --tutorial
*/
Expand Down
14 changes: 11 additions & 3 deletions src/static/css/scss/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ table {
/**
* --point circles
*/
.points-display {
.points-display,
.bonus-display {
@include flexbox;

@include align-center;
Expand All @@ -397,18 +398,25 @@ table {
width: 80px;
height: 80px;

.points-number {
.points-number,
.bonus-number {
font-size: 3em;
display: block;
line-height: 1;
}

.points-label {
.points-label,
.bonus-label {
font-size: .8em;
text-transform: uppercase;
}
}

.bonus-display {
margin-left: 10px;
margin-right: -10px;
}

/* --------------------------------------------
* inactive country
* -------------------------------------------- */
Expand Down
Loading