Skip to content

Build tasks#2

Open
Denmark14 wants to merge 2 commits intomainfrom
build-tasks
Open

Build tasks#2
Denmark14 wants to merge 2 commits intomainfrom
build-tasks

Conversation

@Denmark14
Copy link
Contributor

TO DO

  • Create a github action to recreate output based on changes to input. Action should commit to the same branch the changes occur in.
  • Send output instead of input to dependent repos

The goal of this PR is to create a system that drastically lowers the file size of our data. So far we have achieved a minification of 57MB -> 1.8MB

@Denmark14 Denmark14 added the enhancement New feature or request label May 29, 2023
@Denmark14 Denmark14 self-assigned this May 29, 2023
@Denmark14 Denmark14 requested review from AarCon and Glup3 May 29, 2023 02:14
@Denmark14 Denmark14 marked this pull request as ready for review May 29, 2023 02:16
}

function writeToOutput(filename, data) {
fs.writeFileSync(path.join(__dirname, '..', 'output', filename), JSON.stringify(data), 'utf-8');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the space parameter for the stringify here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#using_the_space_parameter). Should make it a bit easier to read the resulting json files from this. It also might add some length which might not be preferable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the goal here is absolute minification. you can also use numbers to specify how many spaces (or was it tabs?) you want per indentation. Our old content used 2

fs.writeFileSync(path.join(__dirname, '..', 'output', filename), JSON.stringify(data), 'utf-8');
}

function HoneyTreeData() {
Copy link
Contributor

@AarCon AarCon May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New version of the HoneyTreeData() converted from Python to JS by ChatGPT 3.5 (no bugs in the original, just easier readability):

function matchHoneyTreeData(match, honeyRoutes) {
  const arrayRegex = /\[(.*?)\]\s*=\s*\{(.*?)\}/;
  const valuesStr = match[1];
  const honeyTrees = {};

  const lines = valuesStr.split("\n");
  for (let i = 0; i < lines.length; i++) {
    let line = lines[i].trim();
    if (!line) {
      continue;
    }

    const submatch = line.match(arrayRegex);
    if (!submatch) {
      continue;
    }

    const key = submatch[1];
    const values = submatch[2].split(",").map(v => v.trim());
    if (!values.includes("AMPHAROS")) {
      honeyTrees[honeyRoutes[key]] = values;
    }
  }
  return honeyTrees;
}

function HoneyTreeData(honeyworkCppFilePath, honeyroutesFilePath) {
  const constRegex = /const\s+int32_t\s+HONEY_TREES\[\s*NUM_ZONE_ID\s*\]\[\s*10\s*\]\s*=\s*\{\s*([\s\S]*?)\};/;
  const fs = require('fs');
  const honeyData = fs.readFileSync(honeyworkCppFilePath, 'utf8');
  const honeyRoutes = JSON.parse(fs.readFileSync(honeyroutesFilePath, 'utf8'));

  // Extract honey trees data
  const match = honeyData.match(constRegex);
  if (match) {
    return matchHoneyTreeData(match, honeyRoutes);
  }
}

function getHoneyTreeMons(routes) {
  const honeyEncounterData = HoneyTreeData();

  for (const key in honeyEncounterData) {
    for (const mon of honeyEncounterData[key]) {
      if (mon.toUpperCase() in routes[key]) {
        continue;
      }
      if (mon === "FARFETCHD") {
        routes[key].push("Farfetch'd");
      } else {
        routes[key].push(mon.toUpperCase());
      }
    }
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if anything doesn't make sense here and I can explain it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants