Skip to content

Commit

Permalink
Merge branch 'steam-beta' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Oct 22, 2023
2 parents 9eb29d7 + ec37916 commit 3f3a577
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 43 deletions.
59 changes: 52 additions & 7 deletions scripts/set-flavour.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, writeFileSync } from 'fs';
import { readdirSync, readFileSync, writeFileSync } from 'fs';

if (process.argv.length <= 2) {
console.error('Please provide a flavour (DEV, STANDALONE, STEAM, STEAM_CN)');
Expand All @@ -11,25 +11,70 @@ if (!['DEV', 'STANDALONE', 'STEAM', 'STEAM_CN'].includes(flavour)) {
process.exit(1);
}

// Determine flavour derivations
let appKey = (() => {
switch (flavour) {
case 'DEV':
return 'steam.overlay.2538150-DEV';
case 'STANDALONE':
return 'steam.overlay.2538150-STANDALONE';
case 'STEAM':
return 'steam.overlay.2538150-STEAM';
case 'STEAM_CN':
return 'steam.overlay.2538150-STEAM';
default:
console.warn('COULD NOT DETERMINE APP KEY FROM FLAVOUR');
return 'steam.overlay.2538150-DEV';
}
})();

// Set Main UI flavour
{
let uiFlavour = readFileSync('src-ui/build.ts').toString();
const path = 'src-ui/build.ts';
let uiFlavour = readFileSync(path).toString();
uiFlavour = uiFlavour.replaceAll(
/export const FLAVOUR: BuildFlavour = '(DEV|STANDALONE|STEAM|STEAM_CN)';/g,
`export const FLAVOUR: BuildFlavour = '${flavour}';`
);
writeFileSync('src-ui/build.ts', uiFlavour);
console.log('Updated src-ui/build.ts');
writeFileSync(path, uiFlavour);
console.log(path);
}

// Set Core flavour
{
let coreFlavour = readFileSync('src-core/src/flavour.rs').toString();
const path = 'src-core/src/flavour.rs';
let coreFlavour = readFileSync(path).toString();
coreFlavour = coreFlavour.replaceAll(
/pub const BUILD_FLAVOUR: BuildFlavour = BuildFlavour::(Dev|Standalone|Steam|SteamCn);/g,
`pub const BUILD_FLAVOUR: BuildFlavour = BuildFlavour::${flavour
.split('_')
.map((t) => t.toUpperCase().charAt(0) + t.toLowerCase().substring(1))
.join('')};`
);
writeFileSync('src-core/src/flavour.rs', coreFlavour);
console.log('Updated src-core/src/flavour.rs');
writeFileSync(path, coreFlavour);
console.log('Updated ' + path);
}

// Set flavour of vr manifest
{
const path = 'src-core/resources/manifest.vrmanifest';
let manifest = JSON.parse(readFileSync(path).toString());
manifest['applications'].forEach((app) => {
app['app_key'] = appKey;
});
writeFileSync(path, JSON.stringify(manifest, null, 2));
console.log('Updated ' + path);
}

// Set flavour of default input profiles
{
const basePath = 'src-core/resources/input';
readdirSync(basePath).forEach((file) => {
const path = basePath + '/' + file;
const contents = JSON.parse(readFileSync(path).toString());
if (!contents['app_key']) return;
contents['app_key'] = appKey;
writeFileSync(path, JSON.stringify(contents, null, 2));
console.log('Updated ' + path);
});
}
6 changes: 5 additions & 1 deletion src-core/resources/input/default_knuckles.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"controller_type": "knuckles",
"description": "OyasumiVR's default bindings for Valve Index controllers",
"name": "OyasumiVR Default Bindings",
"options": {},
"category": "steamvr_input",
"alias_info": {},
"app_key": "steam.overlay.2538150-DEV",
"bindings": {
"/actions/main": {
"sources": [
Expand Down Expand Up @@ -121,4 +125,4 @@
]
}
}
}
}
6 changes: 5 additions & 1 deletion src-core/resources/input/default_oculus_touch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"controller_type": "oculus_touch",
"description": "OyasumiVR's default bindings for Oculus controllers",
"name": "OyasumiVR Default Bindings",
"options": {},
"category": "steamvr_input",
"alias_info": {},
"app_key": "steam.overlay.2538150-DEV",
"bindings": {
"/actions/main": {
"sources": [
Expand Down Expand Up @@ -121,4 +125,4 @@
]
}
}
}
}
6 changes: 5 additions & 1 deletion src-core/resources/input/default_vive_controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"controller_type": "vive_controller",
"description": "OyasumiVR's default bindings for Vive controllers",
"name": "OyasumiVR Default Bindings",
"options": {},
"category": "steamvr_input",
"alias_info": {},
"app_key": "steam.overlay.2538150-DEV",
"bindings": {
"/actions/main": {
"sources": [
Expand Down Expand Up @@ -103,4 +107,4 @@
]
}
}
}
}
32 changes: 17 additions & 15 deletions src-core/resources/manifest.vrmanifest
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"source" : "builtin",
"applications": [{
"app_key": "steam.overlay.2538150",
"launch_type": "binary",
"binary_path_windows": "..\\OyasumiVR.exe",
"action_manifest_path": ".\\input\\action_manifest.json",
"is_dashboard_overlay": true,
"strings": {
"en_us": {
"name": "OyasumiVR",
"description": "OyasumiVR - VR Sleeping Utilities"
}
}
}]
}
"source": "builtin",
"applications": [
{
"app_key": "steam.overlay.2538150-DEV",
"launch_type": "binary",
"binary_path_windows": "..\\OyasumiVR.exe",
"action_manifest_path": ".\\input\\action_manifest.json",
"is_dashboard_overlay": true,
"strings": {
"en_us": {
"name": "OyasumiVR",
"description": "OyasumiVR - VR Sleeping Utilities"
}
}
}
]
}
35 changes: 17 additions & 18 deletions src-core/src/steam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ pub mod commands;
pub const STEAM_APP_ID: AppId = AppId(2538150);

lazy_static! {
pub static ref STEAMWORKS_CLIENT: Mutex<Option<Client>> =
Mutex::default();
pub static ref STEAMWORKS_SINGLE_CLIENT: Mutex<Option<SingleClient>> =
Mutex::default();
pub static ref STEAMWORKS_USER_STATS_FETCHED: Mutex<bool> =
Mutex::new(false);
pub static ref STEAMWORKS_CLIENT: Mutex<Option<Client>> = Mutex::default();
pub static ref STEAMWORKS_SINGLE_CLIENT: Mutex<Option<SingleClient>> = Mutex::default();
pub static ref STEAMWORKS_USER_STATS_FETCHED: Mutex<bool> = Mutex::new(false);
}

pub async fn init() {
if crate::BUILD_FLAVOUR != crate::flavour::BuildFlavour::Steam && crate::BUILD_FLAVOUR != crate::flavour::BuildFlavour::SteamCn {
if crate::BUILD_FLAVOUR != crate::flavour::BuildFlavour::Steam
&& crate::BUILD_FLAVOUR != crate::flavour::BuildFlavour::SteamCn
{
return;
}
let (client, single) = match Client::init_app(STEAM_APP_ID) {
Expand All @@ -43,17 +42,17 @@ pub async fn init() {
return;
}
};
let _cb = client.register_callback(|stats: UserStatsReceived| {
match stats.result {
Ok(_) => {
println!("USER STATS: {:?}", stats.result.unwrap());
tokio::spawn(async {
*STEAMWORKS_USER_STATS_FETCHED.lock().await = true;
});
}
Err(e) => {
println!("USER STATS ERROR: {:?}", e);
}
let _cb = client.register_callback(|stats: UserStatsReceived| match stats.result {
Ok(_) => {
tokio::spawn(async {
*STEAMWORKS_USER_STATS_FETCHED.lock().await = true;
});
}
Err(e) => {
error!(
"[Core] Failed to fetch user stats from Steamworks: {:#?}",
e
);
}
});
client.user_stats().request_current_stats();
Expand Down

0 comments on commit 3f3a577

Please sign in to comment.