Skip to content

Commit

Permalink
Precompress assets uploaded to itch.io, prettify web code
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston committed Jan 2, 2024
1 parent 70fdf0d commit d1e1b5d
Show file tree
Hide file tree
Showing 29 changed files with 882 additions and 803 deletions.
54 changes: 43 additions & 11 deletions .github/workflows/DeployPages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,21 @@ jobs:
cd ${{ github.workspace }}/src/asteroids-website
npm run build
- name: Upload artifact
id: upload
uses: actions/upload-artifact@v4
with:
path: '${{ github.workspace }}/src/asteroids-website/build'
- name: Build Svelte-Compressed
run: |
cd ${{ github.workspace }}/src/asteroids-website
npm run build-compressed
- name: Upload compressed artifact
id: upload-compressed
uses: actions/upload-pages-artifact@v2
with:
path: '${{ github.workspace }}/src/asteroids-website/build'

deploy:
deploy-github-pages:
runs-on: ubuntu-latest
needs: build
permissions:
Expand All @@ -100,6 +110,36 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2

deploy-itchio:
runs-on: ubuntu-latest
needs: deploy
permissions:
contents: write
steps:
- name: Download artifact compressed
uses: actions/[email protected]
with:
name: github-pages
path: asteroids-compressed
- name: Set current datetime
id: set_datetime
run: echo "datetime=$(date +"%Y%m%d%H%M%S")" >> "$GITHUB_OUTPUT"
- name: Create compressed ZIP
run: |
cd ../asteroids-compressed
mkdir ./asteroids-compressed
tar -xvf ./artifact-compressed.tar -C ./asteroids-compressed
zip -r ../asteroids-v${{ steps.set_datetime.outputs.datetime }}.zip ./asteroids/
- uses: manleydev/butler-publish-itchio-action@master
env:
BUTLER_CREDENTIALS: ${{ secrets.ITCHIO_API_KEY }}
CHANNEL: html
VERSION: v${{ steps.set_datetime.outputs.datetime }}
ITCH_GAME: asteroids
ITCH_USER: dylanlangston
PACKAGE: ./asteroids-v${{ steps.set_datetime.outputs.datetime }}.zip


release:
runs-on: ubuntu-latest
Expand All @@ -110,7 +150,7 @@ jobs:
- name: Download artifact
uses: actions/[email protected]
with:
name: github-pages
name: artifact
path: asteroids
- name: Set current datetime
id: set_datetime
Expand All @@ -134,12 +174,4 @@ jobs:
draft: false
commit: ${{ github.head_ref }}
tag: v${{ steps.set_datetime.outputs.datetime }}
token: ${{ secrets.GITHUB_TOKEN }}
- uses: manleydev/butler-publish-itchio-action@master
env:
BUTLER_CREDENTIALS: ${{ secrets.ITCHIO_API_KEY }}
CHANNEL: html
VERSION: v${{ steps.set_datetime.outputs.datetime }}
ITCH_GAME: asteroids
ITCH_USER: dylanlangston
PACKAGE: ./asteroids-v${{ steps.set_datetime.outputs.datetime }}.zip
token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions src/Shared.zig
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ pub const Shared = struct {
defer loadedShader.deactivate();
return drawFunction();
}
pub fn DrawWithArgs(shader: AssetManager.Shaders, comptime T: type, comptime A: type, drawFunction: *const fn (a: A) T, args: A) T {
const loadedShader = Get(shader);
loadedShader.activate();
defer loadedShader.deactivate();
return drawFunction(args);
}
};

pub const Sprite = Sprites;
Expand Down
1 change: 1 addition & 0 deletions src/asteroids-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "vite dev",
"dev-open": "vite dev --open",
"build": "vite build",
"build-compressed": "vite build -- --precompress",
"preview": "vite preview --port 8080",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Expand Down
10 changes: 5 additions & 5 deletions src/asteroids-website/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
plugins: {
tailwindcss: {},
autoprefixer: {}
}
};
4 changes: 2 additions & 2 deletions src/asteroids-website/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MiniAudio } from "./types/miniaudio";
import type { MiniAudio } from './types/miniaudio';

// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
Expand All @@ -13,4 +13,4 @@ declare global {
Settings: Settings;
miniaudio: MiniAudio | undefined = undefined;
}
}
}
38 changes: 18 additions & 20 deletions src/asteroids-website/src/app.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<noscript>
<style>
.jsonly {
display: none;
}
</style>
</noscript>
%sveltekit.head%
</head>

<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<noscript>
<style>
.jsonly {
display: none
}
</style>
</noscript>
%sveltekit.head%
</head>

<body data-sveltekit-preload-data="hover" class="h-screen touch-none">
<div style="display: contents">%sveltekit.body%</div>
<script async src="fixes.js"></script>
</body>

</html>
<body data-sveltekit-preload-data="hover" class="h-screen touch-none">
<div style="display: contents">%sveltekit.body%</div>
<script async src="fixes.js"></script>
</body>
</html>
10 changes: 5 additions & 5 deletions src/asteroids-website/src/app.postcss
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ textarea,
button,
select,
a {
-webkit-tap-highlight-color: transparent;
-webkit-tap-highlight-color: transparent;
}

html {
background-color: theme(colors.blue-dark);
background-repeat: repeat;
overflow: hidden;
background-color: theme(colors.blue-dark);
background-repeat: repeat;
overflow: hidden;
}

* {
@apply text-yellow-light;
@apply text-yellow-light;
}
2 changes: 1 addition & 1 deletion src/asteroids-website/src/error.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1>Error</h1>
<p>Code %sveltekit.status%</p>
<p>%sveltekit.error.message%</p>
<p>%sveltekit.error.message%</p>
22 changes: 11 additions & 11 deletions src/asteroids-website/src/lib/gameController.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export enum Button {
Up = 0,
Down,
Left,
Right,
Up_Left,
Up_Right,
Down_Left,
Down_Right,
A,
Start,
}
Up = 0,
Down,
Left,
Right,
Up_Left,
Up_Right,
Down_Left,
Down_Right,
A,
Start
}
116 changes: 56 additions & 60 deletions src/asteroids-website/src/lib/localizer.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,71 @@
import {
_,
getLocaleFromNavigator,
register,
init,
} from "svelte-i18n";
import { _, getLocaleFromNavigator, register, init } from 'svelte-i18n';

export enum Locales {
unknown = 0,
english,
spanish,
french,
unknown = 0,
english,
spanish,
french
}

class LocaleGroup {
public readonly Locale: Locales;
public readonly Index: number;
public readonly Prefix: string;
constructor(locale: Locales) {
this.Locale = locale;
this.Prefix = this.GetLocalePrefix(locale);
this.Index = navigator.languages.findIndex(l => l.startsWith(this.Prefix));
}
public readonly Locale: Locales;
public readonly Index: number;
public readonly Prefix: string;
constructor(locale: Locales) {
this.Locale = locale;
this.Prefix = this.GetLocalePrefix(locale);
this.Index = navigator.languages.findIndex((l) => l.startsWith(this.Prefix));
}

private GetLocalePrefix(locale: Locales): string {
switch (locale) {
case Locales.english:
return "en";
case Locales.spanish:
return "es";
case Locales.french:
return "fr";
default:
return "undefined";
}
}
private GetLocalePrefix(locale: Locales): string {
switch (locale) {
case Locales.english:
return 'en';
case Locales.spanish:
return 'es';
case Locales.french:
return 'fr';
default:
return 'undefined';
}
}
}

export class Localizer {
private static _ = new Localizer();
private static _ = new Localizer();

constructor() {
register("en", () => import("../locales/en.json"));
register("es", () => import("../locales/es.json"));
register("fr", () => import("../locales/fr.json"));
constructor() {
register('en', () => import('../locales/en.json'));
register('es', () => import('../locales/es.json'));
register('fr', () => import('../locales/fr.json'));

init({
fallbackLocale: "en",
initialLocale: getLocaleFromNavigator()
});
}
init({
fallbackLocale: 'en',
initialLocale: getLocaleFromNavigator()
});
}

private static Locale: LocaleGroup | undefined = undefined;
private static LoadLocale(): LocaleGroup | undefined {
if (Localizer.Locale == undefined) {
const allLocales = Object.entries(Locales).map((_, locale) => new LocaleGroup(locale));
const sortedLocales = allLocales.filter(l => l.Index > -1).sort((a, b) => a.Index - b.Index);
Localizer.Locale = sortedLocales.at(0);
}
return Localizer.Locale;
}
private static Locale: LocaleGroup | undefined = undefined;
private static LoadLocale(): LocaleGroup | undefined {
if (Localizer.Locale == undefined) {
const allLocales = Object.entries(Locales).map((_, locale) => new LocaleGroup(locale));
const sortedLocales = allLocales
.filter((l) => l.Index > -1)
.sort((a, b) => a.Index - b.Index);
Localizer.Locale = sortedLocales.at(0);
}
return Localizer.Locale;
}

public static GetLocale(): Locales {
const locale = Localizer.LoadLocale();
if (locale == undefined) return Locales.unknown;
return locale.Locale;
}
public static GetLocale(): Locales {
const locale = Localizer.LoadLocale();
if (locale == undefined) return Locales.unknown;
return locale.Locale;
}

public static GetLocalePrefix(): string {
const locale = Localizer.LoadLocale();
if (locale == undefined) return "en";
return locale.Prefix;
}
public static GetLocalePrefix(): string {
const locale = Localizer.LoadLocale();
if (locale == undefined) return 'en';
return locale.Prefix;
}
}

Loading

0 comments on commit d1e1b5d

Please sign in to comment.