Skip to content

Commit

Permalink
Refactor so that some levels use the tiledMap scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Dec 28, 2024
1 parent fb13245 commit 2bda5e7
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 84 deletions.
6 changes: 3 additions & 3 deletions scripts/generateAssetManifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ async function main() {
let assetFonts = [];
let assetData = [];

function parseDirectory(root, element) {
function parseDirectory(root, element, prefix = "") {
const extName = path.extname(element);
const camelCaseName = element.slice(0, -extName.length).split("_").map(camelCaseString).join('');
const camelCaseName = (prefix ? prefix + "_" : "") + element.slice(0, -extName.length).split("_").map(camelCaseString).join('');
switch(extName) {
case ".png":
importTextures += `import ${camelCaseName}Tex from "${root}${element}";\n`
Expand Down Expand Up @@ -63,7 +63,7 @@ async function main() {
parseDirectory("./", element);
}
for (const element of await readdir(join(assetLocation, "levels"))) {
parseDirectory("./levels/", element);
parseDirectory("./levels/", element, "levels");
}
console.log(MANIFEST_TEMPLATE
.replace("$IMPORT_TEXTURES", importTextures)
Expand Down
126 changes: 126 additions & 0 deletions src/assets/levels/borealis.tmj
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{ "compressionlevel":-1,
"height":40,
"infinite":false,
"layers":[
{
"id":3,
"image":"island1.png",
"locked":true,
"name":"foreground",
"opacity":1,
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"objects",
"objects":[
{
"gid":4,
"height":44,
"id":3,
"name":"",
"properties":[
{
"name":"wormgine.bazooka_ammo",
"type":"int",
"value":1
}],
"rotation":0,
"type":"",
"visible":true,
"width":33,
"x":332.845653169715,
"y":176.205826904856
},
{
"gid":5,
"height":38,
"id":6,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":35,
"x":275.430965195558,
"y":390.168568321178
},
{
"gid":6,
"height":44,
"id":7,
"name":"",
"properties":[
{
"name":"wormgine.end_condition.objects_destroyed.object_type",
"type":"string",
"value":"wormgine.target"
}],
"rotation":0,
"type":"",
"visible":true,
"width":33,
"x":28.3141012422375,
"y":-139.250314848494
},
{
"height":0,
"id":8,
"name":"",
"point":true,
"rotation":0,
"type":"wormgine.water",
"visible":true,
"width":0,
"x":36.4589342622821,
"y":617.147084991043
},
{
"gid":5,
"height":38,
"id":18,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":35,
"x":709.338680926916,
"y":78.1301247771836
},
{
"gid":5,
"height":38,
"id":19,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":35,
"x":467.287581699346,
"y":177.51366607249
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":7,
"nextobjectid":20,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":16,
"tilesets":[
{
"firstgid":1,
"source":"..\/objects.tsj"
}],
"tilewidth":16,
"type":"map",
"version":"1.10",
"width":80
}
File renamed without changes
21 changes: 12 additions & 9 deletions src/assets/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import bazookaTex from "./bazooka.png";
import boneIslesTex from "./bone_isles.png";
import fireworkTex from "./firework.png";
import grenadeTex from "./grenade.png";
import island1Tex from "./island1.png";
import mineTex from "./mine.png";
import mineActiveTex from "./mine_active.png";
import missileActiveTex from "./missile_active.png";
Expand All @@ -27,7 +26,8 @@ import testDolbyDamage3Tex from "./test_dolby_damage3.png";
import testDolbyDamage3BlushTex from "./test_dolby_damage3_blush.png";
import testingGroundTex from "./testing_ground.png";
import windScrollTex from "./windScroll.png";
import trainingTex from "./levels/training.png";
import levels_island1Tex from "./levels/island1.png";
import levels_trainingTex from "./levels/training.png";

// Sounds
import bazookafireSnd from "./bazookafire.ogg";
Expand All @@ -47,14 +47,14 @@ import monogramFnt from "./monogram.woff2";

// Data
import objectsData from "./objects.tsj?url";
import targetTrainingData from "./levels/target_training.tmj?url";
import levels_borealisData from "./levels/borealis.tmj?url";
import levels_targetTrainingData from "./levels/target_training.tmj?url";

export interface AssetTextures {
bazooka: Texture;
boneIsles: Texture;
firework: Texture;
grenade: Texture;
island1: Texture;
mine: Texture;
mineActive: Texture;
missileActive: Texture;
Expand All @@ -71,7 +71,8 @@ export interface AssetTextures {
testDolbyDamage3Blush: Texture;
testingGround: Texture;
windScroll: Texture;
training: Texture;
levels_island1: Texture;
levels_training: Texture;
}

export interface AssetSounds {
Expand All @@ -90,7 +91,8 @@ export interface AssetSounds {

export interface AssetData {
objects: unknown;
targetTraining: unknown;
levels_borealis: unknown;
levels_targetTraining: unknown;
}

export const manifest = {
Expand All @@ -102,7 +104,6 @@ export const manifest = {
{ src: boneIslesTex, alias: "boneIsles" },
{ src: fireworkTex, alias: "firework" },
{ src: grenadeTex, alias: "grenade" },
{ src: island1Tex, alias: "island1" },
{ src: mineTex, alias: "mine" },
{ src: mineActiveTex, alias: "mineActive" },
{ src: missileActiveTex, alias: "missileActive" },
Expand All @@ -119,7 +120,8 @@ export const manifest = {
{ src: testDolbyDamage3BlushTex, alias: "testDolbyDamage3Blush" },
{ src: testingGroundTex, alias: "testingGround" },
{ src: windScrollTex, alias: "windScroll" },
{ src: trainingTex, alias: "training" },
{ src: levels_island1Tex, alias: "levels_island1" },
{ src: levels_trainingTex, alias: "levels_training" },
],
},
{
Expand Down Expand Up @@ -152,7 +154,8 @@ export const manifest = {
name: "data",
assets: [
{ src: objectsData, alias: "objects" },
{ src: targetTrainingData, alias: "targetTraining" },
{ src: levels_borealisData, alias: "levels_borealis" },
{ src: levels_targetTrainingData, alias: "levels_targetTraining" },
],
},
],
Expand Down
13 changes: 8 additions & 5 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { loadAssets } from "../assets";
import { NetGameClient, NetGameInstance } from "../net/client";
import { Lobby } from "./lobby";
import { GameReactChannel } from "../interop/gamechannel";
import type { AssetData } from "../assets/manifest";

interface LoadGameProps {
level: string;
scenario: string;
level?: keyof AssetData;
gameInstance?: NetGameInstance;
}

Expand Down Expand Up @@ -62,20 +64,20 @@ export function App() {
});

const onNewGame = useCallback(
(level: string) => {
if (level === "lobbyGame") {
(scenario: string, level?: keyof AssetData) => {
if (scenario === "lobbyGame") {
// TODO: Bit of a hack
setShowLobby(true);
} else {
setGameState({ level });
setGameState({ scenario, level });
}
},
[setGameState],
);

const onLobbyGameStarted = useCallback(
(instance: NetGameInstance) => {
setGameState({ level: "netGame", gameInstance: instance });
setGameState({ scenario: "netGame", gameInstance: instance });
setShowLobby(false);
},
[setGameState],
Expand Down Expand Up @@ -108,6 +110,7 @@ export function App() {
if (gameState) {
return (
<IngameView
scenario={gameState.scenario}
level={gameState.level}
gameReactChannel={gameReactChannel}
gameInstance={gameState.gameInstance}
Expand Down
20 changes: 13 additions & 7 deletions src/components/ingame-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@ import { NetGameInstance } from "../net/client";
import { GameReactChannel } from "../interop/gamechannel";
import { IWeaponDefiniton } from "../weapons/weapon";
import { WeaponSelector } from "./gameui/weapon-select";
import { AssetData } from "../assets/manifest";

export function IngameView({
scenario,
level,
gameReactChannel,
gameInstance,
}: {
level: string;
scenario: string;
level?: keyof AssetData;
gameReactChannel: GameReactChannel;
gameInstance?: NetGameInstance;
}) {
console.log(scenario, level);
const [game, setGame] = useState<Game>();
const ref = useRef<HTMLDivElement>(null);
const [weaponMenu, setWeaponMenu] = useState<IWeaponDefiniton[] | null>(null);
useEffect(() => {
Game.create(window, level, gameReactChannel, gameInstance).then((game) => {
(window as unknown as { wormgine: Game }).wormgine = game;
game.loadResources().then(() => {
setGame(game);
});
});
Game.create(window, scenario, gameReactChannel, level, gameInstance).then(
(game) => {
(window as unknown as { wormgine: Game }).wormgine = game;
game.loadResources().then(() => {
setGame(game);
});
},
);
}, []);

useEffect(() => {
Expand Down
19 changes: 12 additions & 7 deletions src/components/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { NetGameClient } from "../net/client";
import { GameMenu } from "./menus/types";
import AccountMenu from "./menus/account";
import { OverlayTest } from "./menus/overlaytest";
import type { AssetData } from "../assets/manifest";

interface Props {
onNewGame: (level: string) => void;
onNewGame: (scenario: string, level?: keyof AssetData) => void;
reloadClient: () => void;
client?: NetGameClient;
}
Expand All @@ -17,7 +18,7 @@ const buildCommit = import.meta.env.VITE_BUILD_COMMIT;
const lastCommit = localStorage.getItem("wormgine_last_commit");

function mainMenu(
onStartNewGame: (level: string) => void,
onStartNewGame: (scenario: string, level?: keyof AssetData) => void,
setCurrentMenu: (menu: GameMenu) => void,
clientReady?: boolean,
) {
Expand Down Expand Up @@ -54,19 +55,23 @@ function mainMenu(
</button>
</li>
<li>
<button onClick={() => onStartNewGame("boneIsles")}>
<button
onClick={() => onStartNewGame("tiledMap", "levels_targetTraining")}
>
Bone Isles
</button>
</li>
<li>
<button onClick={() => onStartNewGame("tiledMap")}>
<button
onClick={() => onStartNewGame("tiledMap", "levels_targetTraining")}
>
Test map loading
</button>
</li>
<li>
<button
className="borealis"
onClick={() => onStartNewGame("borealisTribute")}
onClick={() => onStartNewGame("tiledMap", "levels_borealis")}
>
Borealis Tribute Rock
</button>
Expand Down Expand Up @@ -131,9 +136,9 @@ export function Menu({ onNewGame, client, reloadClient }: Props) {
});

const onStartNewGame = useCallback(
(level: string) => {
(scenario: string, level?: keyof AssetData) => {
localStorage.setItem("wormgine_last_commit", buildCommit);
onNewGame(level);
onNewGame(scenario, level);
},
[onNewGame],
);
Expand Down
Loading

0 comments on commit 2bda5e7

Please sign in to comment.