I would like to have Bixby read out the description after selecting a resort. Since the description is not shown when all resorts are being displayed, it'd be nice to have the description dialog after selecting a resort.
I am trying to get the dialog for when result == 1. I have tried to create a dialog to match ViewAll from-property SpaceResort, but still have not been able to get any custom dialog.
result-view {
match {
ViewAll(all) {
from-property {
SpaceResort (result)
}
}
}
message {
template-macro (SPACE_RESORT_RESULT) {
param (result) {expression (result)}
}
}
render {
if (size(result) > 1) {
list-of (result) {
where-each (item) {
layout-macro (space-resort-summary) {
param (spaceResort) {
expression(item)
}
}
}
layout
highlights {
select(pick) {
label {
template-macro (HIGHLIGHT_LABEL_BY_PREFERENCES)
}
layout-macro (space-resort-highlight) {
param (spaceResort) {
expression(pick)
}
}
order-by {
sorting (pick) {
by-preferences
}
}
}
select(pick) {
label("#{raw(pick.highlight)}")
layout-macro (space-resort-highlight) {
param (spaceResort) {
expression(pick)
}
}
filter-by (exists(pick.highlight))
}
select(pick) {
label("#{raw(pick.highlight)}")
layout-macro (space-resort-highlight) {
param (spaceResort) {
expression(pick)
}
}
filter-by (exists(pick.highlight))
}
select(pick) {
label("#{raw(pick.highlight)}")
layout-macro (space-resort-highlight) {
param (spaceResort) {
expression(pick)
}
}
filter-by (exists(pick.highlight))
}
}
}
} else-if (size(result) == 1) {
layout-macro (space-resort-details) {
param (spaceResort) {
expression (result)
}
}
}
}
conversation-drivers {
if ("size(result) == 1") {
conversation-driver {
template-macro (MakeReservation)
}
}
}
}
Go to resources/en/dialogs/ and created a dialog called selected_planet.dialog.bxb.
Create a dialog with this code:
dialog (Result) {
match: SpaceResort (this)
template("You selected this planet!.") {
speech ("#{value(this.description)}")
}
}
The description will now be read out loud by Bixby.
To test this:
Say "Give me a space resort near mars" and select one of the options that appear.
Related
I've made an inventory object for my game. Here is its code:
class player extends Phaser.GameObjects{
constructor(){
super();
this.stuff = [null,null,null,null,null,null,null,null,null,null];
}
collcet(item) {
this.space = 0;
while (this.space < 10){
if (this.items[this.space] == null){
this.items[this.space] == item;
break;
}
else {
this.space += 1;
}
}
}
has(item){
this.space = 0;
this.result = false
while (this.space < 10){
if (this.items[this.space] == item){
this.result = true;
break;
}
else {
this.space += 1;
}
}
return this.result;
}
takeOut(item){
this.space = 0;
while (this.space < 10){
if (this.items[this.space] == item){
this.items[this.space] == null;
break;
}
else {
this.space += 1;
}
}
}
}
I want to have a single inventory that is accessible in all scenes of my game, but I'm using switch statements to change scenes, which I faintly remember don't allow for data to be shared between scenes. Is there any way I can have this inventory work, or do I need to rethink the whole thing?
If it helps, I'm using Phaser 3 in VSCode, employing arcade physics.
Start or add your scenes first, then switch between them. When you start them, pass your game state:
export default class BootScene extends Phaser.Scene {
constructor() {
super({ key: "BootScene" });
}
preload() {
this.gameState = {
inventory: [ some stuff ],
}
}
create() {
const startScene = false;
this.scene.add("InventoryScene", InventoryScene, startScene, this.gameState);
this.scene.start("GameScene", this.gameState);
}
}
Now switch between your scenes:
export default class GameScene extends Phaser.Scene {
constructor() {
super({ key: "GameScene" });
}
init(gameState) {
this.gameState = gameState;
}
update() {
if player presses "i" {
this.scene.switch("InventoryScene");
}
}
The state you passed is available within the scene.
export default class InventoryScene extends Phaser.Scene {
constructor() {
super({ key: "InventoryScene" });
}
init(gameState) {
this.gameState = gameState;
}
update() {
const { some stuff } = this.gameState.inventory;
if player presses "esc" {
this.scene.switch("GameScene");
}
}
i try to adopt answer from How to re-use the same FetchRequest, rather than the same request in several views?
i build simple app with Core data
// Count+CoreDataProperties.swift
extension Count {
#nonobjc public class func fetchRequest() -> NSFetchRequest<Count> {
return NSFetchRequest<Count>(entityName: "Count")
}
#NSManaged public var id: UUID?
#NSManaged public var name: String?
#NSManaged public var number: Int16
}
// CoreDataManager.swift // all structs to fetch core data and set Environment
public struct CountEnvironmentKey: EnvironmentKey {
public static var defaultValue: [Count] = []
}
public extension EnvironmentValues {
var counts: [Count] {
get { self[CountEnvironmentKey.self] }
set { self[CountEnvironmentKey.self] = newValue }
}
}
public extension View {
func setCount(_ counts: [Count]) -> some View {
environment(\.counts, counts)
}
}
struct CountLoaderViewModifier: ViewModifier {
#FetchRequest( sortDescriptors: [])
var counts: FetchedResults<Count>
func body(content: Content) -> some View {
content
.setCount(Array(counts))
}
}
extension View {
func loadCounts() -> some View {
modifier(CountLoaderViewModifier())
}
}
// ContentView.swift
struct ContentView: View {
#Environment(\.managedObjectContext) private var viewContext
#Environment(\.counts) var counts
var body: some View {
NavigationView {
List {
ForEach(counts) { item in
NavigationLink {
Text("\(item.number)")
} label: {
Text("Item at \(item.name!)")
}
}
.onDelete(perform: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
Text("Select an item")
}
}
private func addItem() {
withAnimation {
let newItem = Count(context: viewContext)
newItem.name = "Name"
newItem.number = 1
newItem.id = UUID()
do {
try viewContext.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
}
}
private func deleteItems(offsets: IndexSet) {
withAnimation {
offsets.map { counts[$0] }.forEach(viewContext.delete)
do {
try viewContext.save()
} catch {
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
}
}
}
// MyEnvApp.swift
#main
struct MyEnvApp: App {
let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.loadCounts()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}
in #main i getting warning
Context in environment is not connected to a persistent store coordinator: <NSManagedObjectContext: 0x60000273dfb0>
the code from sample
#ObservedObject var persistenceManager = PersistenceManager(usage: .main)
generate error also, i understand that i need to connect my core data store to environment
thanks for help in advance
.loadCounts() is applied as a modifier outside (after) the modifier that sets the managed object context in the environment. This means the environment value is not present in your modifier's body. Try moving .loadCounts() above .environment(\.managedObjectContext, ...).
I don't know why take() options not get correct number as I expect.
Example ,I type take:2 but it just get one product, but when I remove relations it work normal.It is so strange with me,Am I missing something?
My code
async getProducts(#Arg("searchOptions") searchOptions : SearchOptionsInput): Promise<ProductResponse> {
try {
const {skip,type} = searchOptions
const findOptions: { [key: string]: any } = {
skip,
take: 2,
relations: ["prices"],
};
switch (type) {
case "PRICE_DESC":
findOptions.order = {
prices: {
price: "DESC"
}
}
break;
default:
findOptions.order = {
createdAt:"DESC"
}
break;
}
const products = await Product.find(findOptions);
return {
code: 200,
success: true,
products,
};
} catch (error) {
return {
code: 500,
success: false,
message: `Server error:${error.message}`,
};
}
}
My query
query GetProducts{
getProducts(searchOptions:{
skip:0,
type:"PRICE_DESC"
}){
code
success
products{
id
prices{
price
}
}
}
}
I have a form where a user can enter several values to track charges.
But the values are only stored in the properties when the user hits Enter if the values is added and the user selects the next field then the value for previous entered property remains at the initial value.
It there anything that needs to be set to accept normal change of fields?
Thanks.
import SwiftUI
import CoreData
struct CreateEditChargeView: View {
#Environment(\.managedObjectContext) private var viewContext
#Environment(\.presentationMode) var presentation
private var isNew = true
#ObservedObject var charge:Charge = Charge(entity: Charge.entity(), insertInto: nil)
var selectedVehicle: Vehicle
init(selectedVehicle: Vehicle, charge: Charge? = nil) {
self.selectedVehicle = selectedVehicle
if let charge = charge {
isNew = false
self.charge = charge
} else {
self.charge.id = UUID()
}
}
#ViewBuilder
var body: some View {
Form {
Section(header: Text("Basic")) {
TextField("KM", value: $charge.odometer,formatter: Formatter.distanceFormatter)
TextField("Price per Unit", value: $charge.pricePerUnit, formatter: Formatter.currencyFormatter)
}
}.navigationBarItems(leading: VStack{
if presentation.wrappedValue.isPresented {
Button(action: {
presentation.wrappedValue.dismiss()
}) {
Text("Cancel")
}
}
}, trailing: VStack {
if presentation.wrappedValue.isPresented {
Button(action: {
if isNew {
viewContext.insert(charge)
charge.vehicle = selectedVehicle
}
do {
try viewContext.save()
} catch {
ErrorHandler.handleError(error: error)
}
presentation.wrappedValue.dismiss()
}) {
Text("Done")
}
}
})
}
}
I want to display the error messages I am receiving from my backend in an alert, whenever my login failes:
My login-button triggers this function from my user.actions:
function login(username, password) {
return dispatch => {
dispatch(request({ username }));
userService.login(username, password)
.then(
user => {
dispatch(success(user));
history.goBack();
},
error => {
dispatch(failure(error.toString()));
dispatch(alertActions.error(error.toString()));
}
);
};
function request(user) { return { type: userConstants.LOGIN_REQUEST, user } }
function success(user) { return { type: userConstants.LOGIN_SUCCESS, user } }
function failure(error) { return { type: userConstants.LOGIN_FAILURE, error } }
}
My alert.reducer looks as following:
import { alertConstants } from '../_constants';
export function alert(state = {}, action) {
switch (action.type) {
case alertConstants.SUCCESS:
return {
type: 'alert-success',
message: action.message
};
case alertConstants.ERROR:
return {
type: 'alert-danger',
message: action.message
};
case alertConstants.CLEAR:
return {};
default:
return state
}
}
In my App.js I receive this state with mapStateToProps:
function mapStateToProps(state) {
const { alert } = state;
return {
alert
};
}
After that, I want to display an alert with the alert message:
{alert.message &&
alert(alert.message)
}
Can you help me with that?
your action/reducer code looks ok, I think maybe it is a conflict with the props name and the native alert function.
Have you tried to change the props names? Something like:
function mapStateToProps(state) {
const { alert } = state;
return {
alertState: alert
};
}
and
{ alertState.message && alert(alertState.message) }