Skip to content

Commit

Permalink
#42 use indexeddb storage, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
L3P3 committed Feb 3, 2024
1 parent 5d144a8 commit c1a43ba
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 80 deletions.
3 changes: 2 additions & 1 deletion app-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<title>Minicraft (Roh)</title>
<meta name=viewport content="width=device-width">
<link rel=stylesheet href=src/app.css>
<link rel="shortcut icon" href=assets/logo.svg>
</head>
<body>
<script type=module src=https://cdn.jsdelivr.net/gh/L3P3/lui@dist/lui.dev.js></script>
<script type=module src=src/app.js></script>
<script>
window.ASSETS = '/assets/';
window.ASSETS = 'assets/';
</script>
</body>
</html>
3 changes: 2 additions & 1 deletion app-prod.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<title>Minicraft (Gebaut)</title>
<meta name=viewport content="width=device-width">
<link rel=stylesheet href=dist/app.css>
<link rel="shortcut icon" href=assets/logo.svg>
</head>
<body>
<script defer src=https://cdn.jsdelivr.net/gh/L3P3/lui@dist/lui.dev.js></script>
<script defer src=dist/app-de.js></script>
<script>
window.ASSETS = '/assets/';
window.ASSETS = 'assets/';
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions locales/ru.csv
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ modification: Изменения
mouse_mode_normal: Классический режим компьютерной мышки.
mouse_mode_selection: Выборь с компьютерной мышки.
mouse_sensitivity: Чуствительность компьютерной мышки.
e_existing_world: Новое имя мира:\n(макс. 16 символов)
name_existing_world: Новое имя мира:\n(макс. 16 символов)
name_new_world: Имя нового Мира:\n(макс. 16 симболов)
new_world: Новый мир
no: Нет
Expand Down Expand Up @@ -88,7 +88,7 @@ unknown_world: Неизвестный мир
unpublish_world: Приватизировать мир
upload_world_to_server: Загрузит мир на сервер
upload: Загрузит
version_1: Версия
version_1: Версия
version_2: от L3P3
view_angle: Радиус зрения
view_distance: Далность зрения
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minicraft",
"version": "0.9.8",
"version": "0.9.9",
"description": "voxel-based 3d game, written in javascript",
"homepage": "https://l3p3.de/minicraft",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ button {
.game .menu > .window > h2 {
margin: 0;
font-size: unset;
color: #666;
}
.game .menu.inventory > .window > .grid {
display: grid;
Expand Down
2 changes: 2 additions & 0 deletions src/etc/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export const String_fromCharCode = String.fromCharCode;

const Date_ = Date;
const JSON_ = JSON;
export const Promise_ = Promise;
export const JSON_stringify = JSON_.stringify;
export const JSON_parse = JSON_.parse;
export const localStorage_ = localStorage;
export const localStorage_getItem = key => localStorage_.getItem(key);
export const localStorage_setItem = localStorage_.setItem.bind(localStorage_);
export const localStorage_removeItem = localStorage_.removeItem.bind(localStorage_);
export const indexedDB_ = window_.indexedDB;
export const Uint8Array_ = Uint8Array;
export const Uint32Array_ = Uint32Array;
export const Map_ = Map;
Expand Down
33 changes: 29 additions & 4 deletions src/etc/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,39 @@ import {
import {
JSON_parse,
JSON_stringify,
Object_keys,
localStorage_,
localStorage_getItem,
localStorage_removeItem,
localStorage_setItem,
} from './helpers.js';
import {
locale_unknown_world,
locale_unknown_world_found,
} from './locale.js';

let config_loaded = localStorage_getItem('minicraft.config');
config_loaded = config_loaded && JSON_parse(config_loaded);

// HACK remove deleted worlds' chunks (i am so sorry)
if (
config_loaded &&
config_loaded['worlds'] &&
config_loaded['version'].startsWith('0.9.')
) {
const prefixes_keep = new Set(
config_loaded['worlds']
.map(world => 'minicraft.world.' + world.id)
);
for (const key of Object_keys(localStorage_))
if (
key.startsWith('minicraft.world.') &&
!prefixes_keep.has(key.split(':')[0])
) {
localStorage_removeItem(key);
}
}

export const reducers = {
init: () => {
let needs_save = false;
Expand All @@ -25,9 +50,7 @@ export const reducers = {
/** @type {!Array<TYPE_WORLD_LISTING_LOCAL>} */
worlds: [],
};
const config_raw = localStorage_getItem('minicraft.config');
if (config_raw) {
let config_loaded = JSON_parse(config_raw);
if (config_loaded) {
let tmp = config_loaded['flag_textures'];
if (tmp != null)
config.flag_textures = tmp;
Expand All @@ -44,8 +67,9 @@ export const reducers = {
config.world_last = tmp;
if ((
tmp = config_loaded['worlds']
) != null)
) != null) {
config.worlds = tmp;
}
else if (
localStorage_getItem('minicraft.world.0:meta')
) {
Expand All @@ -59,6 +83,7 @@ export const reducers = {
};
needs_save = true;
}
config_loaded = null;
}
const state = {
account: {
Expand Down
Loading

0 comments on commit c1a43ba

Please sign in to comment.