mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-25 09:52:02 +00:00
Merge branch 'day-18-toy-factory' of https://github.com/thepaperpilot/Advent-Incremental into day-18-toy-factory
This commit is contained in:
commit
44a232f2aa
3 changed files with 42 additions and 29 deletions
|
@ -10,7 +10,7 @@ const element = shallowRef<HTMLElement | null>(null);
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
application: Application;
|
application: Application;
|
||||||
}>();
|
}>();
|
||||||
console.log(props.application);
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (element.value !== null) {
|
if (element.value !== null) {
|
||||||
element.value?.append(props.application.view);
|
element.value?.append(props.application.view);
|
||||||
|
|
|
@ -65,6 +65,8 @@ const id = "factory";
|
||||||
// what is the actual day?
|
// what is the actual day?
|
||||||
const day = 18;
|
const day = 18;
|
||||||
|
|
||||||
|
const toyGoal = 1e3;
|
||||||
|
|
||||||
// 20x20 block size
|
// 20x20 block size
|
||||||
// TODO: unhardcode stuff
|
// TODO: unhardcode stuff
|
||||||
|
|
||||||
|
@ -129,16 +131,16 @@ const factory = createLayer(id, () => {
|
||||||
.map(c => FACTORY_COMPONENTS[c.type]?.energyCost ?? 0)
|
.map(c => FACTORY_COMPONENTS[c.type]?.energyCost ?? 0)
|
||||||
.reduce((a, b) => a + b, 0)
|
.reduce((a, b) => a + b, 0)
|
||||||
);
|
);
|
||||||
|
const energyEfficiency = computed(() =>
|
||||||
|
Decimal.div(energyConsumption.value, computedEnergy.value).recip().pow(2).min(1)
|
||||||
|
);
|
||||||
const tickRate = createSequentialModifier(() => [
|
const tickRate = createSequentialModifier(() => [
|
||||||
createMultiplicativeModifier(() => ({
|
createMultiplicativeModifier(() => ({
|
||||||
multiplier: elvesEffect,
|
multiplier: elvesEffect,
|
||||||
description: "Trained Elves"
|
description: "Trained Elves"
|
||||||
})),
|
})),
|
||||||
createMultiplicativeModifier(() => ({
|
createMultiplicativeModifier(() => ({
|
||||||
multiplier: Decimal.div(energyConsumption.value, computedEnergy.value)
|
multiplier: energyEfficiency,
|
||||||
.recip()
|
|
||||||
.pow(2)
|
|
||||||
.min(1),
|
|
||||||
description: "Energy Consumption",
|
description: "Energy Consumption",
|
||||||
enabled: () => Decimal.gt(energyConsumption.value, computedEnergy.value)
|
enabled: () => Decimal.gt(energyConsumption.value, computedEnergy.value)
|
||||||
}))
|
}))
|
||||||
|
@ -166,8 +168,8 @@ const factory = createLayer(id, () => {
|
||||||
<div>
|
<div>
|
||||||
{formatWhole(energyConsumption.value)} / {formatWhole(computedEnergy.value)}{" "}
|
{formatWhole(energyConsumption.value)} / {formatWhole(computedEnergy.value)}{" "}
|
||||||
energy used
|
energy used
|
||||||
{Decimal.lt(tickRate.value, 1) ? (
|
{Decimal.gt(energyConsumption.value, computedEnergy.value) ? (
|
||||||
<>{" (" + format(Decimal.mul(tickRate.value, 100))}% efficiency)</>
|
<>{" (" + format(Decimal.mul(energyEfficiency.value, 100))}% efficiency)</>
|
||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
|
@ -1325,7 +1327,7 @@ const factory = createLayer(id, () => {
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
{main.day.value === day
|
{main.day.value === day
|
||||||
? `Do something to complete the day`
|
? `Reach ${format(toyGoal)} for each toy to complete the day`
|
||||||
: `${name} Complete!`}{" "}
|
: `${name} Complete!`}{" "}
|
||||||
-{" "}
|
-{" "}
|
||||||
<button
|
<button
|
||||||
|
@ -1418,12 +1420,38 @@ const factory = createLayer(id, () => {
|
||||||
direction: Direction.Right,
|
direction: Direction.Right,
|
||||||
width: 600,
|
width: 600,
|
||||||
height: 25,
|
height: 25,
|
||||||
progress: () => (main.day.value === day ? 0 : 1),
|
fillStyle: `backgroundColor: ${color}`,
|
||||||
display: jsx(() => (main.day.value === day ? <>Requirement progress here</> : ""))
|
progress: () =>
|
||||||
|
main.day.value === day
|
||||||
|
? Decimal.div(toys.clothes.value, toyGoal)
|
||||||
|
.clampMax(1)
|
||||||
|
.add(Decimal.div(toys.woodenBlocks.value, toyGoal).clampMax(1))
|
||||||
|
.add(Decimal.div(toys.trucks.value, toyGoal).clampMax(1))
|
||||||
|
.div(3)
|
||||||
|
: 1,
|
||||||
|
display: jsx(() =>
|
||||||
|
main.day.value === day ? (
|
||||||
|
<>
|
||||||
|
{
|
||||||
|
[toys.clothes.value, toys.woodenBlocks.value, toys.trucks.value].filter(t =>
|
||||||
|
Decimal.gte(t, toyGoal)
|
||||||
|
).length
|
||||||
|
}{" "}
|
||||||
|
/ 3
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)
|
||||||
|
)
|
||||||
})) as GenericBar;
|
})) as GenericBar;
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (main.day.value === day && false) {
|
if (
|
||||||
|
main.day.value === day &&
|
||||||
|
Decimal.gte(toys.clothes.value, toyGoal) &&
|
||||||
|
Decimal.gte(toys.woodenBlocks.value, toyGoal) &&
|
||||||
|
Decimal.gte(toys.trucks.value, toyGoal)
|
||||||
|
) {
|
||||||
main.completeDay();
|
main.completeDay();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -104,7 +104,7 @@ const layer = createLayer(id, function (this: BaseLayer) {
|
||||||
onPurchase() {
|
onPurchase() {
|
||||||
cloth.cloth.value = Decimal.sub(cloth.cloth.value, clothesCost.value.cloth);
|
cloth.cloth.value = Decimal.sub(cloth.cloth.value, clothesCost.value.cloth);
|
||||||
this.amount.value = Decimal.add(this.amount.value, 1);
|
this.amount.value = Decimal.add(this.amount.value, 1);
|
||||||
clothes.value = this.amount.value;
|
clothes.value = Decimal.add(clothes.value, 1);
|
||||||
}
|
}
|
||||||
})) as GenericBuyable;
|
})) as GenericBuyable;
|
||||||
const woodenBlocksCost = computed(() => {
|
const woodenBlocksCost = computed(() => {
|
||||||
|
@ -136,7 +136,7 @@ const layer = createLayer(id, function (this: BaseLayer) {
|
||||||
onPurchase() {
|
onPurchase() {
|
||||||
trees.logs.value = Decimal.sub(trees.logs.value, woodenBlocksCost.value.wood);
|
trees.logs.value = Decimal.sub(trees.logs.value, woodenBlocksCost.value.wood);
|
||||||
this.amount.value = Decimal.add(this.amount.value, 1);
|
this.amount.value = Decimal.add(this.amount.value, 1);
|
||||||
woodenBlocks.value = this.amount.value;
|
woodenBlocks.value = Decimal.add(woodenBlocks.value, 1);
|
||||||
}
|
}
|
||||||
})) as GenericBuyable;
|
})) as GenericBuyable;
|
||||||
const trucksCost = computed(() => {
|
const trucksCost = computed(() => {
|
||||||
|
@ -196,7 +196,7 @@ const layer = createLayer(id, function (this: BaseLayer) {
|
||||||
metal.metal.value = Decimal.sub(metal.metal.value, trucksCost.value.metal);
|
metal.metal.value = Decimal.sub(metal.metal.value, trucksCost.value.metal);
|
||||||
plastic.plastic.value = Decimal.sub(plastic.plastic.value, trucksCost.value.plastic);
|
plastic.plastic.value = Decimal.sub(plastic.plastic.value, trucksCost.value.plastic);
|
||||||
this.amount.value = Decimal.add(this.amount.value, 1);
|
this.amount.value = Decimal.add(this.amount.value, 1);
|
||||||
trucks.value = this.amount.value;
|
trucks.value = Decimal.add(trucks.value, 1);
|
||||||
}
|
}
|
||||||
})) as GenericBuyable;
|
})) as GenericBuyable;
|
||||||
const buyables = [clothesBuyable, woodenBlocksBuyable, trucksBuyable];
|
const buyables = [clothesBuyable, woodenBlocksBuyable, trucksBuyable];
|
||||||
|
@ -292,21 +292,6 @@ const layer = createLayer(id, function (this: BaseLayer) {
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
globalBus.on("update", diff => {
|
|
||||||
if (Decimal.lt(main.day.value, day)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Decimal.lt(clothes.value, clothesBuyable.amount.value)) {
|
|
||||||
clothesBuyable.amount.value = clothes.value;
|
|
||||||
}
|
|
||||||
if (Decimal.lt(woodenBlocks.value, woodenBlocksBuyable.amount.value)) {
|
|
||||||
woodenBlocksBuyable.amount.value = woodenBlocks.value;
|
|
||||||
}
|
|
||||||
if (Decimal.lt(trucks.value, trucksBuyable.amount.value)) {
|
|
||||||
trucksBuyable.amount.value = trucks.value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const { total: totalToys, trackerDisplay } = setUpDailyProgressTracker({
|
const { total: totalToys, trackerDisplay } = setUpDailyProgressTracker({
|
||||||
resource: toySum,
|
resource: toySum,
|
||||||
goal: 500,
|
goal: 500,
|
||||||
|
|
Loading…
Reference in a new issue