Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Workshop API #46

Open
JJL772 opened this issue Sep 20, 2022 · 1 comment
Open

JS: Workshop API #46

JJL772 opened this issue Sep 20, 2022 · 1 comment
Assignees
Labels
Area: C++ Backend Related to C++ backend code that isn't open source JS API JS API extensions - Requires work by programmers

Comments

@JJL772
Copy link
Member

JJL772 commented Sep 20, 2022

We need an API to manage workshop addons.

This of course depends on workshop support as detailed in the p2ce tracker.

See: https://github.com/StrataSource/pano-typed/tree/feat/workshop-api

API Description

type DownloadState = ValueOf<DownloadStateEnum>;
interface DownloadStateEnum {
	UninstallPending: 0,
	Uninstalling:     1,
	Uninstalled:      2,

	InstallPending:   3,
	Installing:       4,
	Installed:        5,
}

/** Describes a workshop item. */
interface AddonMeta {
	type: string;
	index: number;
	title: string;
	description: string;
	local: boolean;

	authors: string[];
	tags: string[];

	dependencies: {[uuid: string]: { required: boolean }};
	subscriptions: number;
	votescore: number;
	flagged: boolean;

	// The standard workshop thumbnail. Exists on all addons.
	thumb: string;

	// These only exist when the addon is a campaign.
	cover?: string;
	logo?: string;
}

/** A chapter of an addon. */
interface AddonChapterMeta {
	map: string;
	title: string;
	description: string;

	unlocked: boolean;
	thumb: string;
	background: string;
}

/** [API not finalized] The workshop content API. Exclusive to P2:CE! */
declare namespace WorkshopAPI {
	/** Returns the number of addons in the addons list. */
	function GetAddonCount(): number;
	/** Returns the index of the addon that owns the specified map, or null if the map is not owned by an addon. */
	function GetAddonByMap(mapname: string): number;
	
	/** Returns the metadata for the addon at the specified index. */
	function GetAddonMeta(index: number): AddonMeta;
	/** Returns the metadata of the maps for the addon at the specified index. */
	function GetAddonChapters(index: number): AddonChapterMeta[];
	/** Returns the download state of the addon at the specified index. */
	function GetAddonState(index: number): DownloadState;
	/** Returns the subscription state of the addon at the specified index. */
	function GetAddonSubscribed(index: number): boolean;
	/** Returns the enable state of the addon at the specified index. */
	function GetAddonEnabled(index: number): boolean;
	/** Sets the subscription state of the addon at the specified index, returning whether the operation succeeded. */
	function SetAddonSubscribed(index: number, subscribed: boolean): boolean;
	/** Sets the enable state of the addon at the specified index, returning whether the operation succeeded. */
	function SetAddonEnabled(index: number, enabled: boolean): boolean;
}

interface GlobalEventNameMap {
	/** Fires when the installation state of an addon is updated.  */
	'WorkshopAddonStateUpdated':				(index: uint32, state: DownloadState) => void,
}

Events

NOTES:

  • uuid is the workshop addon ID. This may be empty string if the addon is locally installed (i.e. directly in the addons/ directory)

Invoked when there's a download status update to an item that's downloading

WorkshopDownloadStatus(index: int, uuid: string, bytesDownloaded: uint64, bytesTotal: uint64)

Invoked when the addon's state has changed

WorkshopStateChanged(index: int, uuid: string, state: DownloadState)

Invoked when a new addon is subscribed and added to the internal addon list

WorkshopItemAdded(index: int, uuid: string)

@JJL772 JJL772 added the JS API JS API extensions - Requires work by programmers label Sep 20, 2022
@JJL772 JJL772 self-assigned this Jul 29, 2023
@JJL772 JJL772 added the Area: C++ Backend Related to C++ backend code that isn't open source label Jul 29, 2023
@JJL772
Copy link
Member Author

JJL772 commented Aug 12, 2023

This API might need some changing to accommodate local non-workshop addons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C++ Backend Related to C++ backend code that isn't open source JS API JS API extensions - Requires work by programmers
Projects
None yet
Development

No branches or pull requests

1 participant