Skip to content

Commit

Permalink
Implemented machine filter for production, fixed bugs in dataset, add…
Browse files Browse the repository at this point in the history
…ed modal for old version
  • Loading branch information
greeny committed Sep 26, 2024
1 parent eede760 commit d952798
Show file tree
Hide file tree
Showing 63 changed files with 1,065 additions and 848 deletions.
1,731 changes: 897 additions & 834 deletions data/data1.0.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/Data/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export class Data
return true;
}

return typeof entity.metadata.manufacturingSpeed !== 'undefined';;
return entity.metadata.manufacturingSpeed !== 0;
}

public isExtractorBuilding(entity: BuildingTypes): boolean
Expand All @@ -390,6 +390,15 @@ export class Data
});
}

public getManufacturers(): IBuildingSchema[]
{
return Object.values(this.getRawData().buildings).filter((building) => {
return this.isManufacturerBuilding(building) && !this.isManualManufacturer(building);
}).sort((a, b) => {
return a.name.localeCompare(b.name);
});
}

}

export default new Data;
11 changes: 9 additions & 2 deletions src/Module/AppModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ILocationProvider, IModule, ISCEProvider, IScope} from 'angular';
import {ILocationProvider, IModule, ISCEProvider, IScope, ITimeoutService} from 'angular';
import {StateService, StateParams, UrlRouterProvider} from 'angular-ui-router';
import {HomeController} from '@src/Module/Controllers/HomeController';
import {AppDirective} from '@src/Module/Directives/AppDirective';
Expand Down Expand Up @@ -346,7 +346,7 @@ export class AppModule
});
},
]);
this.app.run(['$transitions', '$rootScope', '$state', ($transitions: any, $rootScope: any, $state: StateService) => {
this.app.run(['$transitions', '$rootScope', '$state', '$timeout', ($transitions: any, $rootScope: any, $state: StateService, $timeout: ITimeoutService) => {
$rootScope.aprilMode = April.isApril();
$rootScope.aprilModePossible = April.isAprilPossible();

Expand Down Expand Up @@ -379,6 +379,13 @@ export class AppModule
DataProvider.change($state.params.version);
});
});

$timeout(() => {
$('#modal').modal({
backdrop: 'static',
keyboard: false,
});
})
}]);

this.app.filter('number', () => {
Expand Down
1 change: 1 addition & 0 deletions src/Module/Controllers/ProductionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ProductionController
public readonly sinkableItems: IItemSchema[] = data.getSinkableItems();
public readonly alternateRecipes: IRecipeSchema[] = data.getAlternateRecipes();
public readonly basicRecipes: IRecipeSchema[] = data.getBaseItemRecipes();
public readonly machines: IBuildingSchema[] = data.getManufacturers();

public result: string;

Expand Down
1 change: 1 addition & 0 deletions src/Tools/Production/IProductionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IProductionDataRequest

blockedResources: string[]; // whether the raw resource is available for usage or not
blockedRecipes: string[]; // whether normal recipe can be used
blockedMachines?: string[]; // which machines are blocked
allowedAlternateRecipes: string[]; // whether alt is available or not (doesn't guarantee usage)

sinkableResources: string[]; // whether or not you can sink a given resource
Expand Down
79 changes: 77 additions & 2 deletions src/Tools/Production/ProductionTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {Solver} from '@src/Solver/Solver';
import {ProductionResult} from '@src/Tools/Production/Result/ProductionResult';
import {ProductionResultFactory} from '@src/Tools/Production/Result/ProductionResultFactory';
import {DataProvider} from '@src/Data/DataProvider';
import {IRecipeSchema} from '@src/Schema/IRecipeSchema';

export class ProductionTab
{
Expand Down Expand Up @@ -54,14 +55,18 @@ export class ProductionTab
this.addEmptyProduct();
}

if (typeof this.data.request.blockedMachines === 'undefined') {
this.data.request.blockedMachines = [];
}

this.unregisterCallback = scope.$watch(() => {
return this.data.request;
}, Callbacks.debounce((newValue, oldValue) => {
this.firstRun = false;
this.scope.saveState();
this.shareLink = '';
this.calculate(this.scope.$timeout);
}, 300), true);
}, 400), true);
}

public calculate($timeout?: ITimeoutService): void
Expand Down Expand Up @@ -89,8 +94,43 @@ export class ProductionTab
this.resultStatus = ResultStatus.CALCULATING;

const calc = () => {
const apiRequest: IProductionDataApiRequest = this.data.request as IProductionDataApiRequest;
const apiRequest: IProductionDataApiRequest = angular.copy(this.data.request) as IProductionDataApiRequest;
apiRequest.gameVersion = this.version === '0.8' ? '0.8.0' : '1.0.0';

const blockedMachines = apiRequest.blockedMachines || [];
const allowedAlts: string[] = [];
for (const recipeClass of apiRequest.allowedAlternateRecipes) {
const recipe = data.getRecipeByClassName(recipeClass);
if (recipe) {
let allowed = true;
for (const machineClass of blockedMachines) {
if (recipe.producedIn.indexOf(machineClass) !== -1) {
allowed = false;
}
}
if (allowed) {
allowedAlts.push(recipeClass);
}
}
}
apiRequest.allowedAlternateRecipes = allowedAlts;

const blockedRecipes: string[] = [];
for (const recipe of data.getBaseItemRecipes()) {
let allowed = apiRequest.blockedRecipes.indexOf(recipe.className) === -1;
for (const machineClass of blockedMachines) {
if (recipe.producedIn.indexOf(machineClass) !== -1) {
allowed = false;
}
}
if (!allowed) {
blockedRecipes.push(recipe.className);
}
}
apiRequest.blockedRecipes = blockedRecipes;

delete apiRequest.blockedMachines;

Solver.solveProduction(apiRequest, (result) => {
const res = () => {
let length = 0;
Expand Down Expand Up @@ -142,6 +182,7 @@ export class ProductionTab
request: {
allowedAlternateRecipes: [],
blockedRecipes: [],
blockedMachines: [],
blockedResources: [],
sinkableResources: [],
production: [],
Expand Down Expand Up @@ -358,6 +399,40 @@ export class ProductionTab
return this.data.request.blockedRecipes.indexOf(className) === -1;
}

public isMachineEnabled(className: string): boolean
{
if (typeof this.data.request.blockedMachines === 'undefined') {
return false;
}
return this.data.request.blockedMachines.indexOf(className) === -1;
}

public toggleMachine(className: string): void
{
if (typeof this.data.request.blockedMachines === 'undefined') {
return;
}
const index = this.data.request.blockedMachines.indexOf(className);
if (index === -1) {
this.data.request.blockedMachines.push(className);
} else {
this.data.request.blockedMachines.splice(index, 1);
}
}

public recipeMachineDisabled(recipe: IRecipeSchema): boolean
{
if (typeof this.data.request.blockedMachines === 'undefined') {
return false;
}
for (const madeIn of recipe.producedIn) {
if (this.data.request.blockedMachines.indexOf(madeIn) !== -1) {
return true;
}
}
return false;
}

public convertAlternateRecipeName(name: string): string
{
return name.replace('Alternate: ', '');
Expand Down
5 changes: 5 additions & 0 deletions styles/production.scss
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ $border: 1px solid rgba(0, 0, 0, 0.125);
background-color: $gray-700;
}

tr.disabled {
color: $gray-600;
text-decoration: line-through;
}

td {
padding: 2px;
.recipe-item {
Expand Down
48 changes: 45 additions & 3 deletions templates/Controllers/production.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,14 @@ <h4>Import (.sft file)</h4>
<span class="fas fa-fw fa-scroll mr-1"></span>
Recipes
</a>
<!--</li><li class="nav-item">
</li>
<li class="nav-item">
<a href="javascript: void(0);" class="nav-link" ng-class="{active: ctrl.tab.tab === 'machines'}" ng-click="ctrl.tab.tab = 'machines'">
<span class="fas fa-fw fa-industry mr-1"></span>
Machines
</a>
</li>
<!--<li class="nav-item">
<a href="javascript: void(0);" class="nav-link" ng-class="{active: ctrl.tab.tab === 'sink'}" ng-click="ctrl.tab.tab = 'sink'">
<span class="fas fa-fw fa-ticket-alt mr-1"></span>
Sink points
Expand Down Expand Up @@ -402,7 +409,7 @@ <h3 class="card-header card-header-with-buttons">

<div class="card-body" ng-show="ctrl.tab.state.alternateRecipesExpanded">
<table class="alternate-recipe-list">
<tr ng-repeat="recipe in ctrl.alternateRecipes | filter: {name: ctrl.tab.state.alternateRecipesQuery} | orderBy:'name'" ng-click="ctrl.tab.toggleAlternateRecipe(recipe.className)">
<tr ng-repeat="recipe in ctrl.alternateRecipes | filter: {name: ctrl.tab.state.alternateRecipesQuery} | orderBy:'name'" ng-click="ctrl.tab.toggleAlternateRecipe(recipe.className)" ng-class="{'disabled': ctrl.tab.recipeMachineDisabled(recipe)}" data-tooltip title="{{ctrl.tab.recipeMachineDisabled(recipe) ? 'Recipe disabled because corresponding building is disabled.' : ''}}">
<td>
<span class="fas fa-check-square" ng-show="ctrl.tab.isAlternateRecipeEnabled(recipe.className)"></span>
<span class="fas fa-square" ng-show="!ctrl.tab.isAlternateRecipeEnabled(recipe.className)"></span>
Expand Down Expand Up @@ -452,7 +459,7 @@ <h3 class="card-header d-flex">
</h3>
<div class="card-body" ng-show="ctrl.tab.state.basicRecipesExpanded">
<table class="alternate-recipe-list">
<tr ng-repeat="recipe in ctrl.basicRecipes | filter: {name: ctrl.tab.state.basicRecipesQuery} | orderBy:'name'" ng-click="ctrl.tab.toggleBasicRecipe(recipe.className)">
<tr ng-repeat="recipe in ctrl.basicRecipes | filter: {name: ctrl.tab.state.basicRecipesQuery} | orderBy:'name'" ng-click="ctrl.tab.toggleBasicRecipe(recipe.className)" ng-class="{'disabled': ctrl.tab.recipeMachineDisabled(recipe)}" data-tooltip title="{{ctrl.tab.recipeMachineDisabled(recipe) ? 'Recipe disabled because corresponding building is disabled.' : ''}}">
<td>
<span class="fas fa-check-square" ng-show="ctrl.tab.isBasicRecipeEnabled(recipe.className)"></span>
<span class="fas fa-square" ng-show="!ctrl.tab.isBasicRecipeEnabled(recipe.className)"></span>
Expand Down Expand Up @@ -481,6 +488,41 @@ <h3 class="card-header d-flex">
</div>
</div>

<div class="col-md-10" ng-if="ctrl.tab.tab === 'machines'">
<p>
Select machines you have available. Disabling a machine will automatically disable all recipes in that machine.
</p>

<div class="row">
<div class="col-md-6">
<div class="recipe-list-card card">
<div class="card-header d-flex">
<span class="recipe-list-card-title text-nowrap">
Available machines
</span>
</div>

<div class="card-body">
<table class="alternate-recipe-list">
<tr ng-repeat="machine in ctrl.machines | orderBy:'name'" ng-click="ctrl.tab.toggleMachine(machine.className)">
<td>
<span class="fas fa-check-square" ng-show="ctrl.tab.isMachineEnabled(machine.className)"></span>
<span class="fas fa-square" ng-show="!ctrl.tab.isMachineEnabled(machine.className)"></span>
</td>
<td class="d-flex justify-content-between">
<span>
<item-icon item="machine.className" size="20"></item-icon>
{{machine.name}}
</span>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>

<div class="col-md-10" ng-show="ctrl.tab.tab === 'sink'">
<div class="row">
<div class="col-md-6">
Expand Down
26 changes: 20 additions & 6 deletions templates/Directives/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ <h6 class="dropdown-header">Support me</h6>
</nav>

<div class="container-fluid px-xl-5 px-lg-4 px-md-3 px-sm-2 px-1" style="margin-top: 60px;">
<div class="alert alert-danger alert-dismissible fade show" ng-if="version === '0.8'">
<b>You're looking at Tools for Update 8!</b> If you want to calculate builds for full release (1.0), change version in top menu.<br>
You can use the export/import functionality to move production lines to 1.0 Tools.
<button class="close" data-dismiss="alert">&times;</button>
</div>

<div ui-view></div>

<hr>
Expand All @@ -116,3 +110,23 @@ <h6 class="dropdown-header">Support me</h6>
</footer>
</div>

<div class="modal" tabindex="-1" ng-if="version === '0.8'" id="modal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Old version!</h3>
</div>
<div class="modal-body">
<p class="alert alert-danger">
<b>You're looking at Tools for Update 8!</b> If you want to calculate builds for full release (1.0), use the button below to switch.<br>
You can use the export/import functionality to move production lines to 1.0 Tools.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Stay on 0.8 Tools</button>
<a ng-click="changeVersion('1.0')" class="btn btn-success">Go to 1.0 Tools</a>
</div>
</div>
</div>
</div>

Binary file removed www/assets/images/items/a-friend_256.png
Binary file not shown.
Binary file removed www/assets/images/items/a-friend_64.png
Binary file not shown.
Binary file removed www/assets/images/items/beam-connector_256.png
Binary file not shown.
Binary file removed www/assets/images/items/beam-connector_64.png
Binary file not shown.
Binary file removed www/assets/images/items/beam-support_256.png
Binary file not shown.
Binary file removed www/assets/images/items/beam-support_64.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed www/assets/images/items/candy-cane-decor_256.png
Binary file not shown.
Binary file removed www/assets/images/items/candy-cane-decor_64.png
Binary file not shown.
Binary file removed www/assets/images/items/candy-cane_256.png
Binary file not shown.
Binary file removed www/assets/images/items/candy-cane_64.png
Binary file not shown.
Binary file not shown.
Binary file removed www/assets/images/items/double-beam-connector_64.png
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-gift-tree_256.png
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-gift-tree_64.png
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-lights_256.png
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-lights_64.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-tree-base_256.png
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-tree-base_64.png
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-wreath_256.png
Binary file not shown.
Binary file removed www/assets/images/items/ficsmas-wreath_64.png
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed www/assets/images/items/giant-ficsmas-tree_256.png
Diff not rendered.
Binary file removed www/assets/images/items/giant-ficsmas-tree_64.png
Diff not rendered.
Binary file removed www/assets/images/items/it-s-snowing_256.png
Diff not rendered.
Binary file removed www/assets/images/items/it-s-snowing_64.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed www/assets/images/items/mercer-sphere_256.png
Diff not rendered.
Binary file removed www/assets/images/items/mercer-sphere_64.png
Diff not rendered.
Binary file removed www/assets/images/items/metal-beam_256.png
Diff not rendered.
Binary file removed www/assets/images/items/metal-beam_64.png
Diff not rendered.
Binary file removed www/assets/images/items/painted-beam_256.png
Diff not rendered.
Binary file removed www/assets/images/items/painted-beam_64.png
Diff not rendered.
Binary file removed www/assets/images/items/snowfight_256.png
Diff not rendered.
Binary file removed www/assets/images/items/snowfight_64.png
Diff not rendered.
Binary file removed www/assets/images/items/snowman_256.png
Diff not rendered.
Binary file removed www/assets/images/items/snowman_64.png
Diff not rendered.
Binary file removed www/assets/images/items/somersloop-analysis_256.png
Diff not rendered.
Binary file removed www/assets/images/items/somersloop-analysis_64.png
Diff not rendered.
Binary file removed www/assets/images/items/somersloop_256.png
Diff not rendered.
Binary file removed www/assets/images/items/somersloop_64.png
Diff not rendered.
Binary file removed www/assets/images/items/structural-beam-pack_256.png
Diff not rendered.
Binary file removed www/assets/images/items/structural-beam-pack_64.png
Diff not rendered.

0 comments on commit d952798

Please sign in to comment.