Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Overall project refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Soundwave2142 committed May 16, 2023
1 parent be57053 commit 4ca697b
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 162 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# `Change log`

---------------
### 1.2.0 - 20.05.2023
- JS files reworked and refactored
- Project Archived

### 1.1.0 - 08.02.2023
- Restructure of the files (split into sever files/classes) and minor refactoring + minor text changes
- Commit history reset + `README.MD` update
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## This tool is now `outdated` (only for game versions 1.39-1.42) and not supported, for new info how to create new custom fonts for ETS2/ATS visit [this forum thread](https://forum.scssoft.com/viewtopic.php?t=297332).
### This tool is `outdated` (only for game versions 1.39-1.42) and not supported. For new info on how to create new custom fonts for ETS2/ATS visit [this SCSsoft forum thread](https://forum.scssoft.com/viewtopic.php?t=297332).

---

Expand All @@ -8,20 +8,23 @@ A simple converter of BMFont file `.fnt` to SCS' `.font` format for ETS2 and ATS
Original idea by Etrusan.

---

## How to use

1. Got to [releases section](https://github.com/Soundwave2142/MT-bmfont2scs/releases) of `MT-bmfont2scs` and download latest relase
1. Got to [releases section](https://github.com/Soundwave2142/MT-bmfont2scs/releases) of `MT-bmfont2scs` and download
the latest release
2. Extract contents of ZIP file anywhere and open `bmfont2scs.html` in your browser
3. Click "select file" button and select BMFont's `.fnt` file
4. The script will generate an archive with `.font` + `.mat` + `.tobj` files for you and start a download in browser

It is recommended to set up the right path in your .fnt file `file=<path>` before converting. That path will be used
in all generated files.

---
## Support the author

[<img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif">](https://www.paypal.com/donate?hosted_button_id=FUN3Z5RJCQEWL)

---
## Other tools for ETS2/ATS

### [Trucking Tool Exploration Merger](https://github.com/Soundwave2142/TT-exploration-merger)
7 changes: 6 additions & 1 deletion bmfont2scs.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- scripts -->
<script src="resources/js/bmfont2scs-helper.js"></script>
<script src="resources/js/bmfont2scs-ziper.js"></script>
<script src="resources/js/bmfont2scs-file-creator.js"></script>
<script src="resources/js/bmfont2scs.js"></script>

<!-- styles -->
Expand All @@ -32,6 +32,11 @@ <h3><a href="https://github.com/Soundwave2142/TS-bmfont2scs">Github link</a></h3

<!-- input fields -->
<div class="inputs">
<p>
It is recommended to set up the right path in your .fnt file 'file=>path<' before converting. That path will be used
in all generated files.
</p>

<div class="upload-div">
Select bmfont file (.fnt) :
<input type="file" id="file-input" single>
Expand Down
158 changes: 158 additions & 0 deletions resources/js/bmfont2scs-file-creator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
* @author Soundwave2142
*
* https://github.com/Soundwave2142
* https://sw-projects.net/
*
* Original idea by Etrusan
*
* 02.28.2021
*/

class BMFont2SCSFileCreator {

/**
* @type {JSZip}
*/
zip = new JSZip();

/**
* @type {BMFont2SCSHelper}
*/
helper = new BMFont2SCSHelper();

/**
* @type {{kerningKeepIfLimit: boolean, generalInfo: [], kerningLimit: number}}
*/
config = {
kerningLimit: 1535,
kerningKeepIfLimit: true,
generalInfo: []
}

/**
* @param config
*/
constructor(config) {
this.config = $.extend(this.config, config);
}

/**
* @param fileName {string}
* @param chars {array}
* @param kernings {array}
* @param contents {string}
*
* @returns {BMFont2SCSFileCreator}
*/
createFontFile(fileName, chars, kernings, contents = '') {
const self = this;

// add general info
this.config.generalInfo.forEach(function (line) {
contents += line + '\n';
})

// add header and insert coordinates for chars
contents += '\n' + '#NUM, P_x, P_y, W, H, L, T, A, I # character / glyph name\n\n';
chars.forEach(function (setOfCoordinates) {
setOfCoordinates.forEach(function (coordinate, key) {
const spacing = self.calculateSpacingForCoordinate(coordinate, key)
const delimiter = setOfCoordinates.length > (key + 1) ? ',' : '';

contents += spacing + coordinate + delimiter;
});

contents += " # '" + self.helper.getUnicodeFromHex(setOfCoordinates[0]) + "'\n";
});

const BreakException = {};

// add header and insert coordinates for kerning
if (kernings.length < this.config.kerningLimit || this.config.kerningKeepIfLimit) {
contents += '\n# kerning...\n\n';

try {
kernings.forEach(function (coordinates, key) {
if (key >= self.config.kerningLimit) {
throw BreakException // throw a break, if kerning reached its limit
}

contents += 'kern: ' + coordinates[0] + ', ' + coordinates[1] + ', ' + coordinates[2] + ' # \''
+ self.helper.getUnicodeFromHex(coordinates[0]) + '\' -> \''
+ self.helper.getUnicodeFromHex(coordinates[1]) + '\'\n';
});
} catch (e) {
if (e !== BreakException) throw e;
}
}

this.zip.file(fileName + '.font', contents);

return this;
}

/**
* @param coordinate {string}
* @param coordinatePosition {int}
* @param defaultSpacing {string}
*
* @returns {string}
*/
calculateSpacingForCoordinate(coordinate, coordinatePosition, defaultSpacing = '') {
// have bigger spacing after first (hex) value, rest are smaller (4)
const maxSpacing = coordinatePosition === 1 ? 7 : 4;

for (let i = 0; i < (maxSpacing - coordinate.length); i++) {
defaultSpacing += ' ';
}

return defaultSpacing;
}

/**
* @param fileName {string}
* @param contents {string}
*
* @returns {BMFont2SCSFileCreator}
*/
createMatFile(fileName, contents = '') {
contents = 'material : "ui.white_font" {\n'
+ ' texture : "' + fileName + '.tobj"\n'
+ ' texture_name : "texture"\n'
+ '}\n';

this.zip.file(fileName + '.mat', contents);

return this;
}

/**
* @param fileName {string}
* @param contents {string}
*
* @returns {BMFont2SCSFileCreator}
*/
createTobjFile(fileName, contents = '') {
contents = 'map 2d ' + fileName + '.tga\n'
+ 'addr\n'
+ ' clamp_to_edge\n'
+ ' clamp_to_edge\n'
+ 'color_space linear\n'
+ 'nomips\n'
+ 'nocompress\n';

this.zip.file(fileName + '.tobj', contents);

return this;
}

/**
* @param name
*/
saveZip(name) {
this.zip.generateAsync({type: 'blob'}).then(function (blob) {
saveAs(blob, name + '.zip');
});
}
}
9 changes: 4 additions & 5 deletions resources/js/bmfont2scs-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Original idea by Etrusan
*
* 02.28.2021
*
*/

class BMFont2SCSHelper {
Expand All @@ -18,7 +17,7 @@ class BMFont2SCSHelper {
*
* @returns {number}
*/
sortFunction(a, b) {
sortFunction = function (a, b) {
if (a[0] === b[0]) {
return 0;
} else {
Expand All @@ -41,10 +40,10 @@ class BMFont2SCSHelper {
* @returns {string}
*/
convertDecToHex(val) {
var element = parseInt(val, 10).toString(16);
var prefix = 'x';
const element = parseInt(val, 10).toString(16);
let prefix = 'x';

for (var i = element.length; i < 4; i++) {
for (let i = element.length; i < 4; i++) {
prefix += '0';
}

Expand Down
41 changes: 0 additions & 41 deletions resources/js/bmfont2scs-ziper.js

This file was deleted.

Loading

0 comments on commit 4ca697b

Please sign in to comment.