Skip to content
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
28 changes: 28 additions & 0 deletions local-storage/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ESLint config for MagicScript Apps
module.exports = {
env: {
"es6": true
},
globals: {
// These globals are provided by the vm itself.
"print": true,
"globalThis": true,
// The following globals are provided by `magic-script-polyfills`
"setTimeout": true,
"clearTimeout": true,
"setInterval": true,
"clearInterval": true,
"setImmediate": true,
"clearImmediate": true,
"fetch": true,
"Headers": true,
"Request": true,
"Response": true,

},
parserOptions: {
"ecmaVersion": 2018,
"sourceType": "module"
},
extends: "semistandard",
};
5 changes: 5 additions & 0 deletions local-storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.out/
/node_modules/
/bin/
!/bin/index.js
/digest.sha512.signed
5 changes: 5 additions & 0 deletions local-storage/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.out/
/node_modules/
/bin/
!/bin/index.js
/digest.sha512.signed
4 changes: 4 additions & 0 deletions local-storage/app.package
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DATAS = "digest.sha512.signed" : "." \
"res/" : "res/" \
"bin/" : "bin/"
OPTIONS = package/minApiLevel/2
17 changes: 17 additions & 0 deletions local-storage/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<manifest xmlns:ml="magicleap"
ml:package="com.magicscript.sample.local-storage"
ml:version_name="0.0.1"
ml:version_code="1">
<application ml:visible_name="LocalStorage Sample"
ml:sdk_version="1.0">
<component ml:name=".universe"
ml:visible_name="LocalStorage Sample"
ml:binary_name="bin/index.js"
ml:type="Universe">
<mode ml:shareable="true"/>
<icon ml:model_folder=""
ml:portal_folder=""/>
</component>
<uses-privilege ml:name="MagicScript"/>
</application>
</manifest>
26 changes: 26 additions & 0 deletions local-storage/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"scripts": {
"build": "rollup -c",
"start": "magic-script run"
},
"private": true,
"devDependencies": {
"eslint-config-semistandard": "^13.0.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"magic-script-typings": "^1.6.0",
"rollup": "^1.1.2",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-typescript": "^1.0.1",
"semistandard": "^13.0.1",
"tslib": "^1.10.0",
"typescript": "^3.6.4"
},
"dependencies": {
"magic-script-polyfills": "^2.8.0"
}
}
1 change: 1 addition & 0 deletions local-storage/res/.placeholder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder is a placeholder for app assets.
16 changes: 16 additions & 0 deletions local-storage/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Rollup config for consuming some npm modules in MagicScript

import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import typescript from 'rollup-plugin-typescript';

export default {
external: ['uv', 'lumin', 'ssl'],
input: 'src/main.ts',
preserveModules: true,
output: {
dir: 'bin',
format: 'es'
},
plugins: [resolve(), commonjs(), typescript()]
};
47 changes: 47 additions & 0 deletions local-storage/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { LandscapeApp, ui } from 'lumin';
const { UiText, EclipseLabelType, Alignment, HorizontalTextAlignment } = ui;

export class App extends LandscapeApp {
onAppStart () {
// Create a new prism that's half a meter cubed.
let prism = this.requestNewPrism([0.5, 0.5, 0.5]);

// Configure localStorage from polyfills to persist state to disk.
// This function expects a folder it can write to, don't put anything else in here.
localStorage.updateBase(this.getWritablePathWhenUnlocked() + "localStorage");

// First we read the old value from localStorage.
// If this is our initial load, it will be null, otherwise, it will be a string.
const oldCount = localStorage.getItem('count');

// Convert the old value to a number (defaulting to zero) and increment.
const count = Number(oldCount || '0') + 1;

// Store the new count so next time, it will increment again.
localStorage.setItem('count', String(count));


// Create a nice text label using UIKit.
let text = UiText.CreateEclipseLabel(
prism,
'Hello\nMagicScript! times ' + count,
EclipseLabelType.kT7
);
text.setAlignment(Alignment.CENTER_CENTER);
text.setTextAlignment(HorizontalTextAlignment.kCenter);

// Attach the label to the root of the prism's scene graph.
prism.getRootNode().addChild(text);
}

// Known Issue
// Web Inspector does not work unless the updateLoop function is present in source.
// It can be removed for production code.
updateLoop (delta: number) {
return true;
}

init () {
return 0;
}
}
12 changes: 12 additions & 0 deletions local-storage/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Add support for things like setTimeout, setInterval and fetch.
// Simply importing this sets all these as global definitions.
// They are declared in the .eslintrc so your editor won't complain.
import 'magic-script-polyfills';

// Load main app logic from the app class.
import { App } from './app';

// Launch our app!
// The 0.5 value is the number of seconds to call `updateLoop` in an interval if
// there are no other events waking the event loop.
export default new App(0.5);
13 changes: 13 additions & 0 deletions local-storage/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
"noEmit": true,
"strict": true,
"target": "esnext",
"jsx": "react",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"typeRoots" : ["./node_modules/magic-script-typings", "./node_modules/@types"]
}
}