Skip to content

Commit

Permalink
Merge pull request #565 from discretize/parallelization
Browse files Browse the repository at this point in the history
Parallelization
  • Loading branch information
gw2princeps authored Aug 5, 2023
2 parents 9327cec + d46b719 commit 446258f
Show file tree
Hide file tree
Showing 52 changed files with 18,783 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prettier"
],
"parser": "@typescript-eslint/parser",
"ignorePatterns": ["/plugins/*"],
"ignorePatterns": ["/plugins/*", "wasm_module/"],
"settings": {
"import/resolver": {
"node": {
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ install.bat
*.iml

.DS_Store
.mf/
.mf/

wasm_module/target/
8 changes: 8 additions & 0 deletions docs/Contributing/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ After cloning the repository, install its dependencies with:
yarn install
```

Build the experimental Rust/Webassembly core with:

```sh
yarn wasm
```

To start the vite development server, which will build the site on your computer and update with your changes in real time, use:

```sh
yarn develop
```

Note that the Rust/Webassembly code will not update in real time; the `yarn wasm` command must be rerun to compile any changes to it.

### Pull Requests

Be sure to base your development work and pull requests on the `staging` branch - this isn't the default!
Expand Down
111 changes: 111 additions & 0 deletions generateRustMappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* eslint-disable */
// @ts-nocheck
const { writeFileSync } = require('fs');
const { requireTS } = require('./src/utils/require-ts.js');
const { Affix, AffixNameOrCustom, AscendedItem, ExoticItem, PrimaryAttributes } =
requireTS('./src/utils/gw2-data.ts');

/*
WARNING
it is uncertain if we will use this file in the future.
*/

const OUTPUT_PATH = 'wasm_module/src/mappings.rs';

const SLOTS_MAPPING = [
{ rust: 'Helm', js: 'HELM' },
{ rust: 'Shoulders', js: 'SHOULDERS' },
{ rust: 'Chest', js: 'CHEST' },
{ rust: 'Gloves', js: 'GLOVES' },
{ rust: 'Leggings', js: 'LEGGINGS' },
{ rust: 'Boots', js: 'BOOTS' },
{ rust: 'Amulet', js: 'AMULET' },
{ rust: 'Ring', js: 'RING' },
{ rust: 'Accessory', js: 'ACCESSORY' },
{ rust: 'BackItem', js: 'BACK_ITEM' },
{ rust: 'TwoHandedWeapon', js: 'TWOHANDED_WEAPON' },
{ rust: 'OneHandedWeapon', js: 'ONEHANDED_WEAPON' },
];
const RARITY_MAPPING = [
{
rust: 'Ascended',
},
{
rust: 'Exotic',
},
];

function getRustAttribute(str) {
const adjustedStr = str.replaceAll(' ', '');
return `Attribute::${adjustedStr})`;
}

function findStats(slot: string, affix: AffixNameOrCustom, rarity: string) {
let slotStats = null;
// eslint-disable-next-line default-case
switch (rarity) {
case 'Ascended':
slotStats = AscendedItem[slot];
break;
case 'Exotic':
slotStats = ExoticItem[slot];
break;
}

// find out affix type
const affixType = Affix[affix].type;

return slotStats[affixType];
}

let output = '// AUTOMATICALLY GENERATED FILE\n';
output += '// DO NOT EDIT\n\n';
// todo imports adjustment
output +=
'\nuse crate::gw2data::{Affix, AttributesCollection, Rarity, Slots, Attribute, PrimaryAttributeName, SecondaryAttributeName};\n\n';
output +=
'pub fn add_stats(stats: &mut AttributesCollection, affix: Affix, slot: Slots, rarity: Rarity) {';

output += '\n';
output += 'match slot {';

output += '\n\tSlots::None => {},';
SLOTS_MAPPING.forEach((slot) => {
output += `\n\tSlots::${slot.rust} => match affix {`;

output += '\n\t\tAffix::None => {},';
// match affixes now
Object.keys(Affix).forEach((affix) => {
output += `\n\t\tAffix::${affix} => match rarity {`;

// match rarity now
RARITY_MAPPING.forEach((rarity) => {
output += `\n\t\t\tRarity::${rarity.rust} => {`;
// add stats here
const stats = findStats(slot.js, affix, rarity.rust);
Affix[affix].bonuses.major.forEach((bonus) => {
output += `\n\t\t\t\tstats.add_attribute_value(&${getRustAttribute(bonus)}, ${
stats.major
});`;
});

Affix[affix].bonuses.minor.forEach((bonus) => {
output += `\n\t\t\t\tstats.add_attribute_value(&${getRustAttribute(bonus)}, ${
stats.minor
});`;
});

output += '\n\t\t\t},';
});

output += '\n\t\t},';
});

output += '}\n\t';
});

output += '}\n}';

writeFileSync(OUTPUT_PATH, output);
1 change: 1 addition & 0 deletions locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"buffText_Low Boss Armor (VG, KC)": "Low Boss Armor (VG, KC)",
"buffText_Might": "Might",
"buffText_Protection": "Protection",
"buffText_Reinforced Armor": "Reinforced Armor",
"buffText_Vulnerability": "Vulnerability",
"buildTemplateName_Alacrity Condi Ren Invo (Outdated)": "Alacrity Condi Ren Invo (Outdated)",
"buildTemplateName_Alacrity Condi Willbender (Outdated)": "Alacrity Condi Willbender (Outdated)",
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"extractLocaleEn": "babel --config-file ./babel-extract-en.config.js 'src/**/*.{js,jsx,ts,tsx}' > /dev/null && node cleanupLocale.js",
"extractLocaleCMD": "babel --config-file ./babel-extract.config.js \"src/**/*.{js,jsx,ts,tsx}\" > NUL",
"cleanupLocale": "node cleanupLocale.js",
"wasm": ":",
"wasm-build-data": ":"
"wasm": "wasm-pack build ./wasm_module --target web --release",
"wasm-build-data": "ts-node-esm generateRustMappings.ts"
},
"resolutions": {
"@discretize/gw2-ui-new": "^0.1.2"
Expand All @@ -52,6 +52,7 @@
"arraybuffer-equal": "^1.0.4",
"buffer": "^6.0.3",
"classnames": "^2.3.1",
"comlink": "^4.4.1",
"i18next": "^22.4.15",
"js-yaml": "^4.1.0",
"json-url": "^3.0.0",
Expand All @@ -69,7 +70,9 @@
"typeface-fira-mono": "^1.1.13",
"typeface-muli": "^1.1.13",
"typeface-raleway": "^1.1.13",
"urlsafe-base64": "^1.0.0"
"urlsafe-base64": "^1.0.0",
"wasm-pack": "^0.11.1",
"wasm_module": "file:./wasm_module"
},
"devDependencies": {
"@babel/cli": "^7.16.7",
Expand Down Expand Up @@ -104,8 +107,10 @@
"esm": "^3.2.25",
"gh-pages": "^3.2.3",
"prettier": "^2.4.1",
"ts-node": "^10.9.1",
"typescript": "~5.0.4",
"vite": "^4.3.4",
"vite": "^4.3.9",
"vite-plugin-wasm-pack": "^0.1.12",
"wrangler": "^2.18.0"
}
}
7 changes: 7 additions & 0 deletions src/assets/modifierdata/buffs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
Vitality: [15, converted]
type: Text

- id: reinforced-armor
text: Reinforced Armor
modifiers:
conversionAfterBuffs:
Vitality: {Vitality: 5%}
type: Text

- section: Effects
items:
- id: exposed
Expand Down
15 changes: 10 additions & 5 deletions src/assets/presetdata/preset-buffs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ list:
"protection": true,
"vulnerability": true,
"jade-bot-base": true,
"jade-bot-per-tier": true
"jade-bot-per-tier": true,
"reinforced-armor": true
}
- name: Condi
Expand All @@ -26,7 +27,8 @@ list:
"vulnerability": true,
"assassinsPresence": true,
"jade-bot-base": true,
"jade-bot-per-tier": true
"jade-bot-per-tier": true,
"reinforced-armor": true
}
- name: Power (no spotter)
Expand All @@ -40,7 +42,8 @@ list:
"frostSpirit": true,
"assassinsPresence": true,
"jade-bot-base": true,
"jade-bot-per-tier": true
"jade-bot-per-tier": true,
"reinforced-armor": true
}
- name: Power (spotter)
Expand All @@ -55,7 +58,8 @@ list:
"frostSpirit": true,
"assassinsPresence": true,
"jade-bot-base": true,
"jade-bot-per-tier": true
"jade-bot-per-tier": true,
"reinforced-armor": true
}
- name: Benchmark
Expand All @@ -72,5 +76,6 @@ list:
"frostSpirit": true,
"spotter": true,
"jade-bot-base": true,
"jade-bot-per-tier": true
"jade-bot-per-tier": true,
"reinforced-armor": true
}
17 changes: 9 additions & 8 deletions src/components/TemplateInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Profession } from '@discretize/gw2-ui-new';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import { Link } from '@mui/material';
import React from 'react';
import React, { Fragment } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import creditData from '../assets/presetdata/credit.yaml';
Expand Down Expand Up @@ -39,7 +39,8 @@ const BeginningLinks = ({ credit }) =>
.map((entry) => <Author name={entry.author} />)
.reduce((prev, curr) => [prev, ', ', curr]);

const EndingLinks = ({ credit }) => credit.slice(-1).map((entry) => <Author name={entry.author} />);
const EndingLinks = ({ credit }) =>
credit.slice(-1).map((entry) => <Author key={entry.author} name={entry.author} />);

export default function TemplateInfo() {
const selectedDistribution = useSelector(getSelectedDistribution);
Expand All @@ -64,16 +65,16 @@ export default function TemplateInfo() {
log by <EndingLinks credit={credit} />!
</Trans>
)}
{credit.map((entry) =>
creditData[entry.author]?.authorUrl && entry.url ? (
<>
{credit
.filter((entry) => creditData[entry.author]?.authorUrl && entry.url)
.map((entry) => (
<Fragment key={`${entry.url}`}>
{' '}
<Link href={entry.url} target="_blank" rel="noreferrer">
<OpenInNewIcon fontSize="inherit" />
</Link>
</>
) : null,
)}
</Fragment>
))}
</Info>
);
}
Loading

0 comments on commit 446258f

Please sign in to comment.