{"id":17013868,"url":"https://github.com/technologicnick/scrap-mechanic-common","last_synced_at":"2026-05-10T09:48:02.828Z","repository":{"id":107942245,"uuid":"354319414","full_name":"TechnologicNick/scrap-mechanic-common","owner":"TechnologicNick","description":"Things commonly used when working with Scrap Mechanic","archived":false,"fork":false,"pushed_at":"2021-04-25T00:03:08.000Z","size":200,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T01:02:27.179Z","etag":null,"topics":["files","helper","nodejs","scrap-mechanic"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TechnologicNick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-03T14:57:48.000Z","updated_at":"2021-04-25T00:03:10.000Z","dependencies_parsed_at":"2023-06-19T04:52:21.752Z","dependency_job_id":null,"html_url":"https://github.com/TechnologicNick/scrap-mechanic-common","commit_stats":{"total_commits":49,"total_committers":1,"mean_commits":49.0,"dds":0.0,"last_synced_commit":"f1206957efb0114e761b451be4a6d7dc0bc145b8"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechnologicNick%2Fscrap-mechanic-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechnologicNick%2Fscrap-mechanic-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechnologicNick%2Fscrap-mechanic-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechnologicNick%2Fscrap-mechanic-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TechnologicNick","download_url":"https://codeload.github.com/TechnologicNick/scrap-mechanic-common/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244968172,"owners_count":20540063,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["files","helper","nodejs","scrap-mechanic"],"created_at":"2024-10-14T06:14:30.884Z","updated_at":"2026-05-10T09:48:02.792Z","avatar_url":"https://github.com/TechnologicNick.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scrap-mechanic-common\nThings commonly used when working with Scrap Mechanic\n\n## PathHelper ##\nHandles finding the game installation and user directories\n\n```javascript\nconst { PathHelper } = require(\"scrap-mechanic-common\");\n\n// Locate the User_012345678 directory in %appdata%\nPathHelper.findUserDir();\n\n(async () =\u003e {\n    \n    if (await PathHelper.findSMInstallDir()) {\n        // Found the game installation directory\n        \n        // Update GAME_DATA, SURVIVAL_DATA and CHALLENGE_DATA from PathHelper\n        // to use the new PathHelper.INSTALLATION_DIR value\n        PathHelper.updatePaths();\n        \n        // Expands $GAME_DATA, $SURVIVAL_DATA and $CHALLENGE_DATA to their full locations\n        let texture = \"$GAME_DATA/Objects/Textures/Blocks/blk_woodplanks01_dif.tga\";\n        console.log(\"Wood texture location:\", PathHelper.expandPathPlaceholders(texture));\n    } else {\n        // Unable to locate the game installation directory\n    }\n    \n})();\n```\n\n#### With Electron ####\nIf the game was unable to be found the user is able to select the correct installation directory themselves.\n```javascript\nconst { app  } = require(\"electron\");\nconst { PathHelper } = require(\"scrap-mechanic-common\");\n\n// This method will be called when Electron has finished\n// initialization and is ready to create browser windows.\napp.on(\"ready\", async (event, launchInfo) =\u003e {\n\n    // First tries to find it automatically. If it fails, opens a dialog\n    // and lets the user select it manually\n    if (await PathHelper.findOrSelectSMInstallDir()) {\n        // User has selected a valid Scrap Mechanic installation directory\n    \n        // Update GAME_DATA, SURVIVAL_DATA and CHALLENGE_DATA from PathHelper\n        // to use the new PathHelper.INSTALLATION_DIR value\n        PathHelper.updatePaths();\n    \n        // Locate the User_012345678 directory in %appdata%\n        PathHelper.findUserDir();\n        \n        // Continue the app\n        createWindow();\n    } else {\n        // User canceled the selection\n        \n        app.quit();\n    }\n});\n```\n\n## WorkshopModManager ##\nHandles installed workshop mods.\n\n```javascript\nconst { PathHelper, WorkshopModManager } = require(\"scrap-mechanic-common\");\n\n(async () =\u003e {\n    // Find PathHelper.USER_MODS_DIR\n    PathHelper.findUserDir();\n    \n    // Find PathHelper.WORKSHOP_DIR\n    if (await PathHelper.findSMInstallDir())\n        PathHelper.updatePaths();\n\n    // Loads all mods found in WorkshopModManager.getModsDirectories() and parses the shapesets\n    let { modCount, shapeCount } = WorkshopModManager.reloadMods(true /* parse shapesets */);\n    console.log(`Loaded ${modCount} mods with ${shapeCount} shapes`);\n    \n    // All loaded mods, including fake mods for Creative, Survival and Challenge mode\n    console.log(\"The mod is called:\", WorkshopModManager.mods[\"26ef623b-97d2-49ba-9a10-8898c1a94e9a\"].name);\n    \n    // Gets the mods that have a shape with the uuid of Wood Block 1\n    WorkshopModManager.getModsWithShapeUuid(\"df953d9c-234f-4ac2-af5e-f0490b223e71\")\n    \n    // Expands $CONTENT_${mod.localId} to the full path\n    let preview = \"$CONTENT_26ef623b-97d2-49ba-9a10-8898c1a94e9a/preview.jpg\";\n    console.log(\"The The Modpack mod preview image can be found in:\", WorkshopModManager.expandPathPlaceholders(preview));\n    \n})();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnologicnick%2Fscrap-mechanic-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechnologicnick%2Fscrap-mechanic-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnologicnick%2Fscrap-mechanic-common/lists"}