forked from memolemo-studios/SoftwareTycoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2a33b2
commit 44df66e
Showing
21 changed files
with
479 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
|
||
# Lua/u files | ||
**/*.lua | ||
|
||
# Other files | ||
**/.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
|
||
# Lua/u files | ||
**/*.lua | ||
|
||
# Other files | ||
**/.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"interface": { | ||
"shadow": 6486382942 | ||
}, | ||
"sounds": { | ||
"button_click": 7848185199 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import Roact, { Component } from "@rbxts/roact"; | ||
import { ClientApp } from "client/controllers/AppController"; | ||
import BaseButton from "interface/button/base"; | ||
|
||
@ClientApp({}) | ||
export default class MainApp extends Component { | ||
public render() { | ||
return <textlabel Size={UDim2.fromOffset(200, 50)} Text="Hello Roact!" />; | ||
return <BaseButton Size={UDim2.fromOffset(200, 50)} />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Roact, { mount, unmount } from "@rbxts/roact"; | ||
import { cleanupAssets } from "interface/util/asset"; | ||
import { BundleProvider } from "interface/util/bundle"; | ||
import { HoarcekatStory } from "types/roact/hoarcekat"; | ||
import BaseButton from "./base"; | ||
|
||
export = identity<HoarcekatStory>(parent => { | ||
const tree = mount( | ||
<BundleProvider> | ||
<BaseButton Size={UDim2.fromOffset(200, 50)} SoundsEnabled={false} /> | ||
</BundleProvider>, | ||
parent, | ||
); | ||
return () => { | ||
unmount(tree); | ||
cleanupAssets(); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { SingleMotor, Spring } from "@rbxts/flipper"; | ||
import Roact, { Binding, Component, JsxInstance } from "@rbxts/roact"; | ||
import { withSettings } from "interface/context/settings"; | ||
import { getAssetServices } from "interface/util/asset"; | ||
import { BindingUtil } from "shared/util/binding"; | ||
|
||
export interface BaseButtonProps | ||
extends Omit<JsxInstance<TextButton>, "BackgroundColor3" | "AutoButtonColor" | "Text"> { | ||
BaseColor?: Color3; | ||
HoveredColor3?: Color3; | ||
SoundsEnabled?: boolean; | ||
OnClick?: (rbx: TextButton, inputObject: InputObject, clickCount: number) => void; | ||
} | ||
|
||
/** BaseButton */ | ||
export default class BaseButton extends Component<BaseButtonProps> { | ||
private hoverMotor: SingleMotor; | ||
private hoverBinding: Binding<number>; | ||
|
||
public constructor(props: BaseButtonProps) { | ||
super(props); | ||
|
||
this.hoverMotor = new SingleMotor(0); | ||
this.hoverBinding = BindingUtil.makeBindingFromMotor(this.hoverMotor); | ||
} | ||
|
||
private setMotor(float: number) { | ||
this.hoverMotor.setGoal( | ||
new Spring(float, { | ||
frequency: 5, | ||
dampingRatio: 1, | ||
}), | ||
); | ||
} | ||
|
||
private playClickSound() { | ||
const { SoundManager, AssetManager } = getAssetServices(); | ||
const click_asset_id = "button_click"; | ||
AssetManager.getAssetIdFromSoundName(click_asset_id).match( | ||
id => SoundManager.createSoundFile(click_asset_id, id).play(), | ||
() => warn(`Unable to play because '${click_asset_id}' does not exists`), | ||
); | ||
} | ||
|
||
public render() { | ||
return withSettings(settings => { | ||
const spread_props = { ...this.props }; | ||
spread_props[Roact.Children] = undefined; | ||
spread_props.SoundsEnabled = undefined; | ||
spread_props.OnClick = undefined; | ||
spread_props.BaseColor = undefined; | ||
spread_props.HoveredColor3 = undefined; | ||
return ( | ||
<textbutton | ||
AutoButtonColor={false} | ||
BackgroundColor3={this.hoverBinding.map(alpha => { | ||
return ( | ||
this.props.BaseColor?.Lerp(this.props.HoveredColor3 ?? new Color3(), alpha) ?? new Color3() | ||
); | ||
})} | ||
Event={{ | ||
Activated: (rbx, input, count) => { | ||
// click sound | ||
if (settings.SoundsEnabled && (this.props.SoundsEnabled ?? true)) { | ||
this.playClickSound(); | ||
} | ||
this.props.OnClick?.(rbx, input, count); | ||
}, | ||
MouseEnter: () => this.setMotor(1), | ||
MouseLeave: () => this.setMotor(0), | ||
}} | ||
Text="" | ||
{...spread_props} | ||
> | ||
{this.props[Roact.Children]} | ||
</textbutton> | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createContext, PropsWithChildren } from "@rbxts/roact"; | ||
import Roact from "@rbxts/roact"; | ||
import { DEFAULT_PLAYER_SETTINGS } from "shared/util/playersettings"; | ||
import { PlayerSettings } from "types/player/settings"; | ||
|
||
const SettingsContext = createContext(DEFAULT_PLAYER_SETTINGS); | ||
|
||
export function SettingsProvider(props: PropsWithChildren) { | ||
// TODO: Support for player settings | ||
return <SettingsContext.Provider value={DEFAULT_PLAYER_SETTINGS}>{props[Roact.Children]}</SettingsContext.Provider>; | ||
} | ||
|
||
export function withSettings(callback: (settings: PlayerSettings) => Roact.Element) { | ||
return <SettingsContext.Consumer render={callback} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Roact, { createContext, PropsWithChildren } from "@rbxts/roact"; | ||
import { GameConfigStyles, GameStyle, StyleThemes } from "interface/util/style"; | ||
|
||
const StyleContext = createContext(GameConfigStyles[StyleThemes.Default]); | ||
|
||
export function StyleProvider(props: PropsWithChildren) { | ||
// TODO: Support for dark mode in settings? | ||
return ( | ||
<StyleContext.Provider value={GameConfigStyles[StyleThemes.Default]}> | ||
{props[Roact.Children]} | ||
</StyleContext.Provider> | ||
); | ||
} | ||
|
||
export function withStyle(callback: (style: GameStyle) => Roact.Element) { | ||
return <StyleContext.Consumer render={callback} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Dependency } from "@flamework/core"; | ||
import { RunService } from "@rbxts/services"; | ||
import { AssetManager } from "shared/flamework/AssetManager"; | ||
import { SoundManager } from "shared/flamework/SoundManager"; | ||
|
||
/** | ||
* Gets required asset services such: `AssetManager` and `SoundManager` | ||
*/ | ||
export function getAssetServices() { | ||
if (RunService.IsRunning()) { | ||
return { | ||
SoundManager: Dependency<SoundManager>(), | ||
AssetManager: Dependency<AssetManager>(), | ||
}; | ||
} | ||
return { | ||
SoundManager: new SoundManager(), | ||
AssetManager: new AssetManager(), | ||
}; | ||
} | ||
|
||
/** Cleans up assets */ | ||
export function cleanupAssets() { | ||
getAssetServices().SoundManager.cleanupFiles(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Roact, { PropsWithChildren } from "@rbxts/roact"; | ||
import { StoreProvider } from "@rbxts/roact-rodux"; | ||
import type ClientStore from "client/store/store"; | ||
import { SettingsProvider, withSettings } from "interface/context/settings"; | ||
import { StyleProvider, withStyle } from "interface/context/style"; | ||
import { withTransparency } from "interface/context/transparency"; | ||
import { GameStyle } from "interface/util/style"; | ||
import { PlayerSettings } from "types/player/settings"; | ||
import { RoactBindable } from "types/roact/value"; | ||
|
||
/** | ||
* Straight forward inserting required components such as: | ||
* - StoreProvider (if store property does exists) | ||
* - StyleProvider | ||
* - SettingsProvider | ||
*/ | ||
export function BundleProvider(props: PropsWithChildren<{ store?: typeof ClientStore }>) { | ||
const bundle_wrapper = ( | ||
<SettingsProvider> | ||
<StyleProvider>{props[Roact.Children]}</StyleProvider> | ||
</SettingsProvider> | ||
); | ||
return props.store !== undefined ? ( | ||
<StoreProvider store={props.store}>{bundle_wrapper}</StoreProvider> | ||
) : ( | ||
bundle_wrapper | ||
); | ||
} | ||
|
||
/** | ||
* Straight forward providing required components such as: | ||
* - StyleProvider | ||
* - SettingsProvider | ||
* - TransparencyProvider | ||
*/ | ||
export function withBundle( | ||
callback: (style: GameStyle, settings: PlayerSettings, transparency: RoactBindable<number>) => Roact.Element, | ||
) { | ||
return withStyle(style => { | ||
return withSettings(settings => { | ||
return withTransparency(transparency => { | ||
return callback(style, settings, transparency); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* CSS like structure, this will get easier | ||
* if we want dark theme to the game | ||
*/ | ||
export namespace Style { | ||
export interface PaddingXY { | ||
PaddingX: number; | ||
PaddingY: number; | ||
} | ||
|
||
export interface Frame { | ||
Background: Color3; | ||
} | ||
|
||
export interface TextLabel extends Style.Frame { | ||
Font: Enum.Font; | ||
TextColor: Color3; | ||
TextSize: number; | ||
} | ||
|
||
export interface TextButton extends Style.TextLabel, Style.PaddingXY { | ||
HoverColor: Color3; | ||
} | ||
} | ||
|
||
/** Default game style type structure */ | ||
export interface GameStyle { | ||
Tooltip: Style.PaddingXY & Style.TextLabel; | ||
Buttons: { | ||
Main: Style.TextButton; | ||
}; | ||
Frame: { | ||
Main: Style.Frame; | ||
}; | ||
} | ||
|
||
/** Game style themes */ | ||
export enum StyleThemes { | ||
Default = "DEFAULT", | ||
} | ||
|
||
/** Game style configuration */ | ||
export const GameConfigStyles: { [key in StyleThemes]: GameStyle } = { | ||
[StyleThemes.Default]: { | ||
Tooltip: { | ||
Background: Color3.fromRGB(240, 240, 240), | ||
TextColor: Color3.fromRGB(89, 89, 89), | ||
PaddingX: 12, | ||
PaddingY: 6, | ||
TextSize: 18, | ||
Font: Enum.Font.GothamBlack, | ||
}, | ||
Buttons: { | ||
Main: { | ||
Background: Color3.fromRGB(240, 240, 240), | ||
HoverColor: Color3.fromRGB(212, 212, 212), | ||
PaddingX: 12, | ||
PaddingY: 6, | ||
TextColor: Color3.fromRGB(28, 28, 28), | ||
TextSize: 18, | ||
Font: Enum.Font.SourceSansBold, | ||
}, | ||
}, | ||
Frame: { | ||
Main: { | ||
Background: Color3.fromRGB(227, 227, 227), | ||
}, | ||
}, | ||
}, | ||
}; |
Empty file.
Oops, something went wrong.