Skip to content

Commit

Permalink
Merge pull request Minecraft-Transit-Railway#1018 from Minecraft-Tran…
Browse files Browse the repository at this point in the history
…sit-Railway/beta-13

Beta 13
  • Loading branch information
jonafanho authored Dec 18, 2024
2 parents 5d407ac + 7476fe9 commit b0e11f1
Show file tree
Hide file tree
Showing 197 changed files with 824 additions and 781 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
- name: Build Angular
run: npm run build --prefix buildSrc/src/main/resources/website
- name: Setup Fabric files
run: ./gradlew fabric:setupFiles -PminecraftVersion="${{ matrix.minecraft }}" -PpatreonApiKey="${{ secrets.PATREON_API_KEY }}"
run: ./gradlew fabric:setupFiles -PminecraftVersion="${{ matrix.minecraft }}" -PcrowdinApiKey="${{ secrets.CROWDIN_API_KEY }}" -PpatreonApiKey="${{ secrets.PATREON_API_KEY }}"
- name: Setup Forge files
run: ./gradlew forge:setupFiles -PminecraftVersion="${{ matrix.minecraft }}" -PpatreonApiKey="${{ secrets.PATREON_API_KEY }}"
run: ./gradlew forge:setupFiles -PminecraftVersion="${{ matrix.minecraft }}"
- name: Build ${{ matrix.minecraft }}
run: ./gradlew build -PminecraftVersion="${{ matrix.minecraft }}"
- name: Build ${{ matrix.minecraft }} (server)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Upload Translations to Crowdin
env:
MY_KEY: ${{ secrets.CROWDIN_API_KEY }}
if: ${{ env.MY_KEY != '' && github.ref == 'refs/heads/master' }}
if: ${{ env.MY_KEY != '' }}
uses: crowdin/github-action@master
with:
upload_sources: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ forge/src/main/resources/META-INF
**/website/*.json
**/website/src/app/entity/generated
**/website/src/styles.css
**/website/src/theme.scss
**/website/.gitignore
fabric.mod.json
mtr.accesswidener
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repositories {

dependencies {
implementation "com.google.code.gson:gson:+"
implementation "com.github.crowdin:crowdin-api-client-java:+"
implementation "it.unimi.dsi:fastutil:+"
implementation "commons-io:commons-io:+"
implementation "org.apache.httpcomponents:httpmime:+"
Expand All @@ -14,6 +15,7 @@ dependencies {

repositories {
flatDir { dirs "../libs" }
maven { url "https://jitpack.io" }
}

java {
Expand Down
32 changes: 32 additions & 0 deletions buildSrc/src/main/java/org/mtr/mod/BuildTools.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.mtr.mod;

import com.crowdin.client.Client;
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.translations.model.CrowdinTranslationCreateProjectBuildForm;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -30,6 +33,8 @@
import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class BuildTools {

Expand All @@ -42,6 +47,7 @@ public class BuildTools {
private final int majorVersion;

private static final Logger LOGGER = LogManager.getLogger("Build");
private static final long CROWDIN_PROJECT_ID = 455212;

public BuildTools(String minecraftVersion, String loader, Project project) throws IOException {
this.minecraftVersion = minecraftVersion;
Expand Down Expand Up @@ -108,6 +114,32 @@ public String getForgeVersion() {
return getJson("https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json").getAsJsonObject().getAsJsonObject("promos").get(minecraftVersion + "-latest").getAsString();
}

public void downloadTranslations(String key) throws IOException, InterruptedException {
if (!key.isEmpty()) {
final CrowdinTranslationCreateProjectBuildForm crowdinTranslationCreateProjectBuildForm = new CrowdinTranslationCreateProjectBuildForm();
crowdinTranslationCreateProjectBuildForm.setSkipUntranslatedStrings(false);
crowdinTranslationCreateProjectBuildForm.setSkipUntranslatedFiles(false);
crowdinTranslationCreateProjectBuildForm.setExportApprovedOnly(false);

final Client client = new Client(new Credentials(key, null));
final long buildId = client.getTranslationsApi().buildProjectTranslation(CROWDIN_PROJECT_ID, crowdinTranslationCreateProjectBuildForm).getData().getId();

while (!client.getTranslationsApi().checkBuildStatus(CROWDIN_PROJECT_ID, buildId).getData().getStatus().equals("finished")) {
Thread.sleep(1000);
}

try (final InputStream inputStream = new URL(client.getTranslationsApi().downloadProjectTranslations(CROWDIN_PROJECT_ID, buildId).getData().getUrl()).openStream()) {
try (final ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
FileUtils.write(path.resolve("src/main/resources/assets/mtr/lang").resolve(zipEntry.getName().toLowerCase(Locale.ENGLISH)).toFile(), IOUtils.toString(zipInputStream, StandardCharsets.UTF_8), StandardCharsets.UTF_8);
zipInputStream.closeEntry();
}
}
}
}
}

public void generateTranslations() throws IOException {
final StringBuilder stringBuilder = new StringBuilder("package org.mtr.mod.generated.lang;import org.mtr.mapping.holder.MutableText;import org.mtr.mapping.holder.Text;import org.mtr.mapping.mapper.GraphicsHolder;import org.mtr.mapping.mapper.TextHelper;public interface TranslationProvider{\n");
JsonParser.parseString(FileUtils.readFileToString(path.resolve("src/main/resources/assets/mtr/lang/en_us.json").toFile(), StandardCharsets.UTF_8)).getAsJsonObject().entrySet().forEach(entry -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {LargeTileComponent} from "./component/large-button/large-tile.component"

@Component({
selector: "app-root",
standalone: true,
imports: [
MatStepperModule,
MatProgressSpinnerModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import {Component, EventEmitter, Input, Output, TemplateRef} from "@angular/core";
import {MatButtonModule} from "@angular/material/button";
import {MatIconModule} from "@angular/material/icon";
import {MatAccordion, MatExpansionPanel, MatExpansionPanelActionRow, MatExpansionPanelContent, MatExpansionPanelHeader, MatExpansionPanelTitle} from "@angular/material/expansion";
import {MatExpansionModule} from "@angular/material/expansion";
import {MatTooltip} from "@angular/material/tooltip";
import {NgTemplateOutlet} from "@angular/common";

@Component({
selector: "app-accordion",
standalone: true,
imports: [
MatButtonModule,
MatIconModule,
MatAccordion,
MatExpansionPanel,
MatExpansionPanelActionRow,
MatExpansionPanelContent,
MatExpansionPanelHeader,
MatExpansionPanelTitle,
MatExpansionModule,
MatTooltip,
NgTemplateOutlet,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {FormGroup, ReactiveFormsModule} from "@angular/forms";

@Component({
selector: "app-autocomplete",
standalone: true,
imports: [
MatInputModule,
MatAutocompleteModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ <h2 mat-dialog-title>Model Parts</h2>
<mat-option value="NEXT_STATION_UK">Next Station (UK)</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field subscriptSizing="dynamic">
<mat-label>Default Text</mat-label>
<input matInput aria-label="Default Text" formControlName="displayDefaultText" autocomplete="off"/>
</mat-form-field>
<div class="row gap">
<mat-form-field subscriptSizing="dynamic">
<mat-label>X Padding</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import {MatButtonModule} from "@angular/material/button";
import {MatTooltipModule} from "@angular/material/tooltip";
import {DataService} from "../../service/data.service";
import {MatIconModule} from "@angular/material/icon";
import {ModelPropertiesPartWrapper} from "../../entity/generated/modelPropertiesPartWrapper";
import {ModelPropertiesPartWrapperDTO} from "../../entity/generated/modelPropertiesPartWrapper";
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from "@angular/forms";
import {MatFormField, MatLabel} from "@angular/material/form-field";
import {MatInput} from "@angular/material/input";
import {CREATE_MODEL_PROPERTIES_PART} from "../edit-vehicle-model-parts/edit-vehicle-model-parts.dialog";
import {MatSelectModule} from "@angular/material/select";
import {CdkTextareaAutosize} from "@angular/cdk/text-field";
import {VehicleModelWrapper} from "../../entity/generated/vehicleModelWrapper";
import {PartPosition} from "../../entity/generated/partPosition";
import {VehicleModelWrapperDTO} from "../../entity/generated/vehicleModelWrapper";
import {PartPositionDTO} from "../../entity/generated/partPosition";
import {MatCheckboxModule} from "@angular/material/checkbox";

@Component({
standalone: true,
imports: [
MatDialogModule,
MatButtonModule,
Expand All @@ -36,7 +35,7 @@ import {MatCheckboxModule} from "@angular/material/checkbox";
})
export class EditVehicleModelPartDialog {
private readonly dialogRef = inject(MatDialogRef<EditVehicleModelPartDialog>);
private readonly data = inject<{ model: VehicleModelWrapper, modelPropertiesPart: ModelPropertiesPartWrapper }>(MAT_DIALOG_DATA);
private readonly data = inject<{ model: VehicleModelWrapperDTO, modelPropertiesPart: ModelPropertiesPartWrapperDTO }>(MAT_DIALOG_DATA);
protected readonly modelPartNames: string[] = [];
protected readonly formGroup;

Expand Down Expand Up @@ -176,7 +175,7 @@ export class EditVehicleModelPartDialog {
this.dialogRef.close();
}

private static positionsToString(positions: PartPosition[]) {
private static positionsToString(positions: PartPositionDTO[]) {
return positions.map(position => `${position.x}, ${position.y}, ${position.z}`).join("\n");
}

Expand All @@ -186,12 +185,12 @@ export class EditVehicleModelPartDialog {
const coordinate = parseFloat(coordinateString.replace(/[^\d-.]/g, ""));
return Number.isNaN(coordinate) ? 0 : coordinate;
});
return new PartPosition(coordinates[0] ?? 0, coordinates[1] ?? 0, coordinates[2] ?? 0);
return new PartPositionDTO(coordinates[0] ?? 0, coordinates[1] ?? 0, coordinates[2] ?? 0);
});
}

private static formatPositions(positionsString: string) {
const positions: PartPosition[] = [];
const positions: PartPositionDTO[] = [];
EditVehicleModelPartDialog.stringToPositions(positionsString).forEach(position => positions.push(position));
return EditVehicleModelPartDialog.positionsToString(positions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import {MAT_DIALOG_DATA, MatDialog, MatDialogModule, MatDialogRef} from "@angula
import {MatButtonModule} from "@angular/material/button";
import {MatTooltipModule} from "@angular/material/tooltip";
import {DataService} from "../../service/data.service";
import {VehicleModelWrapper} from "../../entity/generated/vehicleModelWrapper";
import {VehicleModelWrapperDTO} from "../../entity/generated/vehicleModelWrapper";
import {MatTable, MatTableModule} from "@angular/material/table";
import {ModelPropertiesPartWrapper} from "../../entity/generated/modelPropertiesPartWrapper";
import {ModelPropertiesPartWrapperDTO} from "../../entity/generated/modelPropertiesPartWrapper";
import {MatIconModule} from "@angular/material/icon";
import {MatCheckboxModule} from "@angular/material/checkbox";
import {PositionDefinition} from "../../entity/generated/positionDefinition";
import {PositionDefinitionDTO} from "../../entity/generated/positionDefinition";
import {EditVehicleModelPartDialog} from "../edit-vehicle-model-part/edit-vehicle-model-part.dialog";
import {FormControl, FormGroup, ReactiveFormsModule} from "@angular/forms";

const MAIN_COLUMNS: { id: string, title: string, formatData: (modelPropertiesPart: ModelPropertiesPartWrapper) => string }[] = [
const MAIN_COLUMNS: { id: string, title: string, formatData: (modelPropertiesPart: ModelPropertiesPartWrapperDTO) => string }[] = [
{id: "positionDefinition", title: "Model Part", formatData: modelPropertiesPart => modelPropertiesPart.positionDefinition.name},
{id: "positions", title: "Positions", formatData: modelPropertiesPart => modelPropertiesPart.positionDefinition.positions.map(({x, y, z}) => `(${x}, ${y}, ${z})`).join("\n")},
{id: "positionsFlipped", title: "Flipped Positions", formatData: modelPropertiesPart => modelPropertiesPart.positionDefinition.positionsFlipped.map(({x, y, z}) => `(${x}, ${y}, ${z})`).join("\n")},
Expand All @@ -21,13 +21,13 @@ const MAIN_COLUMNS: { id: string, title: string, formatData: (modelPropertiesPar
{id: "type", title: "Type", formatData: modelPropertiesPart => modelPropertiesPart.type},
];

const DOOR_COLUMNS: { id: string, title: string, formatData: (modelPropertiesPart: ModelPropertiesPartWrapper) => string }[] = [
const DOOR_COLUMNS: { id: string, title: string, formatData: (modelPropertiesPart: ModelPropertiesPartWrapperDTO) => string }[] = [
{id: "doorXMultiplier", title: "Door X Multiplier", formatData: modelPropertiesPart => modelPropertiesPart.doorXMultiplier !== 0 || modelPropertiesPart.doorZMultiplier !== 0 ? modelPropertiesPart.doorXMultiplier.toString() : ""},
{id: "doorZMultiplier", title: "Door Z Multiplier", formatData: modelPropertiesPart => modelPropertiesPart.doorXMultiplier !== 0 || modelPropertiesPart.doorZMultiplier !== 0 ? modelPropertiesPart.doorZMultiplier.toString() : ""},
{id: "doorAnimationType", title: "Door Animation", formatData: modelPropertiesPart => modelPropertiesPart.doorXMultiplier !== 0 || modelPropertiesPart.doorZMultiplier !== 0 ? modelPropertiesPart.doorAnimationType : ""},
];

const DISPLAY_COLUMNS: { id: string, title: string, formatData: (modelPropertiesPart: ModelPropertiesPartWrapper) => string }[] = [
const DISPLAY_COLUMNS: { id: string, title: string, formatData: (modelPropertiesPart: ModelPropertiesPartWrapperDTO) => string }[] = [
{id: "displayXPadding", title: "X Padding", formatData: modelPropertiesPart => modelPropertiesPart.type === "DISPLAY" ? modelPropertiesPart.displayXPadding.toString() : ""},
{id: "displayYPadding", title: "Y Padding", formatData: modelPropertiesPart => modelPropertiesPart.type === "DISPLAY" ? modelPropertiesPart.displayYPadding.toString() : ""},
{id: "displayColorCjk", title: "CJK Text Colour", formatData: modelPropertiesPart => modelPropertiesPart.type === "DISPLAY" ? modelPropertiesPart.displayColorCjk : ""},
Expand All @@ -39,15 +39,14 @@ const DISPLAY_COLUMNS: { id: string, title: string, formatData: (modelProperties
{id: "displayDefaultText", title: "Default Text", formatData: modelPropertiesPart => modelPropertiesPart.type === "DISPLAY" ? modelPropertiesPart.displayDefaultText : ""},
];

export const CREATE_MODEL_PROPERTIES_PART = () => new ModelPropertiesPartWrapper(
new PositionDefinition(""),
export const CREATE_MODEL_PROPERTIES_PART = () => new ModelPropertiesPartWrapperDTO(
new PositionDefinitionDTO(""),
"NORMAL", "EXTERIOR", "NORMAL",
0, 0, "FF9900", "FF9900", 1.5, 2, 0, "DESTINATION", "Not In Service",
0, 0, "STANDARD",
);

@Component({
standalone: true,
imports: [
MatDialogModule,
MatButtonModule,
Expand All @@ -61,14 +60,14 @@ export const CREATE_MODEL_PROPERTIES_PART = () => new ModelPropertiesPartWrapper
styleUrl: "edit-vehicle-model-parts.dialog.css",
})
export class EditVehicleModelPartsDialog {
@ViewChild(MatTable) table?: MatTable<ModelPropertiesPartWrapper>;
@ViewChild(MatTable) table?: MatTable<ModelPropertiesPartWrapperDTO>;
private readonly dialogRef = inject(MatDialogRef<EditVehicleModelPartsDialog>);
private readonly model = inject<VehicleModelWrapper>(MAT_DIALOG_DATA);
private readonly model = inject<VehicleModelWrapperDTO>(MAT_DIALOG_DATA);
private readonly dialog = inject(MatDialog);
protected readonly modelPartNames: string[] = [];
protected readonly allColumns = [...MAIN_COLUMNS, ...DOOR_COLUMNS, ...DISPLAY_COLUMNS];
protected readonly displayedColumnNames: string[] = [];
protected readonly dataSource: ModelPropertiesPartWrapper[] = [];
protected readonly dataSource: ModelPropertiesPartWrapperDTO[] = [];
protected readonly formGroup;
protected hasNormal = false;
protected hasFloorOrDoorway = false;
Expand Down Expand Up @@ -144,11 +143,11 @@ export class EditVehicleModelPartsDialog {
this.edit(modelPropertiesPart);
}

edit(modelPropertiesPart: ModelPropertiesPartWrapper) {
edit(modelPropertiesPart: ModelPropertiesPartWrapperDTO) {
this.dialog.open(EditVehicleModelPartDialog, {data: {model: this.model, modelPropertiesPart}}).afterClosed().subscribe(() => this.filterData());
}

delete(modelPropertiesPart: ModelPropertiesPartWrapper) {
delete(modelPropertiesPart: ModelPropertiesPartWrapperDTO) {
modelPropertiesPart.positionDefinition.name = "";
this.filterData();
this.dataService.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {FormatStringListPipe} from "../../pipe/formatStringListPipe";
import {FormatFileNamePipe} from "../../pipe/formatFileNamePipe";
import {AutocompleteComponent} from "../autocomplete/autocomplete.component";
import {MatCheckboxModule} from "@angular/material/checkbox";
import {VehicleModelWrapper} from "../../entity/generated/vehicleModelWrapper";
import {VehicleModelWrapperDTO} from "../../entity/generated/vehicleModelWrapper";
import {CREATE_MODEL} from "../edit/edit.component";
import {VehicleResourceWrapper} from "../../entity/generated/vehicleResourceWrapper";
import {VehicleResourceWrapperDTO} from "../../entity/generated/vehicleResourceWrapper";

@Component({
standalone: true,
imports: [
MatDialogModule,
MatButtonModule,
Expand All @@ -29,7 +28,7 @@ import {VehicleResourceWrapper} from "../../entity/generated/vehicleResourceWrap
})
export class EditVehicleModelPropertiesDialog {
private readonly dialogRef = inject(MatDialogRef<EditVehicleModelPropertiesDialog>);
private readonly data = inject<{ vehicleResource: VehicleResourceWrapper, model: VehicleModelWrapper }>(MAT_DIALOG_DATA);
private readonly data = inject<{ vehicleResource: VehicleResourceWrapperDTO, model: VehicleModelWrapperDTO }>(MAT_DIALOG_DATA);
private readonly customModelList: { [key: string]: number };
private readonly minecraftModelList: { [key: string]: number };
private readonly customTextureList: { [key: string]: number };
Expand Down
Loading

0 comments on commit b0e11f1

Please sign in to comment.