mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-22 00:21:34 +00:00
the start of adding components
This commit is contained in:
parent
2200ba8b3c
commit
a48d6595cf
8 changed files with 2091 additions and 1574 deletions
3369
package-lock.json
generated
3369
package-lock.json
generated
File diff suppressed because it is too large
Load diff
14
package.json
14
package.json
|
@ -17,15 +17,11 @@
|
||||||
"@fontsource/great-vibes": "^4.5.10",
|
"@fontsource/great-vibes": "^4.5.10",
|
||||||
"@fontsource/material-icons": "^4.5.4",
|
"@fontsource/material-icons": "^4.5.4",
|
||||||
"@fontsource/roboto-mono": "^4.5.8",
|
"@fontsource/roboto-mono": "^4.5.8",
|
||||||
"@pixi/app": "~6.3.2",
|
"@pixi/app": "^6.5.8",
|
||||||
"@pixi/constants": "~6.3.2",
|
"@pixi/assets": "^6.5.8",
|
||||||
"@pixi/core": "~6.3.2",
|
"@pixi/graphics": "^6.5.8",
|
||||||
"@pixi/display": "~6.3.2",
|
"@pixi/particle-emitter": "^5.0.8",
|
||||||
"@pixi/graphics": "^6.3.2",
|
"@pixi/sprite": "^6.5.8",
|
||||||
"@pixi/math": "~6.3.2",
|
|
||||||
"@pixi/particle-emitter": "^5.0.7",
|
|
||||||
"@pixi/sprite": "~6.3.2",
|
|
||||||
"@pixi/ticker": "~6.3.2",
|
|
||||||
"@vitejs/plugin-vue": "^2.3.3",
|
"@vitejs/plugin-vue": "^2.3.3",
|
||||||
"@vitejs/plugin-vue-jsx": "^1.3.10",
|
"@vitejs/plugin-vue-jsx": "^1.3.10",
|
||||||
"is-plain-object": "^5.0.0",
|
"is-plain-object": "^5.0.0",
|
||||||
|
|
|
@ -1,53 +1,30 @@
|
||||||
<template>
|
<template>
|
||||||
<table>
|
<div ref="element" class="factoryDisp" />
|
||||||
<tr>
|
|
||||||
<td>Info</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="components">Components! go brrrrrrr</td>
|
|
||||||
<td>
|
|
||||||
<div
|
|
||||||
ref="element"
|
|
||||||
class="factoryDisp"
|
|
||||||
@click="e => $emit('click', e)"
|
|
||||||
@mousemove="e => $emit('mouseMove', e)"
|
|
||||||
@mouseenter="e => $emit('mouseEnter', e)"
|
|
||||||
@mouseleave="e => $emit('mouseLeave', e)"
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Application } from "@pixi/app";
|
import type { Application } from "@pixi/app";
|
||||||
import { onMounted, shallowRef } from "vue";
|
import { onMounted, shallowRef } from "vue";
|
||||||
|
import { blockAmts } from "./factory";
|
||||||
import "lib/pixi";
|
import "lib/pixi";
|
||||||
|
|
||||||
const element = shallowRef<HTMLElement | null>(null);
|
const element = shallowRef<HTMLElement | null>(null);
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
application: Application;
|
application: Application;
|
||||||
}>();
|
}>();
|
||||||
|
console.log(props.application);
|
||||||
defineEmits<{
|
|
||||||
(e: "mouseMove", i: MouseEvent): void;
|
|
||||||
(e: "mouseEnter", i: MouseEvent): void;
|
|
||||||
(e: "mouseLeave", i: MouseEvent): void;
|
|
||||||
(e: "click", i: MouseEvent): void;
|
|
||||||
}>();
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (element.value !== null) {
|
if (element.value !== null) {
|
||||||
element.value?.append(props.application.view);
|
element.value?.append(props.application.view);
|
||||||
|
//props.application.resizeTo = element.value;
|
||||||
|
//props.application.resize();
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError("This should not occur");
|
throw new TypeError("This should not occur");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
.factoryDisp {
|
.factoryDisp {
|
||||||
border: 2px solid green;
|
width: 100%;
|
||||||
}
|
height: 100%;
|
||||||
.components {
|
|
||||||
width: 20%
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
BIN
src/data/layers/factory-components/cursor.jpg
Normal file
BIN
src/data/layers/factory-components/cursor.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
|
@ -3,43 +3,34 @@ import { createLayer } from "game/layers";
|
||||||
import { Application } from "@pixi/app";
|
import { Application } from "@pixi/app";
|
||||||
import { Sprite } from "@pixi/sprite";
|
import { Sprite } from "@pixi/sprite";
|
||||||
import { Graphics } from "@pixi/graphics";
|
import { Graphics } from "@pixi/graphics";
|
||||||
|
import { Assets } from "@pixi/assets";
|
||||||
import Factory from "./Factory.vue";
|
import Factory from "./Factory.vue";
|
||||||
import Modal from "components/Modal.vue";
|
import Modal from "components/Modal.vue";
|
||||||
import conveyor from "./factory-components/conveyor.png";
|
import conveyor from "./factory-components/conveyor.png";
|
||||||
import { reactive, Ref, ref, watchEffect } from "vue";
|
import cursor from "./factory-components/cursor.jpg";
|
||||||
|
import { computed, reactive, Ref, ref, watchEffect } from "vue";
|
||||||
import { Direction } from "util/common";
|
import { Direction } from "util/common";
|
||||||
import { persistent } from "game/persistence";
|
import { persistent } from "game/persistence";
|
||||||
import player from "game/player";
|
import player from "game/player";
|
||||||
|
import "./styles/factory.css";
|
||||||
|
import { globalBus } from "game/events";
|
||||||
|
import { Container } from "@pixi/display";
|
||||||
|
|
||||||
const id = "factory";
|
const id = "factory";
|
||||||
|
|
||||||
// what is the actual day?
|
// what is the actual day?
|
||||||
|
|
||||||
enum FactoryTypes {
|
|
||||||
conveyor,
|
|
||||||
conveyor1
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FactoryComponent {
|
|
||||||
type: FactoryTypes | undefined;
|
|
||||||
directionIn: Direction | undefined;
|
|
||||||
directionOut: Direction | undefined;
|
|
||||||
}
|
|
||||||
const day = 20;
|
const day = 20;
|
||||||
const size = {
|
|
||||||
width: 1000,
|
|
||||||
height: 400
|
|
||||||
};
|
|
||||||
|
|
||||||
// 20x20 block size
|
// 20x20 block size
|
||||||
// TODO: unhardcode stuff
|
// TODO: unhardcode stuff
|
||||||
const blockAmts = {
|
const size = {
|
||||||
w: 50,
|
width: 1000,
|
||||||
h: 20
|
height: 340
|
||||||
|
};
|
||||||
|
export const blockAmts = {
|
||||||
|
w: 50,
|
||||||
|
h: 17
|
||||||
};
|
};
|
||||||
|
|
||||||
const blockWidth = Math.floor(size.width / blockAmts.w);
|
|
||||||
const blockHeight = Math.floor(size.height / blockAmts.h);
|
|
||||||
|
|
||||||
function roundDownTo(num: number, multiple: number) {
|
function roundDownTo(num: number, multiple: number) {
|
||||||
return Math.floor(num / multiple) * multiple;
|
return Math.floor(num / multiple) * multiple;
|
||||||
|
@ -51,6 +42,40 @@ function getRelativeCoords(e: MouseEvent) {
|
||||||
y: e.clientY - rect.top
|
y: e.clientY - rect.top
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface FactoryComponent {
|
||||||
|
directionIn: Direction | undefined;
|
||||||
|
directionOut: Direction | undefined;
|
||||||
|
imageSrc: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
type: string;
|
||||||
|
sprite: Sprite;
|
||||||
|
}
|
||||||
|
const FACTORY_COMPONENTS = {
|
||||||
|
cursor: {
|
||||||
|
directionIn: undefined,
|
||||||
|
directionOut: undefined,
|
||||||
|
imageSrc: cursor,
|
||||||
|
name: "Cursor",
|
||||||
|
description: "Use this to move."
|
||||||
|
},
|
||||||
|
conveyor: {
|
||||||
|
directionIn: Direction,
|
||||||
|
directionOut: Direction,
|
||||||
|
imageSrc: conveyor,
|
||||||
|
name: "Conveyor",
|
||||||
|
description: "Moves 1 item per tick."
|
||||||
|
},
|
||||||
|
someOtherComponent: {
|
||||||
|
directionIn: Direction.Down,
|
||||||
|
directionOut: undefined,
|
||||||
|
imageSrc: conveyor,
|
||||||
|
description: "Accepts anything and produces nothing."
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
type FactoryCompNames = keyof typeof FACTORY_COMPONENTS;
|
||||||
const factory = createLayer(id, () => {
|
const factory = createLayer(id, () => {
|
||||||
// layer display
|
// layer display
|
||||||
const name = "The Factory";
|
const name = "The Factory";
|
||||||
|
@ -62,31 +87,29 @@ const factory = createLayer(id, () => {
|
||||||
y: 0
|
y: 0
|
||||||
});
|
});
|
||||||
const isMouseHoverShown = ref(false);
|
const isMouseHoverShown = ref(false);
|
||||||
const isFactoryShown = ref(false);
|
const whatIsHovered = ref<FactoryCompNames | "">("");
|
||||||
// create a Array filled with th
|
const compSelected = ref<FactoryCompNames | "">("");
|
||||||
const components: Ref<FactoryComponent[][]> = persistent(
|
const components: Ref<unknown[][]> = persistent(
|
||||||
Array(blockHeight)
|
Array(blockAmts.h)
|
||||||
.fill(undefined)
|
.fill(undefined)
|
||||||
.map(() =>
|
.map(() => Array(blockAmts.w).fill(undefined))
|
||||||
Array(blockWidth)
|
|
||||||
.fill(undefined)
|
|
||||||
.map(() => ({
|
|
||||||
type: undefined,
|
|
||||||
directionIn: undefined,
|
|
||||||
directionOut: undefined
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// pixi
|
// pixi
|
||||||
const app = new Application(size);
|
const app = new Application(size);
|
||||||
const graphicContainer = new Graphics();
|
const graphicContainer = new Graphics();
|
||||||
app.stage.addChild(graphicContainer);
|
const spriteContainer = new Container();
|
||||||
|
let blockWidth = 0;
|
||||||
|
let blockHeight = 0;
|
||||||
|
app.stage.addChild(graphicContainer, spriteContainer);
|
||||||
|
|
||||||
|
globalBus.on("update", () => {
|
||||||
|
blockWidth = app.screen.width / blockAmts.w;
|
||||||
|
blockHeight = app.screen.height / blockAmts.h;
|
||||||
|
});
|
||||||
|
|
||||||
// draw graphics
|
// draw graphics
|
||||||
function updateGraphics() {
|
function updateGraphics() {
|
||||||
// factory not shown, no point in rerendering stuff
|
|
||||||
if (isFactoryShown.value) {
|
|
||||||
graphicContainer.clear();
|
graphicContainer.clear();
|
||||||
if (isMouseHoverShown.value) {
|
if (isMouseHoverShown.value) {
|
||||||
graphicContainer.beginFill(0x808080);
|
graphicContainer.beginFill(0x808080);
|
||||||
|
@ -98,7 +121,6 @@ const factory = createLayer(id, () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
watchEffect(updateGraphics);
|
watchEffect(updateGraphics);
|
||||||
|
|
||||||
function onMouseMove(e: MouseEvent) {
|
function onMouseMove(e: MouseEvent) {
|
||||||
|
@ -108,8 +130,25 @@ const factory = createLayer(id, () => {
|
||||||
mouseCoords.x = x;
|
mouseCoords.x = x;
|
||||||
mouseCoords.y = y;
|
mouseCoords.y = y;
|
||||||
}
|
}
|
||||||
function onClick(e: MouseEvent) {
|
async function onClick(e: MouseEvent) {
|
||||||
// placeholder
|
if (compSelected.value === "") {
|
||||||
|
console.warn("You haven't hovered over anything, trickster!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let { x, y } = getRelativeCoords(e);
|
||||||
|
x = roundDownTo(x, blockWidth) / blockWidth;
|
||||||
|
y = roundDownTo(y, blockHeight) / blockHeight;
|
||||||
|
const basicData = structuredClone(
|
||||||
|
FACTORY_COMPONENTS[compSelected.value]
|
||||||
|
) as FactoryComponent;
|
||||||
|
basicData.type = compSelected.value;
|
||||||
|
const sheet = await Assets.load(basicData.imageSrc);
|
||||||
|
basicData.sprite = new Sprite(sheet);
|
||||||
|
basicData.sprite.x = x;
|
||||||
|
basicData.sprite.y = y;
|
||||||
|
basicData.sprite.width = blockWidth;
|
||||||
|
basicData.sprite.height = blockHeight;
|
||||||
|
spriteContainer.addChild(basicData.sprite);
|
||||||
}
|
}
|
||||||
function onMouseEnter() {
|
function onMouseEnter() {
|
||||||
isMouseHoverShown.value = true;
|
isMouseHoverShown.value = true;
|
||||||
|
@ -118,7 +157,13 @@ const factory = createLayer(id, () => {
|
||||||
isMouseHoverShown.value = false;
|
isMouseHoverShown.value = false;
|
||||||
}
|
}
|
||||||
function goBack() {
|
function goBack() {
|
||||||
player.tabs.splice(0, Infinity, "main")
|
player.tabs.splice(0, Infinity, "main");
|
||||||
|
}
|
||||||
|
function onComponentHover(name: FactoryCompNames | "") {
|
||||||
|
whatIsHovered.value = name;
|
||||||
|
}
|
||||||
|
function onCompClick(name: FactoryCompNames) {
|
||||||
|
compSelected.value = name;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
|
@ -128,14 +173,56 @@ const factory = createLayer(id, () => {
|
||||||
minimizable: false,
|
minimizable: false,
|
||||||
display: jsx(() => (
|
display: jsx(() => (
|
||||||
<div class="layer-container">
|
<div class="layer-container">
|
||||||
<button class="goBack" onClick={goBack}>❌</button>
|
<button class="goBack" onClick={goBack}>
|
||||||
|
❌
|
||||||
|
</button>
|
||||||
|
<table cellspacing="0" cellpadding="0" border="0" class="container">
|
||||||
|
<tr>
|
||||||
|
<td class="info" colspan="2">
|
||||||
|
<div style="min-height: 3em">
|
||||||
|
{whatIsHovered.value === ""
|
||||||
|
? undefined
|
||||||
|
: FACTORY_COMPONENTS[whatIsHovered.value].description}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top" class="comps">
|
||||||
|
<h3>Components</h3>
|
||||||
|
<div>
|
||||||
|
{Object.entries(FACTORY_COMPONENTS).map(value => {
|
||||||
|
const key = value[0] as FactoryCompNames;
|
||||||
|
const item = value[1];
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
src={item.imageSrc}
|
||||||
|
style={{
|
||||||
|
width: "20%",
|
||||||
|
"aspect-ratio": "1",
|
||||||
|
border:
|
||||||
|
compSelected.value === key
|
||||||
|
? "1px solid white"
|
||||||
|
: ""
|
||||||
|
}}
|
||||||
|
onMouseenter={() => onComponentHover(key)}
|
||||||
|
onMouseleave={() => onComponentHover("")}
|
||||||
|
onClick={() => onCompClick(key)}
|
||||||
|
></img>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
<Factory
|
<Factory
|
||||||
application={app}
|
application={app}
|
||||||
onMouseMove={onMouseMove}
|
onMousemove={onMouseMove}
|
||||||
onMouseEnter={onMouseEnter}
|
|
||||||
onMouseLeave={onMouseLeave}
|
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
onMouseenter={onMouseEnter}
|
||||||
|
onMouseleave={onMouseLeave}
|
||||||
/>
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
)),
|
)),
|
||||||
components
|
components
|
||||||
|
|
16
src/data/layers/styles/factory.css
Normal file
16
src/data/layers/styles/factory.css
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
.container {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.factoryDisp {
|
||||||
|
border-left: 1px solid white;
|
||||||
|
border-bottom: 1px solid white;
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
border-bottom: 1px solid white;
|
||||||
|
}
|
||||||
|
.comps {
|
||||||
|
border-bottom: 1px solid white;
|
||||||
|
}
|
|
@ -1,7 +1,4 @@
|
||||||
import { Application } from "@pixi/app";
|
import { BatchRenderer, extensions } from "@pixi/core";
|
||||||
import { BatchRenderer, Renderer } from "@pixi/core";
|
|
||||||
import { TickerPlugin } from "@pixi/ticker";
|
import { TickerPlugin } from "@pixi/ticker";
|
||||||
|
|
||||||
Application.registerPlugin(TickerPlugin);
|
extensions.add(TickerPlugin, BatchRenderer);
|
||||||
|
|
||||||
Renderer.registerPlugin("batch", BatchRenderer);
|
|
17
src/main.css
17
src/main.css
|
@ -137,6 +137,15 @@ ul {
|
||||||
background: #070710;
|
background: #070710;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.layer-container {
|
||||||
|
min-width: 100%;
|
||||||
|
min-height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
isolation: isolate;
|
||||||
|
}
|
||||||
|
|
||||||
.goBack {
|
.goBack {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
|
@ -158,11 +167,3 @@ ul {
|
||||||
transform: scale(1.1, 1.1);
|
transform: scale(1.1, 1.1);
|
||||||
text-shadow: 0 0 7px var(--foreground);
|
text-shadow: 0 0 7px var(--foreground);
|
||||||
}
|
}
|
||||||
.layer-container {
|
|
||||||
min-width: 100%;
|
|
||||||
min-height: 100%;
|
|
||||||
margin: 0;
|
|
||||||
flex-grow: 1;
|
|
||||||
display: flex;
|
|
||||||
isolation: isolate;
|
|
||||||
}
|
|
Loading…
Reference in a new issue